add indexing task

This commit is contained in:
Uwe Steinmann 2020-09-30 09:11:13 +02:00
parent 9b357ec3d9
commit 8d2de27828
5 changed files with 150 additions and 8 deletions

View File

@ -37,11 +37,14 @@ class SeedDMS_SchedulerTaskBase {
var $logger;
public function __construct($dms=null, $user=null, $settings=null, $logger=null) { /* {{{ */
var $fulltextservice;
public function __construct($dms=null, $user=null, $settings=null, $logger=null, $fulltextservice=null) { /* {{{ */
$this->dms = $dms;
$this->user = $user;
$this->settings = $settings;
$this->logger = $logger;
$this->fulltextservice = $fulltextservice;
} /* }}} */
public function execute($task) { /* {{{ */

View File

@ -7,7 +7,7 @@ require_once("inc/inc.ClassSchedulerTaskBase.php");
*
* @author Uwe Steinmann <uwe@steinmann.cx>
* @package SeedDMS
* @subpackage trash
* @subpackage core
*/
class SeedDMS_ExpiredDocumentsTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
@ -43,4 +43,143 @@ class SeedDMS_ExpiredDocumentsTask extends SeedDMS_SchedulerTaskBase { /* {{{ */
}
} /* }}} */
/**
* Class for processing a single folder
*
* SeedDMS_Task_Indexer_Process_Folder::process() is used as a callable when
* iterating over all folders recursively.
*/
class SeedDMS_Task_Indexer_Process_Folder { /* {{{ */
protected $forceupdate;
protected $fulltextservice;
public function __construct($fulltextservice, $forceupdate) { /* {{{ */
$this->fulltextservice = $fulltextservice;
$this->forceupdate = $forceupdate;
} /* }}} */
public function process($folder) { /* {{{ */
$documents = $folder->getDocuments();
if($documents) {
$lucenesearch = $this->fulltextservice->Search();
echo $folder->getFolderPathPlain()."\n";
foreach($documents as $document) {
echo $document->getId().":".$document->getName()." ";
/* If the document wasn't indexed before then just add it */
if(!($hit = $lucenesearch->getDocument($document->getId()))) {
try {
$idoc = $this->fulltextservice->IndexedDocument($document, true);
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) {
if (method_exists($hookObj, 'preIndexDocument')) {
$hookObj->preIndexDocument(null, $document, $idoc);
}
}
}
$this->fulltextservice->Indexer()->addDocument($idoc);
echo " (Document added)".PHP_EOL;
} catch(Exception $e) {
echo " (Timeout)".PHP_EOL;
}
} else {
/* Check if the attribute created is set or has a value older
* than the lastet content. Documents without such an attribute
* where added when a new document was added to the dms. In such
* a case the document content wasn't indexed.
*/
try {
$created = (int) $hit->getDocument()->getFieldValue('created');
} catch (/* Zend_Search_Lucene_ */Exception $e) {
$created = 0;
}
$content = $document->getLatestContent();
if($created >= $content->getDate() && !$this->forceupdate) {
echo getMLText('index_document_unchanged').PHP_EOL;
} else {
$this->fulltextservice->Indexer()->delete($hit->id);
try {
$idoc = $this->fulltextservice->IndexedDocument($document, true);
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) {
if (method_exists($hookObj, 'preIndexDocument')) {
$hookObj->preIndexDocument(null, $document, $idoc);
}
}
}
$this->fulltextservice->Indexer()->addDocument($idoc);
echo " (Document updated)".PHP_EOL;
} catch(Exception $e) {
echo " (Timeout)".PHP_EOL;
}
}
}
}
}
} /* }}} */
} /* }}} */
/**
* Class containing methods for running a scheduled task
*
* @author Uwe Steinmann <uwe@steinmann.cx>
* @package SeedDMS
* @subpackage core
*/
class SeedDMS_IndexingDocumentsTask 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;
$fulltextservice = $this->fulltextservice;
$taskparams = $task->getParameter();
$folder = $dms->getRootFolder();
$recreate = isset($taskparams['recreate']) ? $taskparams['recreate'] : false;
if($fulltextservice) {
if($recreate) {
$index = $fulltextservice->Indexer(true);
if(!$index) {
UI::exitError(getMLText("admin_tools"),getMLText("no_fulltextindex"));
}
} else {
$index = $fulltextservice->Indexer(false);
if(!$index) {
$index = $fulltextservice->Indexer(true);
if(!$index) {
UI::exitError(getMLText("admin_tools"),getMLText("no_fulltextindex"));
}
}
}
}
$folderprocess = new SeedDMS_Task_Indexer_Process_Folder($fulltextservice, $recreate);
$tree = new SeedDMS_FolderTree($folder, array($folderprocess, 'process'));
call_user_func(array($folderprocess, 'process'), $folder);
return true;
}
public function getDescription() {
return 'Indexing all new or updated documents';
}
public function getAdditionalParams() {
return array(
array(
'name'=>'recreate',
'type'=>'boolean',
'description'=> 'Force recreation of index',
)
);
}
} /* }}} */
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['expireddocs'] = 'SeedDMS_ExpiredDocumentsTask';
$GLOBALS['SEEDDMS_SCHEDULER']['tasks']['core']['indexingdocs'] = 'SeedDMS_IndexingDocumentsTask';

View File

@ -650,13 +650,13 @@ function seed_pass_verify($password, $hash) { /* {{{ */
} /* }}} */
function resolveTask($task) {
global $dms, $user, $settings, $logger;
global $dms, $user, $settings, $logger, $fulltextservice;
if(is_object($task))
return $task;
if(is_string($task)) {
if(class_exists($task)) {
$task = new $task($dms, $user, $settings, $logger);
$task = new $task($dms, $user, $settings, $logger, $fulltextservice);
}
}
return $task;
@ -741,7 +741,7 @@ class SeedDMS_FolderTree { /* {{{ */
public function __construct($folder, $callback) { /* {{{ */
$iter = new \SeedDMS\RecursiveFolderIterator($folder);
$iter2 = new RecursiveIteratorIterator($iter, RecursiveIteratorIterator:: SELF_FIRST);
$iter2 = new RecursiveIteratorIterator($iter, RecursiveIteratorIterator::SELF_FIRST);
foreach($iter2 as $ff) {
call_user_func($callback, $ff);
// echo $ff->getID().': '.$ff->getFolderPathPlain().'-'.$ff->getName()."<br />";

View File

@ -53,7 +53,7 @@ if ($action == "addtask") { /* {{{ */
$description = $_POST["description"];
$frequency = $_POST["frequency"];
$disabled = isset($_POST["disabled"]) ? $_POST["disabled"] : 0;
$params = $_POST["params"];
$params = isset($_POST["params"]) ? $_POST["params"] : null;
$newtask = $scheduler->addTask($extension, $task, $name, $description, $frequency, $disabled, $params);
if ($newtask) {
@ -90,7 +90,7 @@ else if ($action == "edittask") { /* {{{ */
$description = $_POST["description"];
$frequency = $_POST["frequency"];
$disabled = isset($_POST["disabled"]) ? $_POST["disabled"] : 0;
$params = $_POST["params"];
$params = isset($_POST["params"]) ? $_POST["params"] : null;
if ($editedtask->getName() != $name)
$editedtask->setName($name);

View File

@ -27,7 +27,7 @@ require_once("class.Bootstrap.php");
class SeedDMS_View_Indexer_Process_Folder { /* {{{ */
protected $forceupdate;
protected $index;
protected $fulltextservice;
public function __construct($fulltextservice, $forceupdate) { /* {{{ */
$this->fulltextservice = $fulltextservice;