[BUGFIX] Install new system extensions during upgrade process fails
authorNicole Cordes <n.cordes@biz-design.biz>
Fri, 2 Nov 2012 21:31:42 +0000 (22:31 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Mon, 26 Nov 2012 22:38:04 +0000 (23:38 +0100)
If you try to update your system from 4.7 to current master the second
step "Install System Extensions" fails because of missing extensionmanager
tables.

So we have to push up the initialisation process from EM and adopt
it to include ext_tables.sql as well (at the moment only the file
ext_tables_static+adt.sql is processed).

Change-Id: I5cd4616e5bccd06e86fa3ae4fbde8a083afa428f
Fixes: #42616
Releases: 6.0
Reviewed-on: http://review.typo3.org/16153
Reviewed-by: Mattias Nilsson
Reviewed-by: Wouter Wolters
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/install/Classes/CoreUpdates/ExtensionManagerRepositories.php [deleted file]
typo3/sysext/install/Classes/CoreUpdates/ExtensionManagerTables.php [new file with mode: 0644]
typo3/sysext/install/ext_localconf.php

diff --git a/typo3/sysext/install/Classes/CoreUpdates/ExtensionManagerRepositories.php b/typo3/sysext/install/Classes/CoreUpdates/ExtensionManagerRepositories.php
deleted file mode 100644 (file)
index 66c1822..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-namespace TYPO3\CMS\Install\CoreUpdates;
-
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2012 Georg Ringer <typo3@ringerge.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 textfile GPL.txt and important notices to the license
- *  from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- *  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.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-/**
- * Contains the update class for filling the basic repository record of the extension manager
- *
- * @author Georg Ringer <typo3@ringerge.org>
- */
-class ExtensionManagerRepositories extends \TYPO3\CMS\Install\Updates\AbstractUpdate {
-
-       protected $title = 'Add the default extension manager repository';
-
-       /**
-        * Checks if an update is needed
-        *
-        * @param string &$description: The description for the update
-        * @return boolean Whether an update is needed (TRUE) or not (FALSE)
-        */
-       public function checkForUpdate(&$description) {
-               $result = FALSE;
-               $description = 'Add the default extension manager repository to the database.';
-
-               $databaseTables = $GLOBALS['TYPO3_DB']->admin_get_tables();
-               if (!isset($databaseTables['tx_extensionmanager_domain_model_repository'])) {
-                       $result = TRUE;
-               } else {
-                       $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'tx_extensionmanager_domain_model_repository');
-                       if ($count === 0) {
-                               $result = TRUE;
-                       }
-               }
-               return $result;
-       }
-
-       /**
-        * Performs the database update.
-        *
-        * @param array &$dbQueries: queries done in this update
-        * @param mixed &$customMessages: custom messages
-        * @return boolean Whether it worked (TRUE) or not (FALSE)
-        */
-       public function performUpdate(array &$dbQueries, &$customMessages) {
-               $result = FALSE;
-               $sqlFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('extensionmanager') . DIRECTORY_SEPARATOR . 'ext_tables_static+adt.sql';
-               $sqlStatements = explode(';', \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($sqlFile));
-
-               foreach ($sqlStatements as $sqlStatement) {
-                       if (trim($sqlStatement) !== '') {
-                               $res = $GLOBALS['TYPO3_DB']->sql_query($sqlStatement);
-                               $dbQueries[] = $sqlStatement;
-                               if ($GLOBALS['TYPO3_DB']->sql_error()) {
-                                       $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error());
-                               } else {
-                                       $result = TRUE;
-                               }
-                       }
-               }
-               return $result;
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/install/Classes/CoreUpdates/ExtensionManagerTables.php b/typo3/sysext/install/Classes/CoreUpdates/ExtensionManagerTables.php
new file mode 100644 (file)
index 0000000..eeb2f74
--- /dev/null
@@ -0,0 +1,164 @@
+<?php
+namespace TYPO3\CMS\Install\CoreUpdates;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Georg Ringer <typo3@ringerge.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 textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  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.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * Contains the update class for filling the basic repository record of the extension manager
+ *
+ * @author Georg Ringer <typo3@ringerge.org>
+ */
+class ExtensionManagerTables extends \TYPO3\CMS\Install\Updates\AbstractUpdate {
+
+       protected $title = 'Add the default Extension Manager database tables';
+
+       /**
+        * @var null|\TYPO3\CMS\Install\Sql\SchemaMigrator
+        */
+       protected $installToolSqlParser = NULL;
+
+       /**
+        * @return \TYPO3\CMS\Install\Sql\SchemaMigrator
+        */
+       protected function getInstallToolSqlParser() {
+               if ($this->installToolSqlParser === NULL) {
+                       $this->installToolSqlParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Install\\Sql\\SchemaMigrator');
+               }
+
+               return $this->installToolSqlParser;
+       }
+
+       /**
+        * Gets all create, add and change queries from ext_tables.sql
+        *
+        * @return array
+        */
+       protected function getUpdateStatements() {
+               $updateStatements = array();
+
+               // Get all necessary statements for ext_tables.sql file
+               $rawDefinitions = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('extensionmanager') . '/ext_tables.sql');
+               $fieldDefinitionsFromFile = $this->getInstallToolSqlParser()->getFieldDefinitions_fileContent($rawDefinitions);
+               if (count($fieldDefinitionsFromFile)) {
+                       $fieldDefinitionsFromCurrentDatabase = $this->getInstallToolSqlParser()->getFieldDefinitions_database();
+                       $diff = $this->getInstallToolSqlParser()->getDatabaseExtra($fieldDefinitionsFromFile, $fieldDefinitionsFromCurrentDatabase);
+                       $updateStatements = $this->getInstallToolSqlParser()->getUpdateSuggestions($diff);
+               }
+
+               return $updateStatements;
+       }
+
+       /**
+        * Checks if an update is needed
+        *
+        * @param string &$description: The description for the update
+        * @return boolean Whether an update is needed (TRUE) or not (FALSE)
+        */
+       public function checkForUpdate(&$description) {
+               $result = FALSE;
+               $description = 'Creates necessary database tables and adds static tables for the new Extension Manager.';
+
+               // First check necessary database update
+               $updateStatements = $this->getUpdateStatements();
+               if (empty($updateStatements)) {
+                       // Check for repository database table
+                       $databaseTables = $GLOBALS['TYPO3_DB']->admin_get_tables();
+                       if (!isset($databaseTables['tx_extensionmanager_domain_model_repository'])) {
+                               $result = TRUE;
+                       } else {
+                               // Get count of rows in repository database table
+                               $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'tx_extensionmanager_domain_model_repository');
+                               if ($count === 0) {
+                                       $result = TRUE;
+                               }
+                       }
+               } else {
+                       $result = TRUE;
+               }
+
+               return $result;
+       }
+
+       /**
+        * @param mixed &$customMessages: custom messages
+        *
+        * @return boolean
+        */
+       protected function hasError(&$customMessages) {
+               $result = FALSE;
+               if ($GLOBALS['TYPO3_DB']->sql_error()) {
+                       $customMessages .= '<br /><br />SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error());
+                       $result = TRUE;
+               }
+
+               return $result;
+       }
+
+       /**
+        * Performs the database update.
+        *
+        * @param array &$dbQueries: queries done in this update
+        * @param mixed &$customMessages: custom messages
+        * @return boolean Whether it worked (TRUE) or not (FALSE)
+        */
+       public function performUpdate(array &$dbQueries, &$customMessages) {
+               $result = FALSE;
+
+               // First perform all create, add and change queries
+               $updateStatements = $this->getUpdateStatements();
+               foreach ((array) $updateStatements['add'] as $string) {
+                       $GLOBALS['TYPO3_DB']->admin_query($string);
+                       $dbQueries[] = $string;
+                       $result = ($result || $this->hasError($customMessages));
+               }
+               foreach ((array) $updateStatements['change'] as $string) {
+                       $GLOBALS['TYPO3_DB']->admin_query($string);
+                       $dbQueries[] = $string;
+                       $result = ($result || $this->hasError($customMessages));
+               }
+               foreach ((array) $updateStatements['create_table'] as $string) {
+                       $GLOBALS['TYPO3_DB']->admin_query($string);
+                       $dbQueries[] = $string;
+                       $result = ($result || $this->hasError($customMessages));
+               }
+
+               // Perform statis import anyway
+               $rawDefinitions = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('extensionmanager') . 'ext_tables_static+adt.sql');
+               $statements = $this->getInstallToolSqlParser()->getStatementarray($rawDefinitions, 1);
+               foreach ($statements as $statement) {
+                       if (trim($statement) !== '') {
+                               $GLOBALS['TYPO3_DB']->admin_query($statement);
+                               $dbQueries[] = $statement;
+                               $result = ($result || $this->hasError($customMessages));
+                       }
+               }
+
+               return !$result;
+       }
+
+}
+
+?>
\ No newline at end of file
index e08467f..fff046b 100644 (file)
@@ -17,6 +17,8 @@ $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['removeNotInMenuDoktypeC
 // remove pagetype "advanced" since TYPO3 4.2
 // this is merged with doctype "standard" with tab view to edit
 $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['mergeAdvancedDoktypeConversion'] = 'TYPO3\\CMS\\Install\\CoreUpdates\\MergeAdvancedUpdate';
+// TYPO3 6.0 - Add new tables for ExtensionManager
+$TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['extensionManagerTables'] = 'TYPO3\\CMS\\Install\\CoreUpdates\\ExtensionManagerTables';
 // add new / outsourced system extensions since TYPO3 4.3
 $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['installSystemExtensions'] = 'TYPO3\\CMS\\Install\\CoreUpdates\\InstallSysExtsUpdate';
 // change tt_content.imagecols=0 to 1 for proper display in TCEforms since TYPO3 4.3
@@ -44,7 +46,6 @@ $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['sysext_file_init'] = 'T
 $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['sysext_file_images'] = 'TYPO3\\CMS\\Install\\Updates\\TceformsUpdateWizard';
 $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['sysext_file_uploads'] = 'TYPO3\\CMS\\Install\\Updates\\TtContentUploadsUpdateWizard';
 $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['sysext_file_filemounts'] = 'TYPO3\\CMS\\Install\\Updates\\FilemountUpdateWizard';
-$TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['extensionManagerRepositories'] = 'TYPO3\\CMS\\Install\\CoreUpdates\\ExtensionManagerRepositories';
 // Version 4.7: Migrate the flexforms of MediaElement
 $TYPO3_CONF_VARS['SC_OPTIONS']['ext/install']['update']['mediaElementFlexform'] = 'TYPO3\\CMS\\Install\\CoreUpdates\\MediaFlexformUpdate';
 ?>
\ No newline at end of file