[FEATURE] Integrate File Abstraction Layer Indexer Task
authorTYPO3 FAL Team <typo3v4@typo3.org>
Fri, 20 Apr 2012 16:37:38 +0000 (18:37 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Sat, 28 Apr 2012 13:15:21 +0000 (15:15 +0200)
Integrate a scheduler task that takes care of indexing files.

Change-Id: Id967456dbefadc33d1a23e8756e2cfef30f7139a
Resolves: #34284
Releases: 6.0
Reviewed-on: http://review.typo3.org/10657
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
Reviewed-by: Tolleiv Nietsch
Tested-by: Tolleiv Nietsch
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/scheduler/ext_autoload.php
typo3/sysext/scheduler/ext_localconf.php
typo3/sysext/scheduler/locallang.xlf
typo3/sysext/scheduler/tasks/class.tx_scheduler_fileindexing.php [new file with mode: 0644]

index 83c6807..b43a4bd 100644 (file)
@@ -19,6 +19,7 @@ return array(
        'tx_scheduler_croncmdtest' => $extensionPath . 'tests/tx_scheduler_croncmdTest.php',
        'tx_scheduler_cachingframeworkgarbagecollection' => $extensionPath . 'tasks/class.tx_scheduler_cachingframeworkgarbagecollection.php',
        'tx_scheduler_cachingframeworkgarbagecollection_additionalfieldprovider' => $extensionPath . 'tasks/class.tx_scheduler_cachingframeworkgarbagecollection_additionalfieldprovider.php',
+       'tx_scheduler_fileindexing' => $extensionPath . 'tasks/class.tx_scheduler_fileindexing.php',
        'tx_scheduler_tablegarbagecollection' => $extensionPath . 'tasks/class.tx_scheduler_tablegarbagecollection.php',
        'tx_scheduler_tablegarbagecollection_additionalfieldprovider' => $extensionPath . 'tasks/class.tx_scheduler_tablegarbagecollection_additionalfieldprovider.php',
        'tx_scheduler_recyclergarbagecollection' => $extensionPath . 'tasks/class.tx_scheduler_recyclergarbagecollection.php',
index 2b3786f..95a0236 100644 (file)
@@ -37,6 +37,13 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['tx_scheduler_Ca
        'additionalFields' => 'tx_scheduler_CachingFrameworkGarbageCollection_AdditionalFieldProvider',
 );
 
+       // Add file indexing task
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['tx_scheduler_FileIndexing'] = array(
+       'extension'        => $_EXTKEY,
+       'title'            => 'LLL:EXT:' . $_EXTKEY . '/locallang.xml:fileIndexing.name',
+       'description'      => 'LLL:EXT:' . $_EXTKEY . '/locallang.xml:fileIndexing.description',
+);
+
        // Add recycler directory cleanup task. Windows is not supported
        // because "filectime" does not change after moving a file
 if (TYPO3_OS != 'WIN') {
index 07f9d46..40f11ce 100644 (file)
                        <trans-unit id="cachingFrameworkGarbageCollection.description" xml:space="preserve">
                                <source>This task calls the garbage collection of configured caching framework caches which use one of the selected backends. This will free some space in cache backends which do not have an internal garbage collection. In case of the default database backend it is advisable to run this task once a day when the database is mostly idle.</source>
                        </trans-unit>
+                       <trans-unit id="fileIndexing.name" xml:space="preserve">
+                               <source>File Abstraction Layer: Indexing job</source>
+                       </trans-unit>
+                       <trans-unit id="fileIndexing.description" xml:space="preserve">
+                               <source>Runs indexing tasks based on an indexing configuration and a storage/folder information.</source>
+                       </trans-unit>
                        <trans-unit id="tableGarbageCollection.name" xml:space="preserve">
                                <source>Table garbage collection</source>
                        </trans-unit>
diff --git a/typo3/sysext/scheduler/tasks/class.tx_scheduler_fileindexing.php b/typo3/sysext/scheduler/tasks/class.tx_scheduler_fileindexing.php
new file mode 100644 (file)
index 0000000..5cf5e49
--- /dev/null
@@ -0,0 +1,114 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Lorenz Ulrich <lorenz.ulrich@visol.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!
+ ***************************************************************/
+
+/**
+ * This class provides Scheduler plugin implementation
+ *
+ * @author Lorenz Ulrich <lorenz.ulrich@visol.ch>
+ * @package TYPO3
+ * @subpackage media
+ */
+class tx_scheduler_FileIndexing extends tx_scheduler_Task {
+       /**
+        * @var string
+        */
+       protected $indexingConfiguration;
+
+       /**
+        * @var string
+        */
+       protected $paths;
+
+       /**
+        * Get the value of the protected property indexingConfiguration
+        *
+        * @return string UID of indexing configuration used for the job
+        */
+       public function getIndexingConfiguration() {
+               return $this->indexingConfiguration;
+       }
+
+       /**
+        * Set the value of the private property indexingConfiguration
+        *
+        * @param string $indexingConfiguration UID of indexing configuration used for the job
+        * @return void
+        */
+       public function setIndexingConfiguration($indexingConfiguration) {
+               $this->indexingConfiguration = $indexingConfiguration;
+       }
+
+       /**
+        * Get the value of the protected property paths
+        *
+        * @return string path information for scheduler job (JSON encoded array)
+        */
+       public function getPaths() {
+               return $this->paths;
+       }
+
+       /**
+        * Set the value of the private property paths
+        *
+        * @param array $paths path information for scheduler job (JSON encoded array)
+        * @return void
+        */
+       public function setPaths($paths) {
+               $this->paths = $paths;
+       }
+
+       /**
+        * Function execute from the Scheduler
+        *
+        * @return boolean TRUE on successful execution, FALSE on error
+        */
+       public function execute() {
+               $successfullyExecuted = TRUE;
+               /** @var $fileFactory t3lib_file_Factory */
+               $fileFactory = t3lib_div::makeInstance('t3lib_file_Factory');
+               /** @var $indexerService t3lib_file_Service_IndexerService */
+               $indexerService = t3lib_div::makeInstance('t3lib_file_Service_IndexerService');
+               $indexerService->setFactory($fileFactory);
+
+                       // run indexing of every storage
+               $storageRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                       '*',
+                       'sys_file_storage',
+                       'deleted = 0'
+               );
+               foreach ($storageRecords as $storageRecord) {
+                       $storageObject = $fileFactory->getStorageObject($storageRecord['uid'], $storageRecord);
+                       $folder = $storageObject->getRootLevelFolder();
+                       $indexerService->indexFilesInFolder($folder);
+               }
+
+               return $successfullyExecuted;
+       }
+}
+
+if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/scheduler/tasks/class.tx_scheduler_fileindexing.php'])) {
+       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/scheduler/tasks/class.tx_scheduler_fileindexing.php']);
+}
+
+?>
\ No newline at end of file