2012-12-14 07:53:13 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of Indexer view
|
|
|
|
*
|
|
|
|
* @category DMS
|
2013-02-14 11:10:53 +00:00
|
|
|
* @package SeedDMS
|
2012-12-14 07:53:13 +00:00
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
|
|
|
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
|
|
|
|
* 2010-2012 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Include parent class
|
|
|
|
*/
|
|
|
|
require_once("class.Bootstrap.php");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which outputs the html page for Indexer view
|
|
|
|
*
|
|
|
|
* @category DMS
|
2013-02-14 11:10:53 +00:00
|
|
|
* @package SeedDMS
|
2012-12-14 07:53:13 +00:00
|
|
|
* @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
|
|
|
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
|
|
|
|
* 2010-2012 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
2013-02-14 11:10:53 +00:00
|
|
|
class SeedDMS_View_Indexer extends SeedDMS_Bootstrap_Style {
|
2012-12-14 07:53:13 +00:00
|
|
|
|
2017-02-24 11:13:51 +00:00
|
|
|
function js() { /* {{{ */
|
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$user = $this->params['user'];
|
|
|
|
|
|
|
|
header('Content-Type: application/javascript');
|
|
|
|
?>
|
|
|
|
var queue_count = 0; // Number of functions being called
|
|
|
|
var funcArray = []; // Array of functions waiting
|
|
|
|
var MAX_REQUESTS = 5; // Max requests
|
|
|
|
var CALL_WAIT = 100; // 100ms
|
|
|
|
var docstoindex = 0; // total number of docs to index
|
|
|
|
|
|
|
|
function check_queue() {
|
|
|
|
// Check if count doesn't exceeds or if there aren't any functions to call
|
|
|
|
console.log('Queue has ' + funcArray.length + '/' + docstoindex + ' items');
|
|
|
|
console.log('Currently processing ' + queue_count + ' requests (' + $.active + ')');
|
|
|
|
if(queue_count >= MAX_REQUESTS) {
|
|
|
|
setTimeout(function() { check_queue() }, CALL_WAIT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(funcArray.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
docid = funcArray.pop();
|
|
|
|
$('#status_'+docid).html('Processsing ...');
|
|
|
|
$.ajax({url: '../op/op.Ajax.php',
|
|
|
|
type: 'GET',
|
|
|
|
dataType: "json",
|
|
|
|
data: {command: 'indexdocument', id: docid},
|
|
|
|
beforeSend: function() {
|
|
|
|
queue_count++; // Add request to the counter
|
2017-03-01 15:59:58 +00:00
|
|
|
$('.queue-bar').css('width', (queue_count*100/MAX_REQUESTS)+'%');
|
2017-02-24 11:13:51 +00:00
|
|
|
},
|
|
|
|
error: function(xhr, textstatus) {
|
|
|
|
noty({
|
|
|
|
text: textstatus,
|
|
|
|
type: 'error',
|
|
|
|
dismissQueue: true,
|
|
|
|
layout: 'topRight',
|
|
|
|
theme: 'defaultTheme',
|
2018-01-30 05:31:42 +00:00
|
|
|
timeout: 5000,
|
2017-02-24 11:13:51 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
// console.log('success ' + data.data);
|
|
|
|
if(data.success) {
|
2018-04-11 14:35:26 +00:00
|
|
|
if(data.cmd)
|
|
|
|
$('#status_'+data.data).html('<?php printMLText('index_done'); ?>');
|
|
|
|
else
|
|
|
|
$('#status_'+data.data).html('<?= getMLText('index_done').' ('.getMLText('index_no_content').')'; ?>');
|
2017-02-24 11:13:51 +00:00
|
|
|
} else {
|
2017-02-24 13:14:16 +00:00
|
|
|
$('#status_'+data.data).html('<?php printMLText('index_error'); ?>');
|
2017-02-24 11:13:51 +00:00
|
|
|
noty({
|
2018-04-11 13:31:35 +00:00
|
|
|
text: '<p><strong>Docid: ' + data.data + ' (' + data.mimetype + ')</strong></p>' + '<p>Cmd: ' + data.cmd + '</p>' + data.message,
|
2018-04-10 17:13:57 +00:00
|
|
|
type: 'error',
|
2017-02-24 11:13:51 +00:00
|
|
|
dismissQueue: true,
|
|
|
|
layout: 'topRight',
|
|
|
|
theme: 'defaultTheme',
|
2018-04-10 17:13:57 +00:00
|
|
|
timeout: 25000,
|
2017-02-24 11:13:51 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
complete: function(xhr, textstatus) {
|
2017-03-01 15:59:58 +00:00
|
|
|
queue_count--; // Substract request to the counter
|
2017-02-24 11:13:51 +00:00
|
|
|
$('.queue-bar').css('width', (queue_count*100/MAX_REQUESTS)+'%');
|
|
|
|
$('.total-bar').css('width', (100 - (funcArray.length+queue_count)*100/docstoindex)+'%');
|
|
|
|
$('.total-bar').text(Math.round(100 - (funcArray.length+queue_count)*100/docstoindex)+' %');
|
|
|
|
if(funcArray.length+queue_count == 0)
|
|
|
|
$('.total-bar').addClass('bar-success');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setTimeout(function() { check_queue() }, CALL_WAIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready( function() {
|
|
|
|
$('.tree-toggle').click(function () {
|
|
|
|
$(this).parent().children('ul.tree').toggle(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.indexme').each(function(index) {
|
|
|
|
var element = $(this);
|
|
|
|
var docid = element.data('docid');
|
2017-02-24 13:14:16 +00:00
|
|
|
element.html('<?php printMLText('index_pending'); ?>');
|
2017-02-24 11:13:51 +00:00
|
|
|
funcArray.push(docid);
|
|
|
|
});
|
|
|
|
docstoindex = funcArray.length;
|
|
|
|
check_queue(); // First call to start polling. It will call itself each 100ms
|
|
|
|
});
|
|
|
|
<?php
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
protected function tree($dms, $index, $indexconf, $folder, $indent='') { /* {{{ */
|
|
|
|
$forceupdate = $this->params['forceupdate'];
|
|
|
|
|
2014-05-22 04:50:33 +00:00
|
|
|
set_time_limit(30);
|
2017-02-24 11:13:51 +00:00
|
|
|
// echo $indent."D ".htmlspecialchars($folder->getName())."\n";
|
|
|
|
echo '<ul class="nav nav-list"><li><label class="tree-toggle nav-header">'.htmlspecialchars($folder->getName()).'</label>'."\n";
|
2012-12-14 07:53:13 +00:00
|
|
|
$subfolders = $folder->getSubFolders();
|
|
|
|
foreach($subfolders as $subfolder) {
|
2015-08-10 19:43:15 +00:00
|
|
|
$this->tree($dms, $index, $indexconf, $subfolder, $indent.' ');
|
2012-12-14 07:53:13 +00:00
|
|
|
}
|
|
|
|
$documents = $folder->getDocuments();
|
2017-02-24 11:13:51 +00:00
|
|
|
if($documents) {
|
|
|
|
echo '<ul class="nav nav-list">'."\n";
|
2012-12-14 07:53:13 +00:00
|
|
|
foreach($documents as $document) {
|
2017-02-24 11:13:51 +00:00
|
|
|
// echo $indent." ".$document->getId().":".htmlspecialchars($document->getName());
|
|
|
|
echo "<li class=\"document\">".$document->getId().":".htmlspecialchars($document->getName());
|
2012-12-14 07:53:13 +00:00
|
|
|
/* If the document wasn't indexed before then just add it */
|
2015-08-10 19:43:15 +00:00
|
|
|
$lucenesearch = new $indexconf['Search']($index);
|
|
|
|
if(!($hit = $lucenesearch->getDocument($document->getId()))) {
|
2017-02-24 13:14:16 +00:00
|
|
|
echo " <span id=\"status_".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting')."</span>";
|
2017-02-24 11:13:51 +00:00
|
|
|
/*
|
2015-08-05 19:11:21 +00:00
|
|
|
try {
|
2015-08-10 19:43:15 +00:00
|
|
|
$index->addDocument(new $indexconf['IndexedDocument']($dms, $document, $this->converters ? $this->converters : null, false, $this->timeout));
|
2015-08-05 19:11:21 +00:00
|
|
|
echo "(document added)";
|
|
|
|
} catch(Exception $e) {
|
|
|
|
echo $indent."(adding document failed '".$e->getMessage()."')";
|
|
|
|
}
|
2017-02-24 11:13:51 +00:00
|
|
|
*/
|
2012-12-14 07:53:13 +00:00
|
|
|
} else {
|
|
|
|
/* Check if the attribute created is set or has a value older
|
|
|
|
* than the lasted 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');
|
2015-08-10 19:43:15 +00:00
|
|
|
} catch (/* Zend_Search_Lucene_ */Exception $e) {
|
2012-12-14 07:53:13 +00:00
|
|
|
$created = 0;
|
|
|
|
}
|
|
|
|
$content = $document->getLatestContent();
|
2017-02-24 11:13:51 +00:00
|
|
|
if($created >= $content->getDate() && !$forceupdate) {
|
|
|
|
echo $indent."<span id=\"status_".$document->getID()."\" class=\"indexstatus\" data-docid=\"".$document->getID()."\">document unchanged</span>";
|
2012-12-14 07:53:13 +00:00
|
|
|
} else {
|
2013-06-27 13:11:14 +00:00
|
|
|
$index->delete($hit->id);
|
2017-02-24 13:14:16 +00:00
|
|
|
echo " <span id=\"status_".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"".$document->getID()."\">".getMLText('index_waiting')."</span>";
|
2017-02-24 11:13:51 +00:00
|
|
|
/*
|
2015-08-05 19:11:21 +00:00
|
|
|
try {
|
2015-08-10 19:43:15 +00:00
|
|
|
$index->addDocument(new $indexconf['IndexedDocument']($dms, $document, $this->converters ? $this->converters : null, false, $this->timeout));
|
2015-08-05 19:11:21 +00:00
|
|
|
echo $indent."(document updated)";
|
|
|
|
} catch(Exception $e) {
|
|
|
|
echo $indent."(updating document failed)";
|
|
|
|
}
|
2017-02-24 11:13:51 +00:00
|
|
|
*/
|
2012-12-14 07:53:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-24 11:13:51 +00:00
|
|
|
echo "</li>";
|
2012-12-14 07:53:13 +00:00
|
|
|
echo "\n";
|
|
|
|
}
|
2017-02-24 11:13:51 +00:00
|
|
|
echo "</ul>\n";
|
|
|
|
}
|
|
|
|
echo "</li></ul>\n";
|
2012-12-14 07:53:13 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
function show() { /* {{{ */
|
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$user = $this->params['user'];
|
|
|
|
$index = $this->params['index'];
|
2015-08-10 19:43:15 +00:00
|
|
|
$indexconf = $this->params['indexconf'];
|
2017-02-24 11:13:51 +00:00
|
|
|
$forceupdate = $this->params['forceupdate'];
|
2012-12-14 07:53:13 +00:00
|
|
|
$folder = $this->params['folder'];
|
2013-03-28 09:17:01 +00:00
|
|
|
$this->converters = $this->params['converters'];
|
2015-08-05 19:11:21 +00:00
|
|
|
$this->timeout = $this->params['timeout'];
|
2012-12-14 07:53:13 +00:00
|
|
|
|
|
|
|
$this->htmlStartPage(getMLText("admin_tools"));
|
|
|
|
$this->globalNavigation();
|
|
|
|
$this->contentStart();
|
|
|
|
$this->pageNavigation(getMLText("admin_tools"), "admin_tools");
|
|
|
|
$this->contentHeading(getMLText("update_fulltext_index"));
|
2017-02-24 11:13:51 +00:00
|
|
|
?>
|
|
|
|
<style type="text/css">
|
|
|
|
li {line-height: 20px;}
|
|
|
|
.nav-header {line-height: 19px; margin-bottom: 0px;}
|
|
|
|
.nav-list {padding-right: 0px;}
|
|
|
|
.nav-list>li.document:hover {background-color: #eee;}
|
|
|
|
.indexstatus {font-weight: bold; float: right;}
|
|
|
|
.progress {margin-bottom: 2px;}
|
|
|
|
.bar-legend {text-align: right; font-size: 85%; margin-bottom: 15px;}
|
|
|
|
</style>
|
|
|
|
<div style="max-width: 900px;">
|
|
|
|
<div>
|
|
|
|
<div class="progress">
|
|
|
|
<div class="bar total-bar" role="progressbar" style="width: 100%;"></div>
|
|
|
|
</div>
|
2017-02-24 13:14:16 +00:00
|
|
|
<div class="bar-legend"><?php printMLText('overall_indexing_progress'); ?></div>
|
2017-02-24 11:13:51 +00:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div class="progress">
|
|
|
|
<div class="bar queue-bar" role="progressbar" style="width: 100%;"></div>
|
|
|
|
</div>
|
2017-02-24 13:14:16 +00:00
|
|
|
<div class="bar-legend"><?php printMLText('indexing_tasks_in_queue'); ?></div>
|
2017-02-24 11:13:51 +00:00
|
|
|
</div>
|
|
|
|
<?php
|
2015-08-10 19:43:15 +00:00
|
|
|
$this->tree($dms, $index, $indexconf, $folder);
|
2017-02-24 11:13:51 +00:00
|
|
|
echo "</div>";
|
2012-12-14 07:53:13 +00:00
|
|
|
|
|
|
|
$index->commit();
|
2013-06-27 13:11:14 +00:00
|
|
|
$index->optimize();
|
2012-12-14 07:53:13 +00:00
|
|
|
|
2016-03-15 07:30:53 +00:00
|
|
|
$this->contentEnd();
|
2012-12-14 07:53:13 +00:00
|
|
|
$this->htmlEndPage();
|
|
|
|
} /* }}} */
|
|
|
|
}
|
|
|
|
?>
|