[FEATURE] Integrate preliminary PackageManager API
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / UpdatePackageManager.php
1 <?php
2 namespace TYPO3\CMS\Install\Updates;
3
4 use TYPO3\CMS\Core\Package\PackageFactory;
5 use TYPO3\CMS\Core\Utility\GeneralUtility;
6 use TYPO3\Flow\Annotations as Flow;
7
8 /**
9 * The default TYPO3 Package Manager
10 *
11 * @api
12 * @Flow\Scope("singleton")
13 */
14 class UpdatePackageManager extends \TYPO3\CMS\Core\Package\PackageManager {
15
16 /**
17 * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager
18 */
19 protected $configurationManager;
20
21 /**
22 */
23 public function __construct() {
24 $this->configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager;
25 parent::__construct();
26 }
27
28
29 /**
30 * Initializes the package manager
31 *
32 * @param \TYPO3\CMS\Core\Core\Bootstrap $bootstrap The current bootstrap
33 * @param string $packagesBasePath Absolute path of the Packages directory
34 * @param string $packageStatesPathAndFilename
35 * @return void
36 */
37 public function createPackageStatesFile(\TYPO3\CMS\Core\Core\Bootstrap $bootstrap, $packagesBasePath = PATH_site, $packageStatesPathAndFilename = '') {
38
39 $this->bootstrap = $bootstrap;
40 $this->packagesBasePath = $packagesBasePath;
41 $this->packageStatesPathAndFilename = ($packageStatesPathAndFilename === '') ? PATH_typo3conf . 'PackageStates.php' : $packageStatesPathAndFilename;
42 $this->packageFactory = new PackageFactory($this);
43
44 $this->loadPackageStates();
45 $this->activateProtectedPackagesAndLegacyExtensions();
46 $this->sortAndSavePackageStates();
47 $this->removeExtensionListsFromConfiguration();
48 }
49
50 /**
51 *
52 */
53 protected function activateProtectedPackagesAndLegacyExtensions() {
54 $packagesToActivate = array();
55 // Activate protected/required packages
56 foreach ($this->packages as $packageKey => $package) {
57 if ($package->isProtected() || (isset($this->packageStatesConfiguration['packages'][$packageKey]['state']) && $this->packageStatesConfiguration['packages'][$packageKey]['state'] === 'active')) {
58 $packagesToActivate[$package->getPackageKey()] = $package;
59 }
60 }
61 // Activate legacy extensions
62 foreach ($this->getLoadedExtensionKeys() as $loadedExtensionKey) {
63 try {
64 $package = $this->getPackage($loadedExtensionKey);
65 $packagesToActivate[$package->getPackageKey()] = $package;
66 } catch (\TYPO3\Flow\Package\Exception\UnknownPackageException $exception) {
67 if (isset($this->packageStatesConfiguration['packages'][$loadedExtensionKey])) {
68 unset($this->packageStatesConfiguration['packages'][$loadedExtensionKey]);
69 }
70 }
71 }
72 // Activate dependant packages
73 $this->resolvePackageDependencies();
74 foreach ($packagesToActivate as $packageKey => $package) {
75 foreach ($this->packageStatesConfiguration['packages'][$packageKey]['dependencies'] as $dependantPackageKey) {
76 if (!isset($packagesToActivate[$dependantPackageKey])) {
77 $dependantPackage = $this->getPackage($dependantPackageKey);
78 $packagesToActivate[$dependantPackage->getPackageKey()] = $dependantPackage;
79 }
80 }
81 }
82 // Make all active
83 foreach ($packagesToActivate as $packageKey => $package) {
84 $this->packageStatesConfiguration['packages'][$packageKey]['state'] = 'active';
85 $this->activePackages[$packageKey] = $package;
86 }
87 }
88
89 /**
90 * Loads the states of available packages from the PackageStates.php file.
91 * The result is stored in $this->packageStatesConfiguration.
92 *
93 * @return void
94 */
95 protected function loadPackageStates() {
96 $this->packageStatesConfiguration = array();
97 $this->scanAvailablePackages();
98 }
99
100 /**
101 * @return array|NULL
102 */
103 protected function getLoadedExtensionKeys() {
104 $loadedExtensions = NULL;
105 try {
106 // Extensions in extListArray
107 $loadedExtensions = $this->configurationManager->getLocalConfigurationValueByPath('EXT/extListArray');
108 } catch (\RuntimeException $exception) {
109 // Fallback handling if extlist is still a string and not an array
110 // @deprecated since 6.2, will be removed two versions later without a substitute
111 try {
112 $loadedExtensions = GeneralUtility::trimExplode(',', $this->configurationManager->getLocalConfigurationValueByPath('EXT/extList'));
113 } catch (\RuntimeException $exception) {
114
115 }
116 }
117 return $loadedExtensions;
118 }
119
120 /**
121 *
122 */
123 protected function removeExtensionListsFromConfiguration() {
124 copy(
125 $this->configurationManager->getLocalConfigurationFileLocation(),
126 preg_replace('/\.php$/', '.beforePackageStatesMigration.php', $this->configurationManager->getLocalConfigurationFileLocation())
127 );
128 $this->configurationManager->updateLocalConfiguration(array(
129 'EXT' => array(
130 'extListArray' => '__UNSET',
131 'extList' => '__UNSET',
132 'requiredExt' => '__UNSET',
133 ),
134 ));
135 }
136
137 }