[FEATURE] Grouping for scheduler-jobs
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Classes / Task / FileIndexingTask.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Task;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Lorenz Ulrich <lorenz.ulrich@visol.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * This class provides Scheduler plugin implementation
28 *
29 * @author Lorenz Ulrich <lorenz.ulrich@visol.ch>
30 */
31 class FileIndexingTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
32
33 /**
34 * @var string
35 */
36 protected $indexingConfiguration;
37
38 /**
39 * @var string
40 */
41 protected $paths;
42
43 /**
44 * Get the value of the protected property indexingConfiguration
45 *
46 * @return string UID of indexing configuration used for the job
47 */
48 public function getIndexingConfiguration() {
49 return $this->indexingConfiguration;
50 }
51
52 /**
53 * Set the value of the private property indexingConfiguration
54 *
55 * @param string $indexingConfiguration UID of indexing configuration used for the job
56 * @return void
57 */
58 public function setIndexingConfiguration($indexingConfiguration) {
59 $this->indexingConfiguration = $indexingConfiguration;
60 }
61
62 /**
63 * Get the value of the protected property paths
64 *
65 * @return string path information for scheduler job (JSON encoded array)
66 */
67 public function getPaths() {
68 return $this->paths;
69 }
70
71 /**
72 * Set the value of the private property paths
73 *
74 * @param array $paths path information for scheduler job (JSON encoded array)
75 * @return void
76 */
77 public function setPaths($paths) {
78 $this->paths = $paths;
79 }
80
81 /**
82 * Function execute from the Scheduler
83 *
84 * @return boolean TRUE on successful execution, FALSE on error
85 */
86 public function execute() {
87 $successfullyExecuted = TRUE;
88
89 /** @var $fileFactory \TYPO3\CMS\Core\Resource\ResourceFactory */
90 $fileFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
91 /** @var $indexerService \TYPO3\CMS\Core\Resource\Service\IndexerService */
92 $indexerService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService');
93
94 // run indexing of every storage
95 $storageRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_file_storage', 'deleted = 0');
96 foreach ($storageRecords as $storageRecord) {
97 $storageObject = $fileFactory->getStorageObject($storageRecord['uid'], $storageRecord);
98 $folder = $storageObject->getRootLevelFolder();
99 $indexerService->indexFilesInFolder($folder);
100 }
101 return $successfullyExecuted;
102 }
103
104 }