[FEATURE] Integrate preliminary PackageManager API
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Package / FailsafePackageManager.php
1 <?php
2 namespace TYPO3\CMS\Core\Package;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Thomas Maroschik <tmaroschik@dfau.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * This is an intermediate package manager that loads just
34 * the required extensions for the install in case the package
35 * states are unavailable.
36 */
37 class FailsafePackageManager extends \TYPO3\CMS\Core\Package\PackageManager {
38
39 /**
40 * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager
41 */
42 protected $configurationManager;
43
44 /**
45 * @var boolean TRUE if package manager is in failsafe mode
46 */
47 protected $inFailsafeMode = FALSE;
48
49 /**
50 * Constructor
51 */
52 public function __construct() {
53 $this->configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager;
54 parent::__construct();
55 }
56
57 /**
58 * Loads the states of available packages from the PackageStates.php file.
59 * The result is stored in $this->packageStatesConfiguration.
60 *
61 * @return void
62 */
63 protected function loadPackageStates() {
64 try {
65 parent::loadPackageStates();
66 } catch (\TYPO3\CMS\Core\Package\Exception\PackageStatesUnavailableException $exception) {
67 $this->inFailsafeMode = TRUE;
68 $this->packageStatesConfiguration = array();
69 $this->scanAvailablePackages();
70 }
71 }
72
73 /**
74 * Requires and registers all packages which were defined in packageStatesConfiguration
75 *
76 * @return void
77 * @throws \TYPO3\Flow\Package\Exception\CorruptPackageException
78 */
79 protected function registerPackagesFromConfiguration() {
80 $this->packageStatesConfiguration['packages']['install']['state'] = 'active';
81 parent::registerPackagesFromConfiguration();
82 }
83
84 /**
85 * Sort and save states
86 *
87 * @return void
88 */
89 protected function sortAndSavePackageStates() {
90 // Do not save if in rescue mode
91 if (!$this->inFailsafeMode) {
92 parent::sortAndSavePackageStates();
93 }
94 }
95 }