[TASK] Use fully qualified name resolution in PHP 5.5
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / InstallUtility.php
index 9a95c7a..0436404 100644 (file)
@@ -1,31 +1,19 @@
 <?php
 namespace TYPO3\CMS\Extensionmanager\Utility;
 
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2012-2013 Susanne Moog <susanne.moog@typo3.org>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *  A copy is found in the text file GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
+/**
+ * This file is part of the TYPO3 CMS project.
  *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
  *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
  *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ * The TYPO3 project - inspiring people to share!
+ */
+use TYPO3\CMS\Impexp\Utility\ImportExportUtility;
 
 /**
  * Extension Manager Install Utility
@@ -119,7 +107,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
                $this->reloadCaches();
                $this->processRuntimeDatabaseUpdates($extensionKey);
                $this->saveDefaultConfiguration($extension['key']);
-               if ($extension['clearcacheonload']) {
+               if (!empty($extension['clearcacheonload']) || !empty($extension['clearCacheOnLoad'])) {
                        $this->cacheManager->flushCaches();
                } else {
                        $this->cacheManager->flushCachesInGroup('system');
@@ -153,7 +141,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
         * Wrapper function to check for loaded extensions
         *
         * @param string $extensionKey
-        * @return boolean TRUE if extension is loaded
+        * @return bool TRUE if extension is loaded
         */
        public function isLoaded($extensionKey) {
                return $this->packageManager->isPackageActive($extensionKey);
@@ -184,7 +172,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
         * Checks if an extension is available in the system
         *
         * @param $extensionKey
-        * @return boolean
+        * @return bool
         */
        public function isAvailable($extensionKey) {
                return $this->packageManager->isPackageAvailable($extensionKey);
@@ -267,8 +255,10 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
         * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
         */
        protected function emitTablesDefinitionIsBeingBuiltSignal($extensionKey) {
-               $signalReturn = $this->signalSlotDispatcher->dispatch(__CLASS__, 'tablesDefinitionIsBeingBuilt', array('sqlString' => array(), 'extensionKey' => $extensionKey));
-               $sqlString = $signalReturn['sqlString'];
+               $signalReturn = $this->signalSlotDispatcher->dispatch(__CLASS__, 'tablesDefinitionIsBeingBuilt', array(array(), $extensionKey));
+               // This is important to support old associated returns
+               $signalReturn = array_values($signalReturn);
+               $sqlString = $signalReturn[0];
                if (!is_array($sqlString)) {
                        throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(
                                sprintf(
@@ -301,7 +291,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
         */
        protected function saveDefaultConfiguration($extensionKey) {
                /** @var $configUtility \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility */
-               $configUtility = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\ConfigurationUtility');
+               $configUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class);
                $configUtility->saveDefaultConfiguration($extensionKey);
        }
 
@@ -318,13 +308,13 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
                        $diff = $this->installToolSqlParser->getDatabaseExtra($fieldDefinitionsFromFile, $fieldDefinitionsFromCurrentDatabase);
                        $updateStatements = $this->installToolSqlParser->getUpdateSuggestions($diff);
                        $db = $this->getDatabaseConnection();
-                       foreach ((array) $updateStatements['add'] as $string) {
+                       foreach ((array)$updateStatements['add'] as $string) {
                                $db->admin_query($string);
                        }
-                       foreach ((array) $updateStatements['change'] as $string) {
+                       foreach ((array)$updateStatements['change'] as $string) {
                                $db->admin_query($string);
                        }
-                       foreach ((array) $updateStatements['create_table'] as $string) {
+                       foreach ((array)$updateStatements['create_table'] as $string) {
                                $db->admin_query($string);
                        }
                }
@@ -410,7 +400,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
         *
         * @internal
         * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionData
-        * @return boolean
+        * @return bool
         */
        public function isUpdateAvailable(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionData) {
                $isUpdateAvailable = FALSE;
@@ -421,10 +411,9 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
                if ($highestTerVersionExtension instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension) {
                        $highestVersion = $highestTerVersionExtension->getIntegerVersion();
                        if ($highestVersion > $version) {
-                               try {
-                                       $this->dependencyUtility->buildExtensionDependenciesTree($highestTerVersionExtension);
+                               $this->dependencyUtility->checkDependencies($highestTerVersionExtension);
+                               if (!$this->dependencyUtility->hasDependencyErrors()) {
                                        $isUpdateAvailable = TRUE;
-                               } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
                                }
                        }
                }
@@ -432,29 +421,57 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
        }
 
        /**
-        * Uses the export import extension to import a T3DFile to PID 0
+        * Uses the export import extension to import a T3D or XML file to PID 0
         * Execution state is saved in the this->registry, so it only happens once
         *
         * @param string $extensionSiteRelPath
         * @return void
         */
        protected function importT3DFile($extensionSiteRelPath) {
-               $t3dImportRelFile = $extensionSiteRelPath . 'Initialisation/data.t3d';
-               if (!$this->registry->get('extensionDataImport', $t3dImportRelFile)) {
-                       $t3dImportFile = PATH_site . $t3dImportRelFile;
-                       if (file_exists($t3dImportFile)) {
-                               $importExportUtility = $this->objectManager->get('TYPO3\\CMS\\Impexp\\Utility\\ImportExportUtility');
-                               try {
-                                       $importResult = $importExportUtility->importT3DFile($t3dImportFile, 0);
-                                       $this->registry->set('extensionDataImport', $t3dImportRelFile, 1);
-                                       $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionT3DImport', array($t3dImportRelFile, $importResult, $this));
-                               } catch (\ErrorException $e) {
-                                       /** @var \TYPO3\CMS\Core\Log\Logger $logger */
-                                       $logger = $this->objectManager->get('TYPO3\\CMS\\Core\\Log\\LogManager')->getLogger(__CLASS__);
-                                       $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, $e->getMessage());
-                               }
+               $registryKeysToCheck = array(
+                       $extensionSiteRelPath . 'Initialisation/data.t3d',
+                       $extensionSiteRelPath . 'Initialisation/dataImported',
+               );
+               foreach ($registryKeysToCheck as $registryKeyToCheck) {
+                       if ($this->registry->get('extensionDataImport', $registryKeyToCheck)) {
+                               // Data was imported before => early return
+                               return;
                        }
                }
+               $importFileToUse = NULL;
+               $possibleImportFiles = array(
+                       $extensionSiteRelPath . 'Initialisation/data.t3d',
+                       $extensionSiteRelPath . 'Initialisation/data.xml'
+               );
+               foreach ($possibleImportFiles as $possibleImportFile) {
+                       if (!file_exists(PATH_site . $possibleImportFile)) {
+                               continue;
+                       }
+                       $importFileToUse = $possibleImportFile;
+               }
+               if ($importFileToUse !== NULL) {
+                       /** @var ImportExportUtility $importExportUtility */
+                       $importExportUtility = $this->objectManager->get(\TYPO3\CMS\Impexp\Utility\ImportExportUtility::class);
+                       try {
+                               $importResult = $importExportUtility->importT3DFile(PATH_site . $importFileToUse, 0);
+                               $this->registry->set('extensionDataImport', $extensionSiteRelPath . 'Initialisation/dataImported', 1);
+                               $this->emitAfterExtensionT3DImportSignal($importFileToUse, $importResult);
+                       } catch (\ErrorException $e) {
+                               /** @var \TYPO3\CMS\Core\Log\Logger $logger */
+                               $logger = $this->objectManager->get(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
+                               $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, $e->getMessage());
+                       }
+               }
+       }
+
+       /**
+        * Emits a signal after an t3d file was imported
+        *
+        * @param string $importFileToUse
+        * @param int $importResult
+        */
+       protected function emitAfterExtensionT3DImportSignal($importFileToUse, $importResult) {
+               $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionT3DImport', array($importFileToUse, $importResult, $this));
        }
 
        /**
@@ -473,11 +490,20 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
                                $this->importStaticSql($extTablesStaticSqlContent);
                        }
                        $this->registry->set('extensionDataImport', $extTablesStaticSqlRelFile, 1);
-                       $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionStaticSqlImport', array($extTablesStaticSqlRelFile, $this));
+                       $this->emitAfterExtensionStaticSqlImportSignal($extTablesStaticSqlRelFile);
                }
        }
 
        /**
+        * Emits a signal after a static sql file was imported
+        *
+        * @param string $extTablesStaticSqlRelFile
+        */
+       protected function emitAfterExtensionStaticSqlImportSignal($extTablesStaticSqlRelFile) {
+               $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionStaticSqlImport', array($extTablesStaticSqlRelFile, $this));
+       }
+
+       /**
         * Imports files from Initialisation/Files to fileadmin
         * via lowlevel copy directory method
         *
@@ -498,11 +524,19 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface {
                                }
                                \TYPO3\CMS\Core\Utility\GeneralUtility::copyDirectory($importRelFolder, $destinationRelPath);
                                $this->registry->set('extensionDataImport', $importRelFolder, 1);
-                               $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionFileImport', array($destinationAbsolutePath, $this));
+                               $this->emitAfterExtensionFileImportSignal($destinationAbsolutePath);
                        }
                }
        }
 
+       /**
+        * Emits a signal after extension files were imported
+        *
+        * @param string $destinationAbsolutePath
+        */
+       protected function emitAfterExtensionFileImportSignal($destinationAbsolutePath) {
+               $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterExtensionFileImport', array($destinationAbsolutePath, $this));
+       }
 
        /**
         * @return \TYPO3\CMS\Core\Database\DatabaseConnection