Skip to content

Commit

Permalink
[FEATURE] Added SignalSlotDispatcher in the getFileForLocalProcessing…
Browse files Browse the repository at this point in the history
… function. (#38)

That allow processing temporary file before they will be prossed in graphic functions.

Example: we decrease size in the to large files, over 4000 x 4000, before imagemagick processing because him spend a lot of memory for this files.
  • Loading branch information
Atsyn authored and Lagerregal committed Jul 17, 2018
1 parent 475203d commit 355902c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Classes/Driver/AmazonS3Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/**
Expand Down Expand Up @@ -149,6 +150,11 @@ class AmazonS3Driver extends AbstractHierarchicalFilesystemDriver
*/
protected $temporaryPaths = [];

/**
* @var Dispatcher
*/
protected $signalSlotDispatcher;

/**
* AmazonS3Driver constructor.
*
Expand Down Expand Up @@ -499,12 +505,29 @@ public function getFileForLocalProcessing($fileIdentifier, $writable = true)
if (!is_file($temporaryPath)) {
throw new \RuntimeException('Copying file ' . $fileIdentifier . ' to temporary path failed.', 1320577649);
}
$this->emitGetFileForLocalProcessingSignal($fileIdentifier, $temporaryPath, $writable);
if (!isset($this->temporaryPaths[$temporaryPath])) {
$this->temporaryPaths[$temporaryPath] = $temporaryPath;
}
return $temporaryPath;
}

/**
* @param string $fileIdentifier
* @param string $temporaryPath
* @param bool $writable
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException
*/
protected function emitGetFileForLocalProcessingSignal(&$fileIdentifier, &$temporaryPath, &$writable)
{
list($fileIdentifier, $temporaryPath, $writable) = $this->getSignalSlotDispatcher()->dispatch(
self::class,
'getFileForLocalProcessing',
[$fileIdentifier, $temporaryPath, $writable]
);
}

/**
* Creates a new (empty) file and returns the identifier.
*
Expand Down Expand Up @@ -1602,4 +1625,17 @@ protected function applyFilterMethodsToDirectoryItem(array $filterMethods, $item
}
return true;
}

/**
* Get the SignalSlot dispatcher
*
* @return Dispatcher
*/
protected function getSignalSlotDispatcher()
{
if (!isset($this->signalSlotDispatcher)) {
$this->signalSlotDispatcher = GeneralUtility::makeInstance(ObjectManager::class)->get(Dispatcher::class);
}
return $this->signalSlotDispatcher;
}
}

0 comments on commit 355902c

Please sign in to comment.