TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
core/Classes/Resource/Processing/AbstractTask.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Processing;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
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.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use TYPO3\CMS\Core\Resource;
19 
27 abstract class AbstractTask implements TaskInterface
28 {
32  protected $checksumData = [];
33 
37  protected $targetFile;
38 
42  protected $sourceFile;
43 
47  protected $configuration;
48 
52  protected $type;
53 
57  protected $name;
58 
62  protected $executed = false;
63 
67  protected $successful;
68 
73  public function __construct(Resource\ProcessedFile $targetFile, array $configuration)
74  {
75  $this->targetFile = $targetFile;
76  $this->sourceFile = $targetFile->getOriginalFile();
77  $this->configuration = $configuration;
78  }
79 
87  protected function getChecksumData()
88  {
89  return [
90  $this->getSourceFile()->getUid(),
91  $this->getType() . '.' . $this->getName() . $this->getSourceFile()->getModificationTime(),
92  serialize($this->configuration)
93  ];
94  }
95 
101  public function getConfigurationChecksum()
102  {
103  return GeneralUtility::shortMD5(implode('|', $this->getChecksumData()));
104  }
105 
111  public function getTargetFilename()
112  {
113  return $this->targetFile->getNameWithoutExtension()
114  . '_' . $this->getConfigurationChecksum()
115  . '.' . $this->getTargetFileExtension();
116  }
117 
124  public function getTargetFileExtension()
125  {
126  return $this->targetFile->getExtension();
127  }
128 
134  public function getName()
135  {
136  return $this->name;
137  }
138 
144  public function getType()
145  {
146  return $this->type;
147  }
148 
152  public function getTargetFile()
153  {
154  return $this->targetFile;
155  }
156 
160  public function setTargetFile(Resource\ProcessedFile $targetFile)
161  {
162  $this->targetFile = $targetFile;
163  }
164 
168  public function getSourceFile()
169  {
170  return $this->sourceFile;
171  }
172 
176  public function setSourceFile(Resource\File $sourceFile)
177  {
178  $this->sourceFile = $sourceFile;
179  }
180 
184  public function getConfiguration()
185  {
186  return $this->configuration;
187  }
188 
196  abstract protected function isValidConfiguration(array $configuration);
197 
203  public function isExecuted()
204  {
205  return $this->executed;
206  }
207 
215  public function setExecuted($successful)
216  {
217  $this->executed = true;
218  $this->successful = $successful;
219  }
220 
227  public function isSuccessful()
228  {
229  if (!$this->executed) {
230  throw new \LogicException('Task has not been executed; cannot determine success.', 1352549235);
231  }
232 
233  return $this->successful;
234  }
235 }
__construct(Resource\ProcessedFile $targetFile, array $configuration)