TYPO3 CMS  TYPO3_6-2
AbstractTask.php
Go to the documentation of this file.
1 <?php
3 
17 use \TYPO3\CMS\Core\Resource, \TYPO3\CMS\Core\Utility;
18 
27 abstract class AbstractTask implements TaskInterface {
28 
32  protected $checksumData = array();
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  $this->targetFile = $targetFile;
75  $this->sourceFile = $targetFile->getOriginalFile();
76  $this->configuration = $configuration;
77  }
78 
86  protected function getChecksumData() {
87  return array(
88  $this->getSourceFile()->getUid(),
89  $this->getType() . '.' . $this->getName() . $this->getSourceFile()->getModificationTime(),
90  serialize($this->configuration)
91  );
92  }
93 
99  public function getConfigurationChecksum() {
100  return \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5(implode('|', $this->getChecksumData()));
101  }
102 
108  public function getTargetFilename() {
109  return $this->targetFile->getNameWithoutExtension()
110  . '_' . $this->getConfigurationChecksum()
111  . '.' . $this->getTargetFileExtension();
112  }
113 
120  public function getTargetFileExtension() {
121  return $this->targetFile->getExtension();
122  }
123 
129  public function getName() {
130  return $this->name;
131  }
132 
138  public function getType() {
139  return $this->type;
140  }
141 
145  public function getTargetFile() {
146  return $this->targetFile;
147  }
148 
152  public function setTargetFile(Resource\ProcessedFile $targetFile) {
153  $this->targetFile = $targetFile;
154  }
155 
159  public function getSourceFile() {
160  return $this->sourceFile;
161  }
162 
166  public function setSourceFile(Resource\File $sourceFile) {
167  $this->sourceFile = $sourceFile;
168  }
169 
173  public function getConfiguration() {
174  return $this->configuration;
175  }
176 
184  abstract protected function isValidConfiguration(array $configuration);
185 
191  public function isExecuted() {
192  return $this->executed;
193  }
194 
202  public function setExecuted($successful) {
203  $this->executed = TRUE;
204  $this->successful = $successful;
205  }
206 
213  public function isSuccessful() {
214  if (!$this->executed) {
215  throw new \LogicException('Task has not been executed; cannot determine success.', 1352549235);
216  }
217 
218  return $this->successful;
219  }
220 }
setTargetFile(Resource\ProcessedFile $targetFile)
__construct(Resource\ProcessedFile $targetFile, array $configuration)