add a new task for checking the checksum of all versions

This commit is contained in:
Uwe Steinmann 2021-01-26 15:42:45 +01:00
parent 599786bcb0
commit a7286be63a

View File

@ -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 <uwe@steinmann.cx>
* @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';