Adoptions towards dynamic DB field creation without XClasses. Hooks from #29594 are...
authortmaroschik <tmaroschik@735d13b6-9817-0410-8766-e36946ffe9aa>
Mon, 12 Sep 2011 07:07:41 +0000 (07:07 +0000)
committertmaroschik <tmaroschik@735d13b6-9817-0410-8766-e36946ffe9aa>
Mon, 12 Sep 2011 07:07:41 +0000 (07:07 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/identity/trunk@51827 735d13b6-9817-0410-8766-e36946ffe9aa

Classes/Hooks/class.tx_identity_em_hook.php [new file with mode: 0644]
Classes/Hooks/class.tx_identity_tcemain_hook.php
Classes/Map.php
Classes/Utility/FieldDefinitions.php
ext_localconf.php
ext_tables.sql

diff --git a/Classes/Hooks/class.tx_identity_em_hook.php b/Classes/Hooks/class.tx_identity_em_hook.php
new file mode 100644 (file)
index 0000000..2b29f9e
--- /dev/null
@@ -0,0 +1,123 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Xavier Perseguers <xavier@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 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!
+ ***************************************************************/
+
+/**
+ * Hooks for TYPO3 Extension Manager.
+ *
+ * @author Xavier Perseguers <xavier@typo3.org>
+ *
+ * @package TYPO3
+ * @subpackage identity
+ */
+class tx_identity_em_hook implements tx_em_Index_CheckDatabaseUpdatesHook, Tx_Install_Interfaces_CheckTheDatabaseHook {
+
+       /**
+        * Contains tcaIncluded
+        *
+        * @var bool
+        */
+       protected $tcaIncluded = FALSE;
+
+       /**
+        * Hook that allows pre-processing of database structure modifications.
+        * The hook implementation may return a user form that will temporarily
+        * replace the standard database update form. This allows additional
+        * operations to be performed before the database structure gets updated.
+        *
+        * @param string $extKey: Extension key
+        * @param array $extInfo: Extension information array
+        * @param array $diff: Database differences
+        * @param t3lib_install $instObj: Instance of the installer
+        * @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, tx_em_Install $parent) {
+               // Do nothing here as we don't need to
+               return;
+       }
+
+       /**
+        * Hook that allows to dynamically extend the table definitions for e.g. custom caches.
+        * The hook implementation may return table create strings that will be respected by
+        * the extension manager during installation of an extension.
+        *
+        * @param string $extKey
+        * @param array $extInfo
+        * @param t3lib_install $instObj
+        * @param t3lib_install_Sql $instSqlObj
+        * @param tx_em_Install $parent
+        * @return string
+        */
+       public function appendTableDefinitions($extKey, array $extInfo, $fileContent, t3lib_install $instObj, t3lib_install_Sql $instSqlObj, tx_em_Install $parent) {
+               $fieldDefinitions = $instSqlObj->getFieldDefinitions_fileContent($fileContent);
+               /** @var Tx_Identity_Utility_FieldDefinitions $fieldDefinitionsUtility */
+               $fieldDefinitionsUtility = t3lib_div::makeInstance('Tx_Identity_Utility_FieldDefinitions');
+               // Ignore TCA upon extension installation, things get corrected afterwards if tca is available
+               if (!$extInfo['installed']) {
+                       $fieldDefinitionsUtility->setIgnoreTCA(TRUE);
+               }
+               return $fieldDefinitionsUtility->getInsertIdentityColumnSql($fieldDefinitions);
+       }
+
+       /**
+        *
+        * @param string $extKey
+        * @param array $loadedExtConf
+        * @param string $extensionSqlContent
+        * @param tx_em_Install $parent
+        * @return string
+        */
+       public function appendExtensionTableDefinitions($extKey, array $loadedExtConf, $extensionSqlContent, t3lib_install_Sql $instSqlObj, tx_install $parent) {
+               if (!$this->tcaIncluded) {
+                       $parent->includeTCA();
+                       $this->tcaIncluded = TRUE;
+               }
+               $fieldDefinitions = $instSqlObj->getFieldDefinitions_fileContent($extensionSqlContent);
+               /** @var Tx_Identity_Utility_FieldDefinitions $fieldDefinitionsUtility */
+               $fieldDefinitionsUtility = t3lib_div::makeInstance('Tx_Identity_Utility_FieldDefinitions');
+               return $fieldDefinitionsUtility->getInsertIdentityColumnSql($fieldDefinitions);
+       }
+
+       /**
+        *
+        * @param string $allSqlContent: The content of all relevant sql files
+        * @param t3lib_install_Sql $instSqlObj: Instance of the installer sql object
+        * @param tx_em_Install $parent: The calling parent object
+        * @return string
+        */
+       public function appendGlobalTableDefinitions($allSqlContent, t3lib_install_Sql $instSqlObj, tx_install $parent) {
+               // Do nothing here as we don't need to
+               return;
+       }
+}
+
+
+if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/identity/Classes/Hooks/class.tx_identity_em_hook.php'])) {
+       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/identity/Classes/Hooks/class.tx_identity_em_hook.php']);
+}
+
+?>
\ No newline at end of file
index 129ac76..7f083e0 100644 (file)
@@ -4,7 +4,7 @@ class tx_identity_tcemain_hook {
        public function processDatamap_afterAllOperations($parent) {
                /** @var $identityMap Tx_Identity_Map */
                $identityMap = t3lib_div::makeInstance('Tx_Identity_Map');
-               // $identityMap->rebuild();
+//             $identityMap->rebuild();
                $identityMap->commit();
        }
 }
index c28806b..eda7ab9 100644 (file)
@@ -134,7 +134,7 @@ class Tx_Identity_Map implements t3lib_Singleton {
                                }
                        }
                } else {
-                       throw new Exception('TCA is not available at the moment.', 1300109740);
+                       throw new RuntimeException('TCA is not available at the moment.', 1300109740);
                }
        }
 
index 7123e46..613e8ca 100644 (file)
 <?php
-
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Xavier Perseguers <xavier@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 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!
+ ***************************************************************/
+
+/**
+ * A utility class for the field defintions
+ *
+ * @author Thomas Maroschik <tmaroschik@dfau.de>
+ *
+ * @package TYPO3
+ * @subpackage identity
+ */
 class Tx_Identity_Utility_FieldDefinitions {
 
        /**
+        * Contains ignoreTCA
+        *
+        * @var bool
+        */
+       protected $ignoreTCA = FALSE;
+
+       /**
+        * Sets $ignoreTCA
+        *
+        * @param bool $ignoreTCA
+        */
+       public function setIgnoreTCA($ignoreTCA) {
+               $this->ignoreTCA = $ignoreTCA;
+       }
+
+       /**
+        * Returns $ignoreTCA
+        *
+        * @return bool
+        */
+       public function getIgnoreTCA() {
+               return $this->ignoreTCA;
+       }
+
+
+       /**
         * Check if a table definition contains an uid and a pid, and insert a uuid column
+        * Returns a modified table definition
         *
         * @param array $tableDefinitions
         * @return array
         */
-       public function insertIdentityColumn($tableDefinitions) {
+       public function insertIdentityColumn(array $tableDefinitions) {
+               $identityFieldDefinitions = $this->getIdentityFieldDefintions($tableDefinitions);
+               foreach ($identityFieldDefinitions as $table => $defintion) {
+                               foreach ($defintion['fields'] as $fieldName => $createString) {
+                                       $tableDefinitions[$table]['fields'][$fieldName] = $createString;
+                               }
+                               foreach ($defintion['keys'] as $keyName => $createString) {
+                                       $tableDefinitions[$table]['keys'][$keyName] = $createString;
+                               }
+               }
+               return $tableDefinitions;
+       }
+
+       /**
+        * Check if a table definition contains an uid and a pid, and insert a uuid column
+        * Returns a sql string that inserts the needed indentity fields
+        *
+        * @param array $tableDefinitions
+        * @return string
+        */
+       public function getInsertIdentityColumnSql(array $tableDefinitions) {
+               $sqlContent = LF . LF . LF;
+               $identityFieldDefinitions = $this->getIdentityFieldDefintions($tableDefinitions);
+               foreach ($identityFieldDefinitions as $table => $defintion) {
+                               $sqlRows = array();
+                               foreach ($defintion['fields'] as $fieldName => $createString) {
+                                       $sqlRows[] = TAB . $fieldName . ' ' . $createString;
+                               }
+                               foreach ($defintion['keys'] as $createString) {
+                                       $sqlRows[] = TAB . $createString;
+                               }
+                       $sqlContent .= 'CREATE TABLE ' . $table . ' (' . LF;
+                       $sqlContent .= implode(',' . LF, $sqlRows). LF;
+                       $sqlContent .= ');'  . LF . LF . LF;
+               }
+               return $sqlContent;
+       }
+
+       /**
+        * @throws InvalidArgumentException
+        * @param array $tableDefinitions
+        * @return array
+        */
+       protected function getIdentityFieldDefintions(array $tableDefinitions) {
+               $identityFieldDefintions = array();
+
                $identityConfigurationCheck = t3lib_div::makeInstance('Tx_Identity_Configuration_Check');
                $identityConfiguration = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['identity'];
                $identityProviders = $identityConfiguration[Tx_Identity_Configuration_IdentityProviderInterface::PROVIDERS_LIST];
 
-               foreach ($tableDefinitions as $table => &$definition) {
+               foreach ($tableDefinitions as $table => $definition) {
                        t3lib_div::loadTCA($table);
 
-                       if (isset($GLOBALS['TCA'][$table])) {
+                       if (
+                               isset($GLOBALS['TCA'][$table])
+                               || (
+                                               $this->ignoreTCA
+                                               && in_array('uid', array_keys($definition['fields']))
+                                               && in_array('pid', array_keys($definition['fields']))
+                                               && (
+                                                               t3lib_div::isFirstPartOfStr($table, 'tx_')
+                                                               || t3lib_div::isFirstPartOfStr($table, 'tt_')
+                                                               || t3lib_div::isFirstPartOfStr($table, 'static_')
+                                                               || $table == 'pages'
+                                                               || $table == 'tt_content'
+                                                       )
+                               )
+                       ) {
 
                                if (isset($GLOBALS['TCA'][$table]['ctrl']['EXT']['identity'][Tx_Identity_Configuration_IdentityProviderInterface::KEY])) {
 
@@ -24,19 +143,11 @@ class Tx_Identity_Utility_FieldDefinitions {
                                        $identityProviderField = $identityProviders[$identityProviderKey][Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD];
                                        $identityConfigurationCheck->checkTableSpecificIdentityProviderConfiguration($table, $identityProviderKey);
 
-                                               // Adds field + index definition
-                                       $definition['fields'][$identityProviderField] = $identityProviders[$identityProviderKey][Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD_CREATE_CLAUSE];
-                                       $definition['keys'][$identityProviderField] = 'KEY ' . $identityProviderField . ' (' . $identityProviderField . ')';
-
                                } elseif (isset($identityConfiguration[Tx_Identity_Configuration_IdentityProviderInterface::DEFAULT_PROVIDER])) {
 
-                                       $defaultProviderKey = $identityConfiguration[Tx_Identity_Configuration_IdentityProviderInterface::DEFAULT_PROVIDER];
-                                       $defaultProviderField = $identityProviders[$defaultProviderKey][Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD];
-                                       $identityConfigurationCheck->checkDefaultIdentityProviderConfiguration($defaultProviderKey);
-
-                                               // Adds field + index definition
-                                       $definition['fields'][$defaultProviderField] = $identityProviders[$defaultProviderKey][Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD_CREATE_CLAUSE];
-                                       $definition['keys'][$defaultProviderField] = 'KEY ' . $defaultProviderField . ' (' . $defaultProviderField . ')';
+                                       $identityProviderKey = $identityConfiguration[Tx_Identity_Configuration_IdentityProviderInterface::DEFAULT_PROVIDER];
+                                       $identityProviderField = $identityProviders[$identityProviderKey][Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD];
+                                       $identityConfigurationCheck->checkDefaultIdentityProviderConfiguration($identityProviderKey);
 
                                } else {
 
@@ -47,16 +158,22 @@ class Tx_Identity_Utility_FieldDefinitions {
                                        );
 
                                }
+
+                               // Adds field + index definition
+                               $identityFieldDefintions[$table]['fields'][$identityProviderField] = $identityProviders[$identityProviderKey][Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD_CREATE_CLAUSE];
+                               $identityFieldDefintions[$table]['keys'][$identityProviderField] = 'KEY ' . $identityProviderField . ' (' . $identityProviderField . ')';
+
                        } elseif ($table === 'sys_identity') {
 
                                foreach ($identityProviders as $identityProviderKey=>$identityProviderConfiguration) {
+
                                        $identityConfigurationCheck->checkIdentityProviderConfiguration($identityProviderKey);
                                        $identityField = $identityProviderConfiguration[Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD];
                                        $identityFieldCreateClause = $identityProviderConfiguration[Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD_CREATE_CLAUSE];
 
-                                               // Adds field + index definition
-                                       $definition['fields'][$identityField] = $identityFieldCreateClause;
-                                       $definition['keys'][$identityField] = 'KEY ' . $identityField . ' (' . $identityField . ')';
+                                       // Adds field + index definition
+                                       $identityFieldDefintions[$table]['fields'][$identityField] = $identityFieldCreateClause;
+                                       $identityFieldDefintions[$table]['keys'][$identityField] = 'KEY ' . $identityField . ' (' . $identityField . ')';
 
                                }
 
@@ -64,8 +181,7 @@ class Tx_Identity_Utility_FieldDefinitions {
 
                }
 
-               return $tableDefinitions;
+               return $identityFieldDefintions;
        }
-
 }
 ?>
\ No newline at end of file
index 4542996..10f3547 100644 (file)
@@ -30,8 +30,8 @@ if (!defined ('TYPO3_MODE')) {
        die ('Access denied.');
 }
 
-$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php'] = t3lib_extMgm::extPath($_EXTKEY) . 'Classes/Xclass/class.ux_t3lib_install.php';
-$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/install/mod/class.tx_install.php'] = t3lib_extMgm::extPath($_EXTKEY) . 'Classes/Xclass/class.ux_tx_install.php';
+//$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_install.php'] = t3lib_extMgm::extPath($_EXTKEY) . 'Classes/Xclass/class.ux_t3lib_install.php';
+//$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/install/mod/class.tx_install.php'] = t3lib_extMgm::extPath($_EXTKEY) . 'Classes/Xclass/class.ux_tx_install.php';
 
 if (!interface_exists('t3lib_DB_preProcessQueryHook')) {
        $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_db.php'] = t3lib_extMgm::extPath($_EXTKEY) . 'Classes/Xclass/class.ux_t3lib_db.php';
@@ -55,4 +55,10 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY] = array(
        Tx_Identity_Configuration_IdentityProviderInterface::DEFAULT_PROVIDER   => 'recordUuid',
 );
 
+// Register a hook for the extension manager
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/mod/tools/em/index.php']['checkDBupdates'][] = 'EXT:identity/Classes/Hooks/class.tx_identity_em_hook.php:tx_identity_em_hook';
+
+// Register a hook for the install tool
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install/mod/class.tx_install.php']['checkTheDatabase'][] = 'EXT:identity/Classes/Hooks/class.tx_identity_em_hook.php:tx_identity_em_hook';
+
 ?>
\ No newline at end of file
index 7ea7b5f..3c80532 100644 (file)
@@ -1,11 +1,10 @@
 #
-# Table structure for table 'sys_uuid'
+# Table structure for table 'sys_identity'
 #
-
 CREATE TABLE sys_identity (
-  uid int(11) NOT NULL auto_increment,
-  foreign_tablename varchar(255) NOT NULL default '',
-  foreign_uid int(11) DEFAULT '0' NOT NULL,
-  
-  PRIMARY KEY (uid)
-);
+       uid int(11) NOT NULL auto_increment,
+       foreign_tablename varchar(255) NOT NULL DEFAULT '',
+       foreign_uid int(11) DEFAULT '0' NOT NULL,
+
+       PRIMARY KEY (uid)
+);
\ No newline at end of file