2011-07-21 07:11:39 +00:00
|
|
|
|
<?php
|
2020-02-03 17:28:45 +00:00
|
|
|
|
if(isset($_SERVER['SEEDDMS_HOME'])) {
|
|
|
|
|
require_once($_SERVER['SEEDDMS_HOME']."/inc/inc.ClassSettings.php");
|
|
|
|
|
} else {
|
|
|
|
|
require_once("../inc/inc.ClassSettings.php");
|
|
|
|
|
}
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
|
|
|
|
function usage() { /* {{{ */
|
2020-06-03 16:21:23 +00:00
|
|
|
|
echo "Usage:".PHP_EOL;
|
|
|
|
|
echo " seeddms-indexer [-h] [-v] [--config <file>]".PHP_EOL;
|
|
|
|
|
echo "".PHP_EOL;
|
|
|
|
|
echo "Description:".PHP_EOL;
|
|
|
|
|
echo " This program recreates the full text index of SeedDMS.".PHP_EOL;
|
|
|
|
|
echo "".PHP_EOL;
|
|
|
|
|
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;
|
|
|
|
|
echo " --config: set alternative config file.".PHP_EOL;
|
2011-07-21 07:11:39 +00:00
|
|
|
|
} /* }}} */
|
|
|
|
|
|
2017-12-22 12:05:35 +00:00
|
|
|
|
$version = "0.0.2";
|
2015-06-26 14:17:02 +00:00
|
|
|
|
$shortoptions = "hvc";
|
2011-07-21 07:11:39 +00:00
|
|
|
|
$longoptions = array('help', 'version', 'config:');
|
|
|
|
|
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-06-03 16:21:23 +00:00
|
|
|
|
echo $version."".PHP_EOL;
|
2011-07-21 07:11:39 +00:00
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set alternative config file */
|
|
|
|
|
if(isset($options['config'])) {
|
|
|
|
|
$settings = new Settings($options['config']);
|
|
|
|
|
} else {
|
|
|
|
|
$settings = new Settings();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-26 14:17:02 +00:00
|
|
|
|
/* recreate index */
|
|
|
|
|
$recreate = false;
|
|
|
|
|
if(isset($options['c'])) {
|
|
|
|
|
$recreate = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 10:27:51 +00:00
|
|
|
|
if(isset($settings->_extraPath))
|
|
|
|
|
ini_set('include_path', $settings->_extraPath. PATH_SEPARATOR .ini_get('include_path'));
|
2020-02-03 17:28:45 +00:00
|
|
|
|
//ini_set('include_path', $settings->_rootDir. PATH_SEPARATOR .ini_get('include_path'));
|
|
|
|
|
|
|
|
|
|
require_once("inc/inc.Init.php");
|
|
|
|
|
require_once("inc/inc.Extension.php");
|
|
|
|
|
require_once("inc/inc.DBInit.php");
|
2020-06-03 16:21:23 +00:00
|
|
|
|
require "vendor/autoload.php";
|
2013-02-14 10:27:51 +00:00
|
|
|
|
|
2015-08-10 19:43:15 +00:00
|
|
|
|
if($settings->_fullSearchEngine == 'sqlitefts') {
|
|
|
|
|
$indexconf = array(
|
|
|
|
|
'Indexer' => 'SeedDMS_SQLiteFTS_Indexer',
|
|
|
|
|
'Search' => 'SeedDMS_SQLiteFTS_Search',
|
|
|
|
|
'IndexedDocument' => 'SeedDMS_SQLiteFTS_IndexedDocument'
|
|
|
|
|
);
|
2013-02-14 10:27:51 +00:00
|
|
|
|
|
2015-08-10 19:43:15 +00:00
|
|
|
|
require_once('SeedDMS/SQLiteFTS.php');
|
|
|
|
|
} else {
|
|
|
|
|
$indexconf = array(
|
|
|
|
|
'Indexer' => 'SeedDMS_Lucene_Indexer',
|
|
|
|
|
'Search' => 'SeedDMS_Lucene_Search',
|
|
|
|
|
'IndexedDocument' => 'SeedDMS_Lucene_IndexedDocument'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
require_once('SeedDMS/Lucene.php');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tree($dms, $index, $indexconf, $folder, $indent='') { /* {{{ */
|
2020-06-03 16:21:23 +00:00
|
|
|
|
global $settings, $themes;
|
|
|
|
|
echo $themes->black($indent."D ".$folder->getName()).PHP_EOL;
|
2011-07-21 07:11:39 +00:00
|
|
|
|
$subfolders = $folder->getSubFolders();
|
|
|
|
|
foreach($subfolders as $subfolder) {
|
2015-08-10 19:43:15 +00:00
|
|
|
|
tree($dms, $index, $indexconf, $subfolder, $indent.' ');
|
2011-07-21 07:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
$documents = $folder->getDocuments();
|
|
|
|
|
foreach($documents as $document) {
|
2015-06-26 14:17:02 +00:00
|
|
|
|
echo $indent." ".$document->getId().":".$document->getName()." ";
|
2015-08-10 19:43:15 +00:00
|
|
|
|
$lucenesearch = new $indexconf['Search']($index);
|
|
|
|
|
if(!($hit = $lucenesearch->getDocument($document->getId()))) {
|
|
|
|
|
try {
|
2017-12-22 12:05:35 +00:00
|
|
|
|
$idoc = new $indexconf['IndexedDocument']($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, false, $settings->_cmdTimeout);
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$index->addDocument($idoc);
|
2020-06-03 16:21:23 +00:00
|
|
|
|
echo $themes->green(" (Document added)").PHP_EOL;
|
2015-08-10 19:43:15 +00:00
|
|
|
|
} catch(Exception $e) {
|
2020-06-03 16:21:23 +00:00
|
|
|
|
echo $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 {
|
|
|
|
|
$created = (int) $hit->getDocument()->getFieldValue('created');
|
2015-08-10 19:43:15 +00:00
|
|
|
|
} catch (Exception $e) {
|
2015-06-26 14:17:02 +00:00
|
|
|
|
$created = 0;
|
|
|
|
|
}
|
|
|
|
|
$content = $document->getLatestContent();
|
2020-07-02 15:41:09 +00:00
|
|
|
|
if($created >= $content->getDate()) {
|
2020-06-03 16:21:23 +00:00
|
|
|
|
echo $themes->italic(" (Document unchanged)").PHP_EOL;
|
2011-07-21 07:11:39 +00:00
|
|
|
|
} else {
|
2016-04-05 15:03:03 +00:00
|
|
|
|
$index->delete($hit->id);
|
|
|
|
|
try {
|
2018-11-13 07:47:46 +00:00
|
|
|
|
$idoc = new $indexconf['IndexedDocument']($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null, false, $settings->_cmdTimeout);
|
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['indexDocument'])) {
|
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['indexDocument'] as $hookObj) {
|
|
|
|
|
if (method_exists($hookObj, 'preIndexDocument')) {
|
|
|
|
|
$hookObj->preIndexDocument(null, $document, $idoc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$index->addDocument($idoc);
|
2020-06-03 16:21:23 +00:00
|
|
|
|
echo $themes->green(" (Document updated)").PHP_EOL;
|
2016-04-05 15:03:03 +00:00
|
|
|
|
} catch(Exception $e) {
|
2020-06-03 16:21:23 +00:00
|
|
|
|
echo $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();
|
|
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
|
$db = new SeedDMS_Core_DatabaseAccess($settings->_dbDriver, $settings->_dbHostname, $settings->_dbUser, $settings->_dbPass, $settings->_dbDatabase);
|
2011-07-21 07:11:39 +00:00
|
|
|
|
$db->connect() or die ("Could not connect to db-server \"" . $settings->_dbHostname . "\"");
|
|
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
|
$dms = new SeedDMS_Core_DMS($db, $settings->_contentDir.$settings->_contentOffsetDir);
|
2020-06-03 16:21:23 +00:00
|
|
|
|
if(!$settings->_doNotCheckDBVersion && !$dms->checkVersion()) {
|
|
|
|
|
echo "Database update needed.".PHP_EOL;
|
2015-08-10 19:43:15 +00:00
|
|
|
|
exit(1);
|
2013-06-06 12:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-21 07:11:39 +00:00
|
|
|
|
$dms->setRootFolderID($settings->_rootFolderID);
|
|
|
|
|
|
2015-06-26 14:17:02 +00:00
|
|
|
|
if($recreate)
|
2015-08-10 19:43:15 +00:00
|
|
|
|
$index = $indexconf['Indexer']::create($settings->_luceneDir);
|
2015-06-26 14:17:02 +00:00
|
|
|
|
else
|
2015-08-10 19:43:15 +00:00
|
|
|
|
$index = $indexconf['Indexer']::open($settings->_luceneDir);
|
|
|
|
|
if(!$index) {
|
2020-06-03 16:21:23 +00:00
|
|
|
|
echo "Could not create index.".PHP_EOL;
|
2015-08-10 19:43:15 +00:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$indexconf['Indexer']::init($settings->_stopWordsFile);
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
|
|
|
|
$folder = $dms->getFolder($settings->_rootFolderID);
|
2015-08-10 19:43:15 +00:00
|
|
|
|
tree($dms, $index, $indexconf, $folder);
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
|
|
|
|
$index->commit();
|
2015-06-26 14:17:02 +00:00
|
|
|
|
$index->optimize();
|
2011-07-21 07:11:39 +00:00
|
|
|
|
?>
|