From a7286be63ad7070448db994fdb5912f3229fc3ae Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 26 Jan 2021 15:42:45 +0100 Subject: [PATCH] add a new task for checking the checksum of all versions --- inc/inc.Tasks.php | 74 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/inc/inc.Tasks.php b/inc/inc.Tasks.php index c503eebcb..cc4a06abf 100644 --- a/inc/inc.Tasks.php +++ b/inc/inc.Tasks.php @@ -23,7 +23,7 @@ class SeedDMS_ExpiredDocumentsTask extends SeedDMS_SchedulerTaskBase { /* {{{ */ $taskparams = $task->getParameter(); $docs = $dms->getDocumentsExpired(intval($taskparams['days'])); foreach($docs as $doc) { - echo $doc->getName()."\n"; + echo $doc->getName().PHP_EOL; } return true; } @@ -63,7 +63,7 @@ class SeedDMS_Task_Indexer_Process_Folder { /* {{{ */ $documents = $folder->getDocuments(); if($documents) { $lucenesearch = $this->fulltextservice->Search(); - echo $folder->getFolderPathPlain()."\n"; + echo $folder->getFolderPathPlain().PHP_EOL; foreach($documents as $document) { echo $document->getId().":".$document->getName()." "; /* If the document wasn't indexed before then just add it */ @@ -181,5 +181,75 @@ class SeedDMS_IndexingDocumentsTask extends SeedDMS_SchedulerTaskBase { /* {{{ * } } /* }}} */ +/** + * Class for processing a single folder + * + * SeedDMS_Task_CheckSum_Process_Folder::process() is used as a callable when + * iterating over all folders recursively. + */ +class SeedDMS_Task_CheckSum_Process_Folder { /* {{{ */ + public function __construct() { /* {{{ */ + } /* }}} */ + + public function process($folder) { /* {{{ */ + $dms = $folder->getDMS(); + $documents = $folder->getDocuments(); + if($documents) { + foreach($documents as $document) { + $versions = $document->getContent(); + foreach($versions as $version) { + if(file_exists($dms->contentDir.$version->getPath())) { + $checksum = SeedDMS_Core_File::checksum($dms->contentDir.$version->getPath()); + if($checksum != $version->getChecksum()) { + echo $document->getId().':'.$version->getVersion().' wrong checksum'.PHP_EOL; + } + } else { + echo $document->getId().':'.$version->getVersion().' missing content'.PHP_EOL; + } + } + } + } + } /* }}} */ +} /* }}} */ + +/** + * Class containing methods for running a scheduled task + * + * @author Uwe Steinmann + * @package SeedDMS + * @subpackage core + */ +class SeedDMS_CheckSumTask 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; + $taskparams = $task->getParameter(); + $folder = $dms->getRootFolder(); + + $folderprocess = new SeedDMS_Task_CheckSum_Process_Folder(); + $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 propper checksum'; + } + + 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';