[BUGFIX] Add DB structure update pre-processing hook in EM
authorXavier Perseguers <xavier@typo3.org>
Fri, 26 Aug 2011 10:04:27 +0000 (12:04 +0200)
committerJigal van Hemert <jigal@xs4all.nl>
Sun, 28 Aug 2011 13:11:18 +0000 (15:11 +0200)
Extension Manager lacks a way to perform actions prior to modifying the database
structure (create new tables or add additional fields in existing ones) when
installing an extension.

This would be very handy for DBAL to let user update mapping definition from within
TYPO3 without the need to first manually edit typo3conf/localconf.php.

This is a bugfix as the feature had been accepted for 4.5.0beta1 and was wrongly
removed during Extension Manager refactoring task. In fact, the interface is still
here but never used.

Change-Id: I4de8490a6ad61f0068525fda07f41a8601be9c6c
Fixes: #23877
Releases: 4.5, 4.6
Reviewed-on: http://review.typo3.org/4614
Reviewed-by: Björn Pedersen
Reviewed-by: Philipp Gampe
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
typo3/sysext/em/classes/install/class.tx_em_install.php
typo3/sysext/em/interfaces/interface.tx_em_index_checkdatabaseupdateshook.php

index 4c88076..db1686e 100644 (file)
@@ -822,6 +822,7 @@ class tx_em_Install {
                $content = '';
 
                // Updating tables and fields?
+               $showUpdateStatements = TRUE;
                if (is_array($extInfo['files']) && in_array('ext_tables.sql', $extInfo['files'])) {
                        $path = tx_em_Tools::getExtPath($extKey, $extInfo['type']);
                        $fileContent = t3lib_div::getUrl($path . 'ext_tables.sql');
@@ -842,12 +843,31 @@ class tx_em_Install {
                                        $this->installerSql->performUpdateQueries($update_statements['change'], $this->install->INSTALL['database_update']);
                                        $this->installerSql->performUpdateQueries($update_statements['create_table'], $this->install->INSTALL['database_update']);
                                } else {
-                                       $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
-                                               $update_statements['add'], $GLOBALS['LANG']->getLL('checkDBupdates_add_fields'));
-                                       $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
-                                               $update_statements['change'], $GLOBALS['LANG']->getLL('checkDBupdates_changing_fields'), 1, 0, $update_statements['change_currentValue']);
-                                       $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
-                                               $update_statements['create_table'], $GLOBALS['LANG']->getLL('checkDBupdates_add_tables'));
+                                       if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/mod/tools/em/index.php']['checkDBupdates'])) {
+                                               foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/mod/tools/em/index.php']['checkDBupdates'] as $classData) {
+                                                       $hookObject = t3lib_div::getUserObj($classData);
+
+                                                       if (!($hookObject instanceof tx_em_Index_CheckDatabaseUpdatesHook)) {
+                                                               throw new UnexpectedValueException('$hookObject must implement interface em_index_checkDatabaseUpdatesHook', 1288418476);
+                                                       }
+
+                                                       /* @var $hookObject tx_em_Index_CheckDatabaseUpdatesHook */
+                                                       $preprocessContent = $hookObject->preProcessDatabaseUpdates($extKey, $extInfo, $diff, $this->install, $this);
+                                                       if ($preprocessContent) {
+                                                               $content .= $preprocessContent;
+                                                               $showUpdateStatements = FALSE;
+                                                               break;
+                                                       }
+                                               }
+                                       }
+                                       if ($showUpdateStatements) {
+                                               $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
+                                                       $update_statements['add'], $GLOBALS['LANG']->getLL('checkDBupdates_add_fields'));
+                                               $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
+                                                       $update_statements['change'], $GLOBALS['LANG']->getLL('checkDBupdates_changing_fields'), 1, 0, $update_statements['change_currentValue']);
+                                               $content .= $this->install->generateUpdateDatabaseForm_checkboxes(
+                                                       $update_statements['create_table'], $GLOBALS['LANG']->getLL('checkDBupdates_add_tables'));
+                                       }
                                }
                        }
                }
@@ -1602,4 +1622,4 @@ if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLA
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/install/class.tx_em_install.php']);
 }
 
-?>
\ No newline at end of file
+?>
index 7a8a221..c98d5fe 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2010 Xavier Perseguers <typo3@perseguers.ch>
+*  (c) 2010-2011 Xavier Perseguers <xavier@typo3.org>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -26,9 +26,9 @@
 ***************************************************************/
 
 /**
- * Interface for hook in SC_mod_tools_em_index::checkDBupdates.
+ * Interface for hook in tx_em_Install::checkDBupdates.
  *
- * @author Xavier Perseguers <typo3@perseguers.ch>
+ * @author Xavier Perseguers <xavier@typo3.org>
  * @package TYPO3
  * @subpackage em
  */
@@ -44,10 +44,10 @@ interface tx_em_Index_CheckDatabaseUpdatesHook {
         * @param array $extInfo: Extension information array
         * @param array $diff: Database differences
         * @param t3lib_install $instObj: Instance of the installer
-        * @param SC_mod_tools_em_index $parent: The calling parent object
+        * @param tx_em_Install $parent: The calling parent object
         * @return string Either empty string or a pre-processing user form
         */
-       public function preProcessDatabaseUpdates($extKey, array $extInfo, array $diff, t3lib_install $instObj, SC_mod_tools_em_index $parent);
+       public function preProcessDatabaseUpdates($extKey, array $extInfo, array $diff, t3lib_install $instObj, tx_em_Install $parent);
 
 }