2011-07-21 07:11:39 +00:00
|
|
|
|
<?php
|
2013-02-14 10:27:51 +00:00
|
|
|
|
require_once("../inc/inc.ClassSettings.php");
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
|
|
|
|
function usage() { /* {{{ */
|
|
|
|
|
echo "Usage:\n";
|
2013-02-14 10:27:51 +00:00
|
|
|
|
echo " seeddms-indexer [-h] [-v] [--config <file>]\n";
|
2011-07-21 07:11:39 +00:00
|
|
|
|
echo "\n";
|
|
|
|
|
echo "Description:\n";
|
2013-02-14 11:10:53 +00:00
|
|
|
|
echo " This program recreates the full text index of SeedDMS.\n";
|
2011-07-21 07:11:39 +00:00
|
|
|
|
echo "\n";
|
|
|
|
|
echo "Options:\n";
|
|
|
|
|
echo " -h, --help: print usage information and exit.\n";
|
|
|
|
|
echo " -v, --version: print version and exit.\n";
|
|
|
|
|
echo " --config: set alternative config file.\n";
|
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
|
|
$version = "0.0.1";
|
|
|
|
|
$shortoptions = "hv";
|
|
|
|
|
$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'])) {
|
|
|
|
|
echo $version."\n";
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set alternative config file */
|
|
|
|
|
if(isset($options['config'])) {
|
|
|
|
|
$settings = new Settings($options['config']);
|
|
|
|
|
} else {
|
|
|
|
|
$settings = new Settings();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 10:27:51 +00:00
|
|
|
|
if(isset($settings->_extraPath))
|
|
|
|
|
ini_set('include_path', $settings->_extraPath. PATH_SEPARATOR .ini_get('include_path'));
|
|
|
|
|
|
2013-02-14 11:10:53 +00:00
|
|
|
|
require_once("SeedDMS/Core.php");
|
|
|
|
|
require_once("SeedDMS/Lucene.php");
|
2013-02-14 10:27:51 +00:00
|
|
|
|
|
2011-07-21 07:11:39 +00:00
|
|
|
|
function tree($folder, $indent='') {
|
2014-03-25 20:17:41 +00:00
|
|
|
|
global $index, $dms, $settings;
|
2011-07-21 07:11:39 +00:00
|
|
|
|
echo $indent."D ".$folder->getName()."\n";
|
|
|
|
|
$subfolders = $folder->getSubFolders();
|
|
|
|
|
foreach($subfolders as $subfolder) {
|
|
|
|
|
tree($subfolder, $indent.' ');
|
|
|
|
|
}
|
|
|
|
|
$documents = $folder->getDocuments();
|
|
|
|
|
foreach($documents as $document) {
|
|
|
|
|
echo $indent." ".$document->getId().":".$document->getName()."\n";
|
|
|
|
|
if(!($hits = $index->find('document_id:'.$document->getId()))) {
|
2015-05-02 06:04:41 +00:00
|
|
|
|
$index->addDocument(new SeedDMS_Lucene_IndexedDocument($dms, $document, isset($settings->_converters['fulltext']) ? $settings->_converters['fulltext'] : null));
|
2011-07-21 07:11:39 +00:00
|
|
|
|
} else {
|
|
|
|
|
$hit = $hits[0];
|
|
|
|
|
$created = (int) $hit->getDocument()->getFieldValue('created');
|
|
|
|
|
if($created >= $document->getDate()) {
|
|
|
|
|
echo $indent." Document unchanged\n";
|
|
|
|
|
} else {
|
|
|
|
|
if($index->delete($hit->id)) {
|
2015-05-02 06:04:41 +00:00
|
|
|
|
$index->addDocument(new SeedDMS_Lucene_IndexedDocument($dms, $document, $settings->_converters['fulltext'] ? $settings->_converters['fulltext'] : null));
|
2011-07-21 07:11:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2013-06-06 12:41:55 +00:00
|
|
|
|
if(!$dms->checkVersion()) {
|
|
|
|
|
echo "Database update needed.";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-21 07:11:39 +00:00
|
|
|
|
$dms->setRootFolderID($settings->_rootFolderID);
|
|
|
|
|
|
|
|
|
|
$index = Zend_Search_Lucene::create($settings->_luceneDir);
|
2013-06-11 11:42:41 +00:00
|
|
|
|
SeedDMS_Lucene_Indexer::init($settings->_stopWordsFile);
|
2011-07-21 07:11:39 +00:00
|
|
|
|
|
|
|
|
|
$folder = $dms->getFolder($settings->_rootFolderID);
|
|
|
|
|
tree($folder);
|
|
|
|
|
|
|
|
|
|
$index->commit();
|
|
|
|
|
?>
|