From c53b3babbdeb96277c8ddf2d426552179da87301 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Sun, 9 May 2021 13:41:53 +0200 Subject: [PATCH] add task for creating missing preview images --- inc/inc.Tasks.php | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/inc/inc.Tasks.php b/inc/inc.Tasks.php index 246f5cb8b..591276610 100644 --- a/inc/inc.Tasks.php +++ b/inc/inc.Tasks.php @@ -289,6 +289,87 @@ class SeedDMS_CheckSumTask extends SeedDMS_SchedulerTaskBase { /* {{{ */ } } /* }}} */ +/** + * Class for processing a single folder + * + * SeedDMS_Task_Preview_Process_Folder::process() is used as a callable when + * iterating over all folders recursively. + */ +class SeedDMS_Task_Preview_Process_Folder { /* {{{ */ + protected $logger; + + protected $previewer; + + protected $widths; + + public function __construct($previewer, $widths, $logger) { /* {{{ */ + $this->logger = $logger; + $this->previewer = $previewer; + $this->widths = $widths; + } /* }}} */ + + public function process($folder) { /* {{{ */ + $dms = $folder->getDMS(); + $documents = $folder->getDocuments(); + if($documents) { + foreach($documents as $document) { + $versions = $document->getContent(); + foreach($versions as $version) { + foreach($this->widths as $width) { + if($this->previewer->createPreview($version, $width)) { + $this->logger->log('Task \'preview\': created preview ('.$width.'px) for document '.$document->getId().':'.$version->getVersion(), PEAR_LOG_INFO); +// echo "Preview ".$width."px for ".$document->getId().":".$version->getVersion()." created\n"; + } + } + } + } + } + } /* }}} */ +} /* }}} */ + +/** + * Class containing methods for running a scheduled task + * + * @author Uwe Steinmann + * @package SeedDMS + * @subpackage core + */ +class SeedDMS_PreviewTask extends SeedDMS_SchedulerTaskBase { /* {{{ */ + + /** + * Run the task + * + * @param $task task to be executed + * @param $dms dms + * @return boolean true if task was executed succesfully, otherwise false + */ + public function execute($task) { + $dms = $this->dms; + $logger = $this->logger; + $settings = $this->settings; + $taskparams = $task->getParameter(); + $folder = $dms->getRootFolder(); + + $previewer = new SeedDMS_Preview_Previewer($settings->_cacheDir); + + $folderprocess = new SeedDMS_Task_Preview_Process_Folder($previewer, array($settings->_previewWidthList, $settings->_previewWidthDetail), $logger); + $tree = new SeedDMS_FolderTree($folder, array($folderprocess, 'process')); + call_user_func(array($folderprocess, 'process'), $folder); + + return true; + } + + public function getDescription() { + return 'Check all documents for a missing preview image'; + } + + public function getAdditionalParams() { + return array( + ); + } +} /* }}} */ + $GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['expireddocs'] = 'SeedDMS_ExpiredDocumentsTask'; $GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['indexingdocs'] = 'SeedDMS_IndexingDocumentsTask'; $GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['checksum'] = 'SeedDMS_CheckSumTask'; +$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['preview'] = 'SeedDMS_PreviewTask';