/** * Batch resizes pictures in a given parent directory (including all subdirectories * recursively). * * @param string $directory * @return boolean true if run was successful * @throws \RuntimeException */ protected function batchResizePictures($directory) { $directory = GeneralUtility::getFileAbsFileName($directory); // Check if given directory exists if (!@is_dir($directory)) { throw new \RuntimeException('Given directory "' . $directory . '" does not exist', 1384102984); } $allFileTypes = $this->imageResizer->getAllFileTypes(); // We do not want to pass any backend user, even if manually running the task as administrator from // the Backend as images may be resized based on usergroup rule sets and this should only happen when // actually resizing the image while uploading, not during a batch processing (it's simply "too late"). $backendUser = null; if ($GLOBALS['BE_USER']->isAdmin()) { // As the scheduler user should never be an administrator, if current user is an administrator // the task is most probably run manually from the Scheduler module, so just show notifications $callbackNotification = array($this, 'notify'); } else { $callbackNotification = array($this, 'syslog'); } $excludeDirectories = GeneralUtility::trimExplode(LF, $this->excludeDirectories, true); $directoryContent = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)); foreach ($directoryContent as $fileName => $file) { $filePath = $file->getPath(); $name = substr($fileName, strlen($filePath) + 1); // Skip files in recycler directory or whose type should not be processed $skip = $name[0] === '.' || substr($filePath, -10) === '_recycler_'; // Skip exclude directories foreach ($excludeDirectories as $excludeDirectory) { $excludeDirectory = GeneralUtility::getFileAbsFileName($excludeDirectory); if (GeneralUtility::isFirstPartOfStr($filePath, $excludeDirectory) || rtrim($excludeDirectory, '/') === $filePath) { $skip = true; continue; } } if (!$skip) { if (($dotPosition = strrpos($name, '.')) !== false) { $fileExtension = strtolower(substr($name, $dotPosition + 1)); if (in_array($fileExtension, $allFileTypes)) { $this->imageResizer->processFile($fileName, '', '', null, $backendUser, $callbackNotification); } } } } return true; }
/** * @param string $fileName Full path to the file to be processed * @param string $targetFileName Target file name if not converted, no path included * @param string $targetDirectory * @param File $file * @return string */ protected function processFile($fileName, &$targetFileName, $targetDirectory, File $file = null) { $newFileName = static::$imageResizer->processFile($fileName, $targetFileName, $targetDirectory, $file, $GLOBALS['BE_USER'], array($this, 'notify')); static::$metadata = static::$imageResizer->getLastMetadata(); return $newFileName; }