[TASK] Re-work/simplify copyright header in PHP files - Part 3
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Package / FailsafePackageManager.php
1 <?php
2 namespace TYPO3\CMS\Core\Package;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * This is an intermediate package manager that loads just
21 * the required extensions for the install in case the package
22 * states are unavailable.
23 */
24 class FailsafePackageManager extends \TYPO3\CMS\Core\Package\PackageManager {
25
26 /**
27 * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager
28 */
29 protected $configurationManager;
30
31 /**
32 * @var boolean TRUE if package manager is in failsafe mode
33 */
34 protected $inFailsafeMode = FALSE;
35
36 /**
37 * Constructor
38 */
39 public function __construct() {
40 $this->configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager;
41 parent::__construct();
42 }
43
44 /**
45 * Loads the states of available packages from the PackageStates.php file.
46 * The result is stored in $this->packageStatesConfiguration.
47 *
48 * @return void
49 */
50 protected function loadPackageStates() {
51 try {
52 parent::loadPackageStates();
53 } catch (\TYPO3\CMS\Core\Package\Exception\PackageStatesUnavailableException $exception) {
54 $this->inFailsafeMode = TRUE;
55 $this->packageStatesConfiguration = array();
56 $this->scanAvailablePackages();
57 }
58 }
59
60 /**
61 * Requires and registers all packages which were defined in packageStatesConfiguration
62 *
63 * @return void
64 * @throws \TYPO3\Flow\Package\Exception\CorruptPackageException
65 */
66 protected function registerPackagesFromConfiguration() {
67 $this->packageStatesConfiguration['packages']['install']['state'] = 'active';
68 parent::registerPackagesFromConfiguration();
69 }
70
71 /**
72 * Sort and save states
73 *
74 * @return void
75 */
76 protected function sortAndSavePackageStates() {
77 // Do not save if in rescue mode
78 if (!$this->inFailsafeMode) {
79 parent::sortAndSavePackageStates();
80 }
81 }
82
83 /**
84 * To enable writing of the package states file the package states
85 * migration needs to override eventual failsafe blocks.
86 */
87 public function forceSortAndSavePackageStates() {
88 parent::sortAndSavePackageStates();
89 }
90 }