2 namespace TYPO3\CMS\Core\Resource\Processing
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use \TYPO3\CMS\Core\Resource
, \TYPO3\CMS\Core\Utility
;
20 * Abstract base implementation of a task.
22 * If you extend this class, make sure that you redefine the member variables $type and $name
23 * or set them in the constructor. Otherwise your task won't be recognized by the system and several
27 abstract class AbstractTask
implements TaskInterface
{
32 protected $checksumData = array();
35 * @var Resource\ProcessedFile
37 protected $targetFile;
42 protected $sourceFile;
47 protected $configuration;
62 protected $executed = FALSE
;
67 protected $successful;
70 * @param Resource\ProcessedFile $targetFile
71 * @param array $configuration
73 public function __construct(Resource\ProcessedFile
$targetFile, array $configuration) {
74 $this->targetFile
= $targetFile;
75 $this->sourceFile
= $targetFile->getOriginalFile();
76 $this->configuration
= $configuration;
80 * Sets parameters needed in the checksum. Can be overridden to add additional parameters to the checksum.
81 * This should include all parameters that could possibly vary between different task instances, e.g. the
82 * TYPO3 image configuration in TYPO3_CONF_VARS[GFX] for graphic processing tasks.
86 protected function getChecksumData() {
88 $this->getSourceFile()->getUid(),
89 $this->getType() . '.' . $this->getName() . $this->getSourceFile()->getModificationTime(),
90 serialize($this->configuration
)
95 * Returns the checksum for this task's configuration, also taking the file and task type into account.
99 public function getConfigurationChecksum() {
100 return \TYPO3\CMS\Core\Utility\GeneralUtility
::shortMD5(implode('|', $this->getChecksumData()));
104 * Returns the filename
108 public function getTargetFilename() {
109 return $this->targetFile
->getNameWithoutExtension()
110 . '_' . $this->getConfigurationChecksum()
111 . '.' . $this->getTargetFileExtension();
115 * Gets the file extension the processed file should
116 * have in the filesystem.
120 public function getTargetFileExtension() {
121 return $this->targetFile
->getExtension();
125 * Returns the name of this task
129 public function getName() {
134 * Returns the type of this task
138 public function getType() {
143 * @return Resource\ProcessedFile
145 public function getTargetFile() {
146 return $this->targetFile
;
150 * @param Resource\ProcessedFile $targetFile
152 public function setTargetFile(Resource\ProcessedFile
$targetFile) {
153 $this->targetFile
= $targetFile;
157 * @return Resource\File
159 public function getSourceFile() {
160 return $this->sourceFile
;
164 * @param Resource\File $sourceFile
166 public function setSourceFile(Resource\File
$sourceFile) {
167 $this->sourceFile
= $sourceFile;
173 public function getConfiguration() {
174 return $this->configuration
;
178 * Checks if the given configuration is sensible for this task, i.e. if all required parameters
179 * are given, within the boundaries and don't conflict with each other.
181 * @param array $configuration
184 abstract protected function isValidConfiguration(array $configuration);
187 * Returns TRUE if this task has been executed, no matter if the execution was successful.
191 public function isExecuted() {
192 return $this->executed
;
196 * Set this task executed. This is used by the Processors in order to transfer the state of this task to
197 * the file processing service.
199 * @param boolean $successful Set this to FALSE if executing the task failed
202 public function setExecuted($successful) {
203 $this->executed
= TRUE
;
204 $this->successful
= $successful;
208 * Returns TRUE if this task has been successfully executed. Only call this method if the task has been processed
211 * @throws \LogicException If the task has not been executed already
213 public function isSuccessful() {
214 if (!$this->executed
) {
215 throw new \
LogicException('Task has not been executed; cannot determine success.', 1352549235);
218 return $this->successful
;