Skip to content

Commit

Permalink
[TASK] Streamline FAL pre-emit signals for createFile and setContent
Browse files Browse the repository at this point in the history
In order to streamline the FAL API the following signals have been added.
The according post-processing signals have been available already before:

+ ResourceStorageInterface::SIGNAL_PreFileCreate
+ ResourceStorageInterface::SIGNAL_PreFileSetContents

Resolves: #85434
Releases: master, 8.7
Change-Id: I41fc07afbc4e1a393c8a26fe02f431a7b62015d8
Reviewed-on: https://review.typo3.org/57418
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
  • Loading branch information
ohader authored and fsaris committed Jun 30, 2018
1 parent e81f7e7 commit dda2f6c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions typo3/sysext/core/Classes/Resource/ResourceStorage.php
Expand Up @@ -1680,6 +1680,7 @@ public function setFileContents(AbstractFile $file, $contents)
{
// Check if user is allowed to edit
$this->assureFileWritePermissions($file);
$this->emitPreFileSetContentsSignal($file, $contents);
// Call driver method to update the file and update file index entry afterwards
$result = $this->driver->setFileContents($file->getIdentifier(), $contents);
if ($file instanceof File) {
Expand All @@ -1704,6 +1705,7 @@ public function setFileContents(AbstractFile $file, $contents)
public function createFile($fileName, Folder $targetFolderObject)
{
$this->assureFileAddPermissions($targetFolderObject, $fileName);
$this->emitPreFileCreateSignal($fileName, $targetFolderObject);
$newFileIdentifier = $this->driver->createFile($fileName, $targetFolderObject->getIdentifier());
$this->emitPostFileCreateSignal($newFileIdentifier, $targetFolderObject);
return $this->getResourceFactoryInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $newFileIdentifier);
Expand Down Expand Up @@ -2565,6 +2567,17 @@ protected function emitPostFileReplaceSignal(FileInterface $file, $localFilePath
$this->getSignalSlotDispatcher()->dispatch(self::class, self::SIGNAL_PostFileReplace, [$file, $localFilePath]);
}

/**
* Emits the file pre-create signal
*
* @param string $fileName
* @param Folder $targetFolder
*/
protected function emitPreFileCreateSignal(string $fileName, Folder $targetFolder)
{
$this->getSignalSlotDispatcher()->dispatch(self::class, self::SIGNAL_PreFileCreate, [$fileName, $targetFolder]);
}

/**
* Emits the file post-create signal
*
Expand Down Expand Up @@ -2596,6 +2609,17 @@ protected function emitPostFileDeleteSignal(FileInterface $file)
$this->getSignalSlotDispatcher()->dispatch(self::class, self::SIGNAL_PostFileDelete, [$file]);
}

/**
* Emits the file pre-set-contents signal
*
* @param FileInterface $file
* @param mixed $content
*/
protected function emitPreFileSetContentsSignal(FileInterface $file, $content)
{
$this->getSignalSlotDispatcher()->dispatch(self::class, self::SIGNAL_PreFileSetContents, [$file, $content]);
}

/**
* Emits the file post-set-contents signal
*
Expand Down
Expand Up @@ -22,6 +22,7 @@ interface ResourceStorageInterface
const SIGNAL_SanitizeFileName = 'sanitizeFileName';
const SIGNAL_PreFileAdd = 'preFileAdd';
const SIGNAL_PostFileAdd = 'postFileAdd';
const SIGNAL_PreFileCreate = 'preFileCreate';
const SIGNAL_PostFileCreate = 'postFileCreate';
const SIGNAL_PreFileCopy = 'preFileCopy';
const SIGNAL_PostFileCopy = 'postFileCopy';
Expand All @@ -33,6 +34,7 @@ interface ResourceStorageInterface
const SIGNAL_PostFileRename = 'postFileRename';
const SIGNAL_PreFileReplace = 'preFileReplace';
const SIGNAL_PostFileReplace = 'postFileReplace';
const SIGNAL_PreFileSetContents = 'preFileSetContents';
const SIGNAL_PostFileSetContents = 'postFileSetContents';
const SIGNAL_PreFolderAdd = 'preFolderAdd';
const SIGNAL_PostFolderAdd = 'postFolderAdd';
Expand Down

0 comments on commit dda2f6c

Please sign in to comment.