Implemented a scheduler rebuild map task and cleaned up further.
authortmaroschik <tmaroschik@735d13b6-9817-0410-8766-e36946ffe9aa>
Mon, 30 Jan 2012 14:55:52 +0000 (14:55 +0000)
committertmaroschik <tmaroschik@735d13b6-9817-0410-8766-e36946ffe9aa>
Mon, 30 Jan 2012 14:55:52 +0000 (14:55 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/identity/trunk@57007 735d13b6-9817-0410-8766-e36946ffe9aa

Classes/Provider/AbstractUuid.php
Classes/Tasks/RebuildTask.php [new file with mode: 0644]
Resources/Private/Language/locallang.xml
ext_autoload.php
ext_localconf.php

index 3468d99..c5b4937 100644 (file)
@@ -332,7 +332,7 @@ class Tx_Identity_Provider_AbstractUuid implements Tx_Identity_ProviderInterface
                } else {
                        $validUid = t3lib_utility_Math::canBeInterpretedAsInteger($uid);
                }
-               if (isset($GLOBALS['TCA'][$tablename]) && $validUid) {
+               if ($validUid) {
                        if (isset($this->insertQueue[$uuid])) {
                                unset($this->insertQueue[$uuid]);
                        }
@@ -383,18 +383,38 @@ class Tx_Identity_Provider_AbstractUuid implements Tx_Identity_ProviderInterface
         */
        protected function removeNeedlessUUIDs() {
                $identityField = $this->configuration[Tx_Identity_Configuration_IdentityProviderInterface::IDENTITY_FIELD];
-               foreach ($GLOBALS['TCA'] as $tablename => $configuration) {
-                       $rows = $this->db->exec_SELECTgetRows(
-                               $this->identityTable . '.' . $identityField . ', ' . $this->identityTable . '.foreign_uid',
-                                       $tablename . ' RIGHT JOIN ' . $this->identityTable . ' ON ' .
-                                       $this->identityTable . '.' . $identityField .
-                                       ' = ' .
-                                       $tablename . '.' . $identityField . ' AND ' . $this->identityTable . '.foreign_uid = ' . $tablename . '.uid',
-                                       'foreign_tablename LIKE ' . $tablename . ' AND ' . $tablename . '.uid IS NULL'
-                       );
-                       if (is_array($rows)) {
-                               foreach ($rows as $row) {
-                                       $this->unregisterUUID($row[$identityField], $tablename, $row['uid']);
+               $tablenames = $this->db->exec_SELECTgetRows(
+                       $this->identityTable . '.foreign_tablename',
+                       $this->identityTable,
+                       '',
+                       $this->identityTable . '.foreign_tablename',
+                       '',
+                       '',
+                       'foreign_tablename'
+               );
+               if (is_array($tablenames) && !empty($tablenames)) {
+                       foreach (array_keys($tablenames) as $tablename) {
+                               if ($this->isApplicable($tablename)) {
+                                       $rows = $this->db->exec_SELECTgetRows(
+                                               $this->identityTable . '.' . $identityField . ', ' . $this->identityTable . '.foreign_uid',
+                                               $tablename . ' RIGHT JOIN ' . $this->identityTable . ' ON ' .
+                                               $this->identityTable . '.' . $identityField .
+                                               ' = ' .
+                                               $tablename . '.' . $identityField . ' AND ' . $this->identityTable . '.foreign_uid = ' . $tablename . '.uid',
+                                               'foreign_tablename LIKE \'' . $tablename . '\' AND ' . $tablename . '.uid IS NULL'
+                                       );
+                               } else {
+                                       // Not applicable means, delete all in registry regarding this tablename
+                                       $rows = $this->db->exec_SELECTgetRows(
+                                               $this->identityTable . '.' . $identityField . ', ' . $this->identityTable . '.foreign_uid',
+                                               $this->identityTable,
+                                               'foreign_tablename LIKE \'' . $tablename . '\''
+                                       );
+                               }
+                               if (is_array($rows)) {
+                                       foreach ($rows as $row) {
+                                               $this->unregisterUUID($row[$identityField], $tablename, $row['foreign_uid']);
+                                       }
                                }
                        }
                }
diff --git a/Classes/Tasks/RebuildTask.php b/Classes/Tasks/RebuildTask.php
new file mode 100644 (file)
index 0000000..13fa549
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010 Christian Kuhn <lolli@schwarzbu.ch>
+ *  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.
+ *
+ *  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!
+ ***************************************************************/
+
+/**
+ * Rebuilds the identity map
+ *
+ * @author Thomas Maroschik <tmaroschik@dfau.de>
+ *
+ * @package TYPO3
+ * @subpackage identity
+ */
+class Tx_Identity_Tasks_RebuildTask extends tx_scheduler_Task {
+
+       /**
+        * Public method, usually called by scheduler.
+        *
+        * @return boolean TRUE on success
+        */
+       public function execute() {
+               /** @var $identityMap Tx_Identity_Map */
+               $identityMap = t3lib_div::makeInstance('Tx_Identity_Map');
+               $identityMap->rebuild();
+               $identityMap->commit();
+               return (TRUE);
+       }
+
+}
\ No newline at end of file
index fb5087b..6aea2ea 100644 (file)
                                missing.
                                You should open up the Install tool and run the "Compare" tool under "Database Analyser"
                        </label>
+                       <label index="tasks_rebuildTask.name">Rebuild Identity Map</label>
+                       <label index="tasks_rebuildTask.description">This task is intended to rebuild identifiers for records
+                               without identifier. Further the identity map, that maps identitfies to record locations will be updated
+                               and kept in sync with the records.
+                       </label>
                </languageKey>
        </data>
 </T3locallang>
\ No newline at end of file
index 0f49af2..94f0b2f 100644 (file)
@@ -1,8 +1,6 @@
 <?php
 /*
  * Register necessary class names with autoloader
- *
- * $Id: $
  */
 return array(
        't3lib_db_preprocessqueryhook' => PATH_t3lib . 'interfaces/interface.t3lib_db_preprocessqueryhook.php',
@@ -16,5 +14,6 @@ return array(
        'tx_identity_provider_staticrecorduuid' => t3lib_extMgm::extPath('identity', 'Classes/Provider/StaticRecordUuid.php'),
        'tx_identity_utility_fielddefinitions' => t3lib_extMgm::extPath('identity', 'Classes/Utility/FieldDefinitions.php'),
        'tx_identity_utility_algorithms' => t3lib_extMgm::extPath('identity', 'Classes/Utility/Algorithms.php'),
+       'tx_identity_tasks_rebuildtask' => t3lib_extMgm::extPath('identity', 'Classes/Tasks/RebuildTask.php'),
 );
 ?>
index 8348f0c..5753744 100644 (file)
@@ -30,9 +30,7 @@ if (!defined ('TYPO3_MODE')) {
        die ('Access denied.');
 }
 
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][$_EXTKEY] = 'EXT:' . $_EXTKEY . '/Classes/Hooks/class.tx_identity_tcemain_hook.php:tx_identity_tcemain_hook';
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_db.php']['queryProcessors'][$_EXTKEY] = 'EXT:' . $_EXTKEY . '/Classes/Hooks/class.tx_identity_t3lib_db_preprocess.php:tx_identity_t3lib_db_preprocess';
-
+// Configure the default identity providers.
 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY] = array(
        Tx_Identity_Configuration_IdentityProviderInterface::PROVIDERS_LIST     => array(
                'recordUuid'    => array(
@@ -49,10 +47,25 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$_EXTKEY] = array(
        Tx_Identity_Configuration_IdentityProviderInterface::DEFAULT_PROVIDER   => 'recordUuid',
 );
 
+// Register a hook for tce main
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][$_EXTKEY] = 'EXT:' . $_EXTKEY . '/Classes/Hooks/class.tx_identity_tcemain_hook.php:tx_identity_tcemain_hook';
+
+//Register a hook for DB
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_db.php']['queryProcessors'][$_EXTKEY] = 'EXT:' . $_EXTKEY . '/Classes/Hooks/class.tx_identity_t3lib_db_preprocess.php:tx_identity_t3lib_db_preprocess';
+
 // 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';
 
+
+       // Register extension list update task
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['Tx_Identity_Tasks_RebuildTask'] = array(
+       'extension'                     => $_EXTKEY,
+       'title'                         => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xml:tasks_rebuildTask.name',
+       'description'           => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang.xml:tasks_rebuildTask.description',
+       'additionalFields'      => '',
+);
+
 ?>
\ No newline at end of file