Further cleanup and adjustments in the extension installation flow.
authortmaroschik <tmaroschik@735d13b6-9817-0410-8766-e36946ffe9aa>
Mon, 30 Jan 2012 13:29:10 +0000 (13:29 +0000)
committertmaroschik <tmaroschik@735d13b6-9817-0410-8766-e36946ffe9aa>
Mon, 30 Jan 2012 13:29:10 +0000 (13:29 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/identity/trunk@57004 735d13b6-9817-0410-8766-e36946ffe9aa

Classes/Hooks/class.tx_identity_em_hook.php
Classes/Map.php
Classes/Provider/AbstractUuid.php
Classes/Provider/StaticRecordUuid.php
Classes/ProviderInterface.php
Classes/Utility/ExtensionManager.php
Classes/Utility/FieldDefinitions.php
Resources/Private/Language/locallang.xml
ext_conf_template.txt
ext_emconf.php

index b803cb0..3692676 100644 (file)
@@ -73,7 +73,13 @@ class tx_identity_em_hook implements tx_em_Index_CheckDatabaseUpdatesHook, Tx_In
         * @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);
+               if ($extKey === 'identity') {
+                       // Proceed over all TCA tables if in ext:identity database update dialog
+                       $fieldDefinitions = $GLOBALS['TCA'];
+                       $fieldDefinitions['sys_identity'] = Array();
+               } else {
+                       $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
index 08d7277..31b0c14 100644 (file)
@@ -168,7 +168,6 @@ class Tx_Identity_Map implements t3lib_Singleton {
                if (!$this->isApplicable($tablename)) {
                        return NULL;
                }
-               $this->initializeObject();
                if (isset($this->tableSpecificIdentityProviders[$tablename])) {
                        // Look for a more specific identity provider first
                        return $this->tableSpecificIdentityProviders[$tablename]['provider']->getIdentifierForResourceLocation($tablename, $uid);
@@ -188,7 +187,6 @@ class Tx_Identity_Map implements t3lib_Singleton {
                if (!$this->isApplicable($tablename)) {
                        return NULL;
                }
-               $this->initializeObject();
                if (isset($this->tableSpecificIdentityProviders[$tablename])) {
                        return $this->tableSpecificIdentityProviders[$tablename]['provider']->getIdentifierForNewResourceLocation($tablename);
                } else {
@@ -227,10 +225,14 @@ class Tx_Identity_Map implements t3lib_Singleton {
         * @return bool
         */
        public function isApplicable($tablename) {
-               return t3lib_div::isFirstPartOfStr($tablename, 'tt_')
-                       || t3lib_div::isFirstPartOfStr($tablename, 'tx_')
-                       || t3lib_div::isFirstPartOfStr($tablename, 'static_')
-                       || $tablename === 'pages';
+               $this->initializeObject();
+               if (isset($this->tableSpecificIdentityProviders[$tablename])) {
+                       // Look for a more specific identity provider first
+                       return $this->tableSpecificIdentityProviders[$tablename]['provider']->isApplicable($tablename);
+               } else {
+                       // else take the default provider
+                       return $this->defaultIdentityProvider['provider']->isApplicable($tablename);
+               }
        }
 
        /**
index edc5c92..3468d99 100644 (file)
@@ -51,6 +51,11 @@ class Tx_Identity_Provider_AbstractUuid implements Tx_Identity_ProviderInterface
        protected $configuration = array();
 
        /**
+        * @var array
+        */
+       protected $isApplicableCache = array();
+
+       /**
         * @var t3lib_DB
         */
        protected $db;
@@ -136,6 +141,32 @@ class Tx_Identity_Provider_AbstractUuid implements Tx_Identity_ProviderInterface
        }
 
        /**
+        * @param string $tablename
+        * @return bool
+        */
+       public function isApplicable($tablename) {
+               if (isset($this->isApplicableCache[$tablename])) {
+                       return $this->isApplicableCache[$tablename];
+               }
+               if (isset($GLOBALS['TCA']) && is_array($GLOBALS['TCA']) && in_array($tablename, array_keys($GLOBALS['TCA']))) {
+                       $identityField = $this->configuration[Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD];
+                       if ($identityField) {
+                               // It is necessary to check if the table contains the identity field.
+                               // During the installation of ext:identity there could occur sql errors until the
+                               // extension manager/install tool hook kicks in and the tables are supplied with the identifier field.
+                               $fields = $this->db->admin_get_fields($tablename);
+                               $fieldNames = array_keys($fields);
+                               if ($fields && in_array($identityField, $fieldNames)) {
+                                       $this->isApplicableCache[$tablename] = TRUE;
+                                       return $this->isApplicableCache[$tablename];
+                               }
+                       }
+               }
+               $this->isApplicableCache[$tablename] = FALSE;
+               return $this->isApplicableCache[$tablename];
+       }
+
+       /**
         * Returns a resource location for an identifier
         *
         * @param mixed $identifier
@@ -439,9 +470,9 @@ class Tx_Identity_Provider_AbstractUuid implements Tx_Identity_ProviderInterface
                                foreach ($this->deleteQueue as $deletableEntries) {
                                        $this->db->exec_DELETEquery(
                                                $this->identityTable,
-                                                       $identityField . ' = ' . $this->db->fullQuoteStr($deletableEntries[$identityField], $this->identityTable)
-                                                       . ' OR ( foreign_tablename = ' . $this->db->fullQuoteStr($deletableEntries['tablename'], $this->identityTable) . ' AND '
-                                                       . ' foreign_uid = ' . $this->db->fullQuoteStr($deletableEntries['uid'], $this->identityTable) . ')'
+                                               $identityField . ' = ' . $this->db->fullQuoteStr($deletableEntries[$identityField], $this->identityTable)
+                                               . ' OR ( foreign_tablename = ' . $this->db->fullQuoteStr($deletableEntries['tablename'], $this->identityTable) . ' AND '
+                                               . ' foreign_uid = ' . $this->db->fullQuoteStr($deletableEntries['uid'], $this->identityTable) . ')'
                                        );
                                }
                        }
index 939bbc7..d8542d0 100644 (file)
@@ -42,7 +42,6 @@ class Tx_Identity_Provider_StaticRecordUuid extends Tx_Identity_Provider_Abstrac
                $this->insertMissingUUIDs();
        }
 
-
        /**
         * Walks through all tables and inserts an uuid to a record that has any
         */
index 30136aa..a2a1a6f 100644 (file)
@@ -46,6 +46,14 @@ interface Tx_Identity_ProviderInterface {
        public function validateIdentifier($identifier);
 
        /**
+        * Checks if this provider is applicable to the table
+        *
+        * @param string $tablename
+        * @return bool
+        */
+       public function isApplicable($tablename);
+
+       /**
         * Returns a unique identifier for a resource location
         *
         * @param string $tablename
index 6b444f0..c62deec 100644 (file)
@@ -92,11 +92,10 @@ class Tx_Identity_Utility_ExtensionManager {
                                $tblFileContent .= LF . LF . LF . LF . t3lib_div::getUrl($loadedExtConf['ext_tables.sql']);
                        }
                }
-               $fileContent = implode(
-                               LF, $installer->getStatementArray($tblFileContent, 1, '^CREATE TABLE ')
-               );
+               $fileContent = implode(LF, $installer->getStatementArray($tblFileContent, 1, '^CREATE TABLE '));
                // get the table definitions
                $tableDefinitions = $installer->getFieldDefinitions_fileContent($fileContent);
+               /** @var $fieldDefinitionsUtility Tx_Identity_Utility_FieldDefinitions */
                $fieldDefinitionsUtility = t3lib_div::makeInstance('Tx_Identity_Utility_FieldDefinitions');
                $tableDefinitions = $fieldDefinitionsUtility->insertIdentityColumn($tableDefinitions);
                if (!count($tableDefinitions)) {
@@ -107,8 +106,11 @@ class Tx_Identity_Utility_ExtensionManager {
                // get a diff and check if a field uuid is missing somewhere
                $diff = $installer->getDatabaseExtra($tableDefinitions, $FDdb);
                $update_statements = $installer->getUpdateSuggestions($diff);
+               if (empty($update_statements)) {
+                       return FALSE;
+               }
                $update_statements['add'] = $installer->filterByIdentityField($update_statements['add']);
-               return ! empty($update_statements['add']);
+               return !empty($update_statements['add']);
        }
 
        /**
index c35c82a..6e5c5c2 100644 (file)
@@ -60,7 +60,6 @@ class Tx_Identity_Utility_FieldDefinitions {
                return $this->ignoreTCA;
        }
 
-
        /**
         * Check if a table definition contains an uid and a pid, and insert a uuid column
         * Returns a modified table definition
@@ -71,12 +70,12 @@ class Tx_Identity_Utility_FieldDefinitions {
        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;
-                               }
+                       foreach ($defintion['fields'] as $fieldName => $createString) {
+                               $tableDefinitions[$table]['fields'][$fieldName] = $createString;
+                       }
+                       foreach ($defintion['keys'] as $keyName => $createString) {
+                               $tableDefinitions[$table]['keys'][$keyName] = $createString;
+                       }
                }
                return $tableDefinitions;
        }
@@ -92,13 +91,13 @@ class Tx_Identity_Utility_FieldDefinitions {
                $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;
-                               }
+                       $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;
@@ -113,73 +112,55 @@ class Tx_Identity_Utility_FieldDefinitions {
         */
        protected function getIdentityFieldDefintions(array $tableDefinitions) {
                $identityFieldDefintions = array();
-
                /** @var $identityConfigurationCheck Tx_Identity_Configuration_Check */
                $identityConfigurationCheck = t3lib_div::makeInstance('Tx_Identity_Configuration_Check');
-
                /** @var $identityMap Tx_Identity_Map */
                $identityMap = t3lib_div::makeInstance('Tx_Identity_Map');
-
                $identityConfiguration = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['identity'];
                $identityProviders = $identityConfiguration[Tx_Identity_Configuration_IdentityProviderInterface::PROVIDERS_LIST];
-
                foreach ($tableDefinitions as $table => $definition) {
                        t3lib_div::loadTCA($table);
-
                        if (
                                isset($GLOBALS['TCA'][$table])
+                               || $identityMap->isApplicable($table)
                                || (
-                                               $this->ignoreTCA
-                                               && in_array('uid', array_keys($definition['fields']))
-                                               && in_array('pid', array_keys($definition['fields']))
-                                               && $identityMap->isApplicable($table)
+                                       // During installation of an extension, the extensions tca is not available
+                                       // In this case ignoreTCA is set and we look only for a uid and pid column.
+                                       // If this isn't right, it gets corrected afterwards anyways.
+                                       $this->ignoreTCA
+                                       && in_array('uid', array_keys($definition['fields']))
+                                       && in_array('pid', array_keys($definition['fields']))
                                )
                        ) {
-
                                if (isset($GLOBALS['TCA'][$table]['ctrl']['EXT']['identity'][Tx_Identity_Configuration_IdentityProviderInterface::KEY])) {
-
                                        $identityProviderKey = $GLOBALS['TCA'][$table]['ctrl']['EXT']['identity'][Tx_Identity_Configuration_IdentityProviderInterface::KEY];
                                        $identityProviderField = $identityProviders[$identityProviderKey][Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD];
                                        $identityConfigurationCheck->checkTableSpecificIdentityProviderConfiguration($table, $identityProviderKey);
-
                                } elseif (isset($identityConfiguration[Tx_Identity_Configuration_IdentityProviderInterface::DEFAULT_PROVIDER])) {
-
                                        $identityProviderKey = $identityConfiguration[Tx_Identity_Configuration_IdentityProviderInterface::DEFAULT_PROVIDER];
                                        $identityProviderField = $identityProviders[$identityProviderKey][Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD];
                                        $identityConfigurationCheck->checkDefaultIdentityProviderConfiguration($identityProviderKey);
-
                                } else {
-
-                                       throw InvalidArgumentException(
+                                       throw new InvalidArgumentException(
                                                'There is no default identity provider defined in ' .
                                                '$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'identity\'][Tx_Identity_Configuration_IdentityProviderInterface::DEFAULT_PROVIDER]',
                                                1300104461
                                        );
-
                                }
-
                                // 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
                                        $identityFieldDefintions[$table]['fields'][$identityField] = $identityFieldCreateClause;
                                        $identityFieldDefintions[$table]['keys'][$identityField] = 'KEY ' . $identityField . ' (' . $identityField . ')';
-
                                }
-
                        }
-
                }
-
                return $identityFieldDefintions;
        }
 
index 28152f8..fb5087b 100644 (file)
@@ -1,40 +1,41 @@
 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
 <T3locallang>
-    <meta type="array">
-        <description>Labels for mod1 backend module</description>
-        <type>module</type>
-        <csh_table></csh_table>
-        <labelContext type="array">
-        </labelContext>
-    </meta>
-    <data type="array">
-        <languageKey index="default" type="array">
+       <meta type="array">
+               <description>Labels for mod1 backend module</description>
+               <type>module</type>
+               <csh_table></csh_table>
+               <labelContext type="array">
+               </labelContext>
+       </meta>
+       <data type="array">
+               <languageKey index="default" type="array">
+                       <label index="updater_extmgr_head">Message</label>
                        <label index="updater_header">UUID field(s) or key(s) are missing</label>
                        <label index="updater_message">
-                                 <![CDATA[
+                               <![CDATA[
                                <p style="margin-bottom: 10px">
-                               Identity brings Universally Unique Identifier (UUID) in TYPO3. 
-                               A UUID is an identifier that is immutable and unique across time and space. 
+                               Identity brings Universally Unique Identifier (UUID) in TYPO3.
+                               A UUID is an identifier that is immutable and unique across time and space.
                                </p>
-                               
-                               
+
+
                                <p style="margin-bottom: 10px">
                                A UUID is a 32 hexadecimal digit, for example:
                                <br />
                                <strong>550e8400-e29b-41d4-a716-446655440000</strong>
                                </p>
-                               
+
                                <p style="margin-bottom: 10px">
                                To know more about the use and benefit of UUID consult page :
                                <a href="http://en.wikipedia.org/wiki/Universally_unique_identifier" target="_blank">http://en.wikipedia.org/wiki/Universally_unique_identifier</a>
                                </p>
-                               
-                                       Some "uuid" field(s) or key(s) are detected as missing. Please, launch the 
+
+                                       Some "uuid" field(s) or key(s) are detected as missing. Please, launch the
                                ]]>
                        </label>
                        <label index="ok_header">UUID fields are OK</label>
                        <label index="ok_message">
-                                 <![CDATA[
+                               <![CDATA[
                                <p style="margin-bottom: 10px">
                                To know more about the use and benefit of UUID consult page :
                                <a href="http://en.wikipedia.org/wiki/Universally_unique_identifier" target="_blank">http://en.wikipedia.org/wiki/Universally_unique_identifier</a>
                        <label index="open_updater">Updater Script</label>
                        <label index="ok_table_header">UUID fields are OK and values have been successfully checked</label>
                        <label index="information_table_header">Some table(s) are missing</label>
-                       <label index="information_table_message">While checking the system, it has been detected some table(s) are missing. 
-                       You should open up the Install tool and run the "Compare" tool under "Database Analyser"</label>
-        </languageKey>
-    </data>
+                       <label index="information_table_message">While checking the system, it has been detected some table(s) are
+                               missing.
+                               You should open up the Install tool and run the "Compare" tool under "Database Analyser"
+                       </label>
+               </languageKey>
+       </data>
 </T3locallang>
\ No newline at end of file
index e8a7b28..3876ea0 100644 (file)
@@ -1,2 +1,2 @@
-# cat=basic/dev/1000; type=user[EXT:identity/Classes/Utility/ExtensionManager.php:Tx_Identity_Utility_ExtensionManager->displayMessage]; label=LLL:EXT:identity/Resources/Private/Language/locallang.xml:itest
-updateMessage=0
+# cat=basic/dev/1000; type=user[EXT:identity/Classes/Utility/ExtensionManager.php:Tx_Identity_Utility_ExtensionManager->displayMessage]; label=Message
+updateMessage=0
\ No newline at end of file
index c764aaf..b69c59e 100644 (file)
@@ -1,4 +1,15 @@
 <?php
+
+########################################################################
+# Extension Manager/Repository config file for ext "identity".
+#
+# Auto generated 30-01-2012 13:04
+#
+# Manual updates:
+# Only the data in the array - everything else is removed by next
+# writing. "version" and "dependencies" must not be touched!
+########################################################################
+
 $EM_CONF[$_EXTKEY] = array(
        'title' => 'Identity',
        'description' => '',
@@ -7,7 +18,7 @@ $EM_CONF[$_EXTKEY] = array(
        'author_email' => 'tmaroschik@dfau.de, fabien.udriot@ecodev.ch',
        'author_company' => 'DFAU, Ecodev',
        'shy' => '',
-       'dependencies' => 'typo3',
+       'dependencies' => '',
        'conflicts' => '',
        'priority' => '',
        'module' => '',
@@ -28,6 +39,9 @@ $EM_CONF[$_EXTKEY] = array(
                'suggests' => array(
                ),
        ),
+       'suggests' => array(
+       ),
+       '_md5_values_when_last_written' => 'a:21:{s:20:"class.ext_update.php";s:4:"9073";s:16:"ext_autoload.php";s:4:"2c9b";s:21:"ext_conf_template.txt";s:4:"0608";s:17:"ext_localconf.php";s:4:"d3f6";s:14:"ext_tables.php";s:4:"ab1d";s:14:"ext_tables.sql";s:4:"da8f";s:15:"Classes/Map.php";s:4:"87e1";s:29:"Classes/ProviderInterface.php";s:4:"7b19";s:31:"Classes/Configuration/Check.php";s:4:"df54";s:51:"Classes/Configuration/IdentityProviderInterface.php";s:4:"41a2";s:43:"Classes/Hooks/class.tx_identity_em_hook.php";s:4:"23f9";s:55:"Classes/Hooks/class.tx_identity_t3lib_db_preprocess.php";s:4:"6790";s:48:"Classes/Hooks/class.tx_identity_tcemain_hook.php";s:4:"dc3c";s:29:"Classes/Install/Installer.php";s:4:"6be5";s:33:"Classes/Provider/AbstractUuid.php";s:4:"d378";s:31:"Classes/Provider/RecordUuid.php";s:4:"af00";s:37:"Classes/Provider/StaticRecordUuid.php";s:4:"6b5b";s:30:"Classes/Utility/Algorithms.php";s:4:"8b96";s:36:"Classes/Utility/ExtensionManager.php";s:4:"8af1";s:36:"Classes/Utility/FieldDefinitions.php";s:4:"2798";s:40:"Resources/Private/Language/locallang.xml";s:4:"1032";}',
 );
 
 ?>
\ No newline at end of file