2011-07-21 07:11:39 +00:00
|
|
|
|
<?php
|
2020-02-03 17:28:45 +00:00
|
|
|
|
if(isset($_SERVER['SEEDDMS_HOME'])) {
|
2020-09-03 18:11:15 +00:00
|
|
|
|
ini_set('include_path', $_SERVER['SEEDDMS_HOME'].'/utils'. PATH_SEPARATOR .ini_get('include_path'));
|
|
|
|
|
$myincpath = $_SERVER['SEEDDMS_HOME'];
|
2020-02-03 17:28:45 +00:00
|
|
|
|
} else {
|
2020-09-03 18:11:15 +00:00
|
|
|
|
ini_set('include_path', dirname($argv[0]). PATH_SEPARATOR .ini_get('include_path'));
|
|
|
|
|
$myincpath = dirname($argv[0]);
|
2020-02-03 17:28:45 +00:00
|
|
|
|
}
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
|
|
|
|
function usage() { /* {{{ */
|
2020-06-03 16:21:23 +00:00
|
|
|
|
echo "Usage:".PHP_EOL;
|
2020-08-26 13:26:17 +00:00
|
|
|
|
echo " seeddms-indexer [-h] [-v] [-c] [--config <file>]".PHP_EOL;
|
2020-09-04 07:21:40 +00:00
|
|
|
|
echo PHP_EOL;
|
2020-06-03 16:21:23 +00:00
|
|
|
|
echo "Description:".PHP_EOL;
|
2022-07-28 19:11:29 +00:00
|
|
|
|
echo " This program recreates or updates the full text index of SeedDMS.".PHP_EOL;
|
2020-09-04 07:21:40 +00:00
|
|
|
|
echo PHP_EOL;
|
2020-06-03 16:21:23 +00:00
|
|
|
|
echo "Options:".PHP_EOL;
|
|
|
|
|
echo " -h, --help: print usage information and exit.".PHP_EOL;
|
|
|
|
|
echo " -v, --version: print version and exit.".PHP_EOL;
|
|
|
|
|
echo " -c: recreate index.".PHP_EOL;
|
2022-05-12 07:02:24 +00:00
|
|
|
|
echo " --no-log: do not log.".PHP_EOL;
|
2020-06-03 16:21:23 +00:00
|
|
|
|
echo " --config: set alternative config file.".PHP_EOL;
|
2011-07-21 07:11:39 +00:00
|
|
|
|
} /* }}} */
|
|
|
|
|
|
2022-05-12 07:02:24 +00:00
|
|
|
|
$version = "0.0.3";
|
2015-06-26 14:17:02 +00:00
|
|
|
|
$shortoptions = "hvc";
|
2022-05-12 07:02:24 +00:00
|
|
|
|
$longoptions = array('help', 'version', 'config:', 'no-log');
|
2011-07-21 07:11:39 +00:00
|
|
|
|
if(false === ($options = getopt($shortoptions, $longoptions))) {
|
|
|
|
|
usage();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print help and exit */
|
|
|
|
|
if(isset($options['h']) || isset($options['help'])) {
|
|
|
|
|
usage();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print version and exit */
|
|
|
|
|
if(isset($options['v']) || isset($options['verѕion'])) {
|
2020-09-04 07:21:40 +00:00
|
|
|
|
echo $version.PHP_EOL;
|
2011-07-21 07:11:39 +00:00
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 19:11:29 +00:00
|
|
|
|
$config['log'] = true;
|
|
|
|
|
$config['verbosity'] = 3;
|
|
|
|
|
$config['stats'] = true;
|
|
|
|
|
|
2011-07-21 07:11:39 +00:00
|
|
|
|
/* Set alternative config file */
|
|
|
|
|
if(isset($options['config'])) {
|
2020-09-03 18:11:15 +00:00
|
|
|
|
define('SEEDDMS_CONFIG_FILE', $options['config']);
|
|
|
|
|
} elseif(isset($_SERVER['SEEDDMS_CONFIG_FILE'])) {
|
|
|
|
|
define('SEEDDMS_CONFIG_FILE', $_SERVER['SEEDDMS_CONFIG_FILE']);
|
2011-07-21 07:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-26 14:17:02 +00:00
|
|
|
|
/* recreate index */
|
|
|
|
|
$recreate = false;
|
|
|
|
|
if(isset($options['c'])) {
|
|
|
|
|
$recreate = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 18:11:15 +00:00
|
|
|
|
include($myincpath."/inc/inc.Settings.php");
|
2022-07-28 19:11:29 +00:00
|
|
|
|
if(empty($options['no-log'])) {
|
|
|
|
|
$config['log'] = false;
|
2022-05-12 07:02:24 +00:00
|
|
|
|
include($myincpath."/inc/inc.LogInit.php");
|
2022-07-28 19:11:29 +00:00
|
|
|
|
}
|
2020-09-03 18:11:15 +00:00
|
|
|
|
include($myincpath."/inc/inc.Init.php");
|
|
|
|
|
include($myincpath."/inc/inc.Extension.php");
|
|
|
|
|
include($myincpath."/inc/inc.DBInit.php");
|
2013-02-14 10:27:51 +00:00
|
|
|
|
|
2020-12-12 15:29:56 +00:00
|
|
|
|
function tree($dms, $fulltextservice, $folder, $indent='', $numdocs) { /* {{{ */
|
2022-07-28 19:11:29 +00:00
|
|
|
|
global $settings, $themes, $config, $stats;
|
2020-12-12 15:29:56 +00:00
|
|
|
|
|
|
|
|
|
$index = $fulltextservice->Indexer();
|
|
|
|
|
$lucenesearch = $fulltextservice->Search();
|
|
|
|
|
|
2022-07-28 19:11:29 +00:00
|
|
|
|
$prefix = $themes->black(($config['verbosity'] >= 3 ? $indent : '')."D ".$folder->getId().":".$folder->getName()." ");
|
2020-12-12 15:29:56 +00:00
|
|
|
|
if(($numdocs == 0) || !($hit = $lucenesearch->getFolder($folder->getId()))) {
|
|
|
|
|
try {
|
|
|
|
|
$idoc = $fulltextservice->IndexedDocument($folder, true);
|
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexFolder'])) {
|
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['indexFolder'] as $hookObj) {
|
|
|
|
|
if (method_exists($hookObj, 'preIndexFolder')) {
|
|
|
|
|
$hookObj->preIndexDocument(null, $folder, $idoc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-15 11:24:12 +00:00
|
|
|
|
if($index->addDocument($idoc)) {
|
|
|
|
|
echo $prefix.$themes->green(" (Folder added)").PHP_EOL;
|
|
|
|
|
$stats['folder']['add']++;
|
|
|
|
|
} else {
|
|
|
|
|
$stats['folder']['error']++;
|
|
|
|
|
echo $prefix.$themes->error(" (Failed)").PHP_EOL;
|
|
|
|
|
}
|
2020-12-12 15:29:56 +00:00
|
|
|
|
} catch(Exception $e) {
|
2023-01-10 15:27:17 +00:00
|
|
|
|
$stats['folder']['error']++;
|
2022-07-28 19:11:29 +00:00
|
|
|
|
echo $prefix.$themes->error(" (Timeout)").PHP_EOL;
|
2020-12-12 15:29:56 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
2023-01-10 15:27:17 +00:00
|
|
|
|
$indexed = (int) $hit->getDocument()->getFieldValue('indexed');
|
2020-12-12 15:29:56 +00:00
|
|
|
|
} catch (Exception $e) {
|
2023-01-10 15:27:17 +00:00
|
|
|
|
$indexed = 0;
|
2020-12-12 15:29:56 +00:00
|
|
|
|
}
|
2023-01-10 15:27:17 +00:00
|
|
|
|
if($indexed >= $folder->getDate()) {
|
2022-07-28 19:11:29 +00:00
|
|
|
|
if($config['verbosity'] >= 3)
|
|
|
|
|
echo $prefix.$themes->italic(" (Folder unchanged)").PHP_EOL;
|
2022-07-28 09:59:27 +00:00
|
|
|
|
$stats['folder']['unchanged']++;
|
2020-12-12 15:29:56 +00:00
|
|
|
|
} else {
|
|
|
|
|
$index->delete($hit->id);
|
|
|
|
|
try {
|
|
|
|
|
$idoc = $fulltextservice->IndexedDocument($folder, true);
|
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) {
|
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) {
|
|
|
|
|
if (method_exists($hookObj, 'preIndexDocument')) {
|
|
|
|
|
$hookObj->preIndexDocument(null, $folder, $idoc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-15 11:24:12 +00:00
|
|
|
|
if($index->addDocument($idoc)) {
|
|
|
|
|
echo $prefix.$themes->green(" (Folder updated)").PHP_EOL;
|
|
|
|
|
$stats['folder']['update']++;
|
|
|
|
|
} else {
|
|
|
|
|
$stats['folder']['error']++;
|
|
|
|
|
echo $prefix.$themes->error(" (Failed)").PHP_EOL;
|
|
|
|
|
}
|
2020-12-12 15:29:56 +00:00
|
|
|
|
} catch(Exception $e) {
|
2023-01-10 15:27:17 +00:00
|
|
|
|
$stats['folder']['error']++;
|
2022-07-28 19:11:29 +00:00
|
|
|
|
echo $prefix.$themes->error(" (Timeout)").PHP_EOL;
|
2020-12-12 15:29:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-21 07:11:39 +00:00
|
|
|
|
$subfolders = $folder->getSubFolders();
|
|
|
|
|
foreach($subfolders as $subfolder) {
|
2020-12-12 15:29:56 +00:00
|
|
|
|
tree($dms, $fulltextservice, $subfolder, $indent.' ', $numdocs);
|
2011-07-21 07:11:39 +00:00
|
|
|
|
}
|
2020-12-12 15:29:56 +00:00
|
|
|
|
|
2011-07-21 07:11:39 +00:00
|
|
|
|
$documents = $folder->getDocuments();
|
|
|
|
|
foreach($documents as $document) {
|
2022-07-28 19:11:29 +00:00
|
|
|
|
$prefix = $themes->black(($config['verbosity'] >= 3 ? $indent : '')." ".$document->getId().":".$document->getName()." ");
|
2020-12-12 15:29:56 +00:00
|
|
|
|
if(($numdocs == 0) || !($hit = $lucenesearch->getDocument($document->getId()))) {
|
2015-08-10 19:43:15 +00:00
|
|
|
|
try {
|
2020-09-09 17:49:15 +00:00
|
|
|
|
$idoc = $fulltextservice->IndexedDocument($document, true);
|
2018-11-13 07:47:46 +00:00
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) {
|
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) {
|
|
|
|
|
if (method_exists($hookObj, 'preIndexDocument')) {
|
|
|
|
|
$hookObj->preIndexDocument(null, $document, $idoc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-15 11:24:12 +00:00
|
|
|
|
if($index->addDocument($idoc)) {
|
|
|
|
|
echo $prefix.$themes->green(" (Document added)").PHP_EOL;
|
|
|
|
|
$stats['document']['add']++;
|
|
|
|
|
} else {
|
|
|
|
|
$stats['document']['error']++;
|
|
|
|
|
echo $prefix.$themes->error(" (Failed)").PHP_EOL;
|
|
|
|
|
}
|
2015-08-10 19:43:15 +00:00
|
|
|
|
} catch(Exception $e) {
|
2023-01-10 15:27:17 +00:00
|
|
|
|
$stats['document']['error']++;
|
2022-07-28 19:11:29 +00:00
|
|
|
|
echo $prefix.$themes->error(" (Timeout)").PHP_EOL;
|
2015-08-10 19:43:15 +00:00
|
|
|
|
}
|
2011-07-21 07:11:39 +00:00
|
|
|
|
} else {
|
2015-06-26 14:17:02 +00:00
|
|
|
|
try {
|
2023-01-10 15:27:17 +00:00
|
|
|
|
$indexed = (int) $hit->getDocument()->getFieldValue('indexed');
|
2015-08-10 19:43:15 +00:00
|
|
|
|
} catch (Exception $e) {
|
2023-01-10 15:27:17 +00:00
|
|
|
|
$indexed = 0;
|
2015-06-26 14:17:02 +00:00
|
|
|
|
}
|
|
|
|
|
$content = $document->getLatestContent();
|
2023-01-10 15:27:17 +00:00
|
|
|
|
if($indexed >= $content->getDate()) {
|
2022-07-28 19:11:29 +00:00
|
|
|
|
if($config['verbosity'] >= 3)
|
|
|
|
|
echo $prefix.$themes->italic(" (Document unchanged)").PHP_EOL;
|
2022-07-28 09:59:27 +00:00
|
|
|
|
$stats['document']['unchanged']++;
|
2011-07-21 07:11:39 +00:00
|
|
|
|
} else {
|
2016-04-05 15:03:03 +00:00
|
|
|
|
$index->delete($hit->id);
|
|
|
|
|
try {
|
2020-09-09 17:49:15 +00:00
|
|
|
|
$idoc = $fulltextservice->IndexedDocument($document, true);
|
2018-11-13 07:47:46 +00:00
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) {
|
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) {
|
|
|
|
|
if (method_exists($hookObj, 'preIndexDocument')) {
|
|
|
|
|
$hookObj->preIndexDocument(null, $document, $idoc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-15 11:24:12 +00:00
|
|
|
|
if($index->addDocument($idoc)) {
|
|
|
|
|
echo $prefix.$themes->green(" (Document updated)").PHP_EOL;
|
|
|
|
|
$stats['document']['update']++;
|
|
|
|
|
} else {
|
|
|
|
|
$stats['document']['error']++;
|
|
|
|
|
echo $prefix.$themes->error(" (Failed)").PHP_EOL;
|
|
|
|
|
}
|
2016-04-05 15:03:03 +00:00
|
|
|
|
} catch(Exception $e) {
|
2023-01-10 15:27:17 +00:00
|
|
|
|
$stats['document']['error']++;
|
2022-07-28 19:11:29 +00:00
|
|
|
|
echo $prefix.$themes->error(" (Timeout)").PHP_EOL;
|
2011-07-21 07:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-10 19:43:15 +00:00
|
|
|
|
} /* }}} */
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
2020-06-03 16:21:23 +00:00
|
|
|
|
$themes = new \AlecRabbit\ConsoleColour\Themes();
|
|
|
|
|
|
2020-09-09 17:49:15 +00:00
|
|
|
|
$index = $fulltextservice->Indexer($recreate);
|
2015-08-10 19:43:15 +00:00
|
|
|
|
if(!$index) {
|
2020-09-04 07:21:40 +00:00
|
|
|
|
echo $themes->error("Could not create index.").PHP_EOL;
|
2015-08-10 19:43:15 +00:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 09:59:27 +00:00
|
|
|
|
$stats['folder']['add'] = 0;
|
|
|
|
|
$stats['folder']['unchanged'] = 0;
|
|
|
|
|
$stats['folder']['update'] = 0;
|
2023-01-10 15:27:17 +00:00
|
|
|
|
$stats['folder']['error'] = 0;
|
2022-07-28 09:59:27 +00:00
|
|
|
|
$stats['document']['add'] = 0;
|
|
|
|
|
$stats['document']['unchanged'] = 0;
|
|
|
|
|
$stats['document']['update'] = 0;
|
2023-01-10 15:27:17 +00:00
|
|
|
|
$stats['document']['error'] = 0;
|
2023-01-09 14:32:38 +00:00
|
|
|
|
$stats['time']['total'] = time();
|
2020-12-12 15:29:56 +00:00
|
|
|
|
$numdocs = $fulltextservice->Indexer()->count();
|
2023-04-14 10:47:57 +00:00
|
|
|
|
$dms->usecache = true;
|
2011-07-21 07:11:39 +00:00
|
|
|
|
$folder = $dms->getFolder($settings->_rootFolderID);
|
2020-12-12 15:29:56 +00:00
|
|
|
|
/* if numdocs is 0, then there is no need to check if a document/folder is already
|
|
|
|
|
* indexed. That speeds up the indexing.
|
|
|
|
|
*/
|
|
|
|
|
tree($dms, $fulltextservice, $folder,'', $numdocs);
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
|
|
|
|
$index->commit();
|
2015-06-26 14:17:02 +00:00
|
|
|
|
$index->optimize();
|
2023-01-09 14:32:38 +00:00
|
|
|
|
$stats['time']['total'] = time()-$stats['time']['total'];
|
2022-07-28 09:59:27 +00:00
|
|
|
|
|
|
|
|
|
echo PHP_EOL;
|
2023-01-09 14:32:38 +00:00
|
|
|
|
echo $themes->black("Total Time: ".$stats['time']['total'].' sec.').PHP_EOL;
|
2022-07-28 09:59:27 +00:00
|
|
|
|
echo $themes->black("Documents").PHP_EOL;
|
|
|
|
|
echo $themes->black(" added: ".$stats['document']['add']).PHP_EOL;
|
|
|
|
|
echo $themes->black(" updated: ".$stats['document']['update']).PHP_EOL;
|
|
|
|
|
echo $themes->black(" unchanged: ".$stats['document']['unchanged']).PHP_EOL;
|
2023-01-10 15:27:17 +00:00
|
|
|
|
echo $themes->black(" error: ".$stats['document']['error']).PHP_EOL;
|
2022-07-28 09:59:27 +00:00
|
|
|
|
echo $themes->black("Folders").PHP_EOL;
|
|
|
|
|
echo $themes->black(" added: ".$stats['folder']['add']).PHP_EOL;
|
|
|
|
|
echo $themes->black(" updated: ".$stats['folder']['update']).PHP_EOL;
|
|
|
|
|
echo $themes->black(" unchanged: ".$stats['folder']['unchanged']).PHP_EOL;
|
2023-01-10 15:27:17 +00:00
|
|
|
|
echo $themes->black(" error: ".$stats['folder']['error']).PHP_EOL;
|