Merge branch 'seeddms-5.1.x' into seeddms-6.0.x

This commit is contained in:
Uwe Steinmann 2021-06-24 11:41:23 +02:00
commit 3827cdda27
4 changed files with 20 additions and 17 deletions

View File

@ -165,7 +165,7 @@ class SeedDMS_SQLiteFTS_Indexer {
* @param string $query * @param string $query
* @param array $limit array with elements 'limit' and 'offset' * @param array $limit array with elements 'limit' and 'offset'
* @return boolean false in case of an error, otherwise array with elements * @return boolean false in case of an error, otherwise array with elements
* 'count', 'hits', 'facets' * 'count', 'hits', 'facets'. 'hits' is an array of SeedDMS_SQLiteFTS_QueryHit
*/ */
public function find($query, $limit=array()) { /* {{{ */ public function find($query, $limit=array()) { /* {{{ */
if(!$this->_conn) if(!$this->_conn)
@ -206,20 +206,21 @@ class SeedDMS_SQLiteFTS_Indexer {
/** /**
* Get a single document from index * Get a single document from index
* *
* @param integer $id id of document * @param string $id id of document
* @return boolean false in case of an error, otherwise true * @return boolean false in case of an error, otherwise true
*/ */
public function findById($id) { /* {{{ */ public function findById($id) { /* {{{ */
if(!$this->_conn) if(!$this->_conn)
return false; return false;
$sql = "SELECT ".$this->_rawid." FROM docs WHERE ".$this->_rawid."=".(int) $id; $sql = "SELECT ".$this->_rawid.", documentid FROM docs WHERE documentid=".$this->_conn->quote($id);
$res = $this->_conn->query($sql); $res = $this->_conn->query($sql);
$hits = array(); $hits = array();
if($res) { if($res) {
while($rec = $res->fetch(PDO::FETCH_ASSOC)) { while($rec = $res->fetch(PDO::FETCH_ASSOC)) {
$hit = new SeedDMS_SQLiteFTS_QueryHit($this); $hit = new SeedDMS_SQLiteFTS_QueryHit($this);
$hit->id = $rec[$this->_rawid]; $hit->id = $rec[$this->_rawid];
$hit->documentid = $rec['documentid'];
$hits[] = $hit; $hits[] = $hit;
} }
} }
@ -232,11 +233,11 @@ class SeedDMS_SQLiteFTS_Indexer {
* @param integer $id id of index record * @param integer $id id of index record
* @return boolean false in case of an error, otherwise true * @return boolean false in case of an error, otherwise true
*/ */
public function getDocument($id) { /* {{{ */ public function getDocument($id, $content=true) { /* {{{ */
if(!$this->_conn) if(!$this->_conn)
return false; return false;
$sql = "SELECT ".$this->_rawid.", documentid, title, comment, owner, keywords, category, mimetype, origfilename, created, users, status, path FROM docs WHERE documentid='D".$id."'"; $sql = "SELECT ".$this->_rawid.", documentid, title, comment, owner, keywords, category, mimetype, origfilename, created, users, status, path".($content ? ", content" : "")." FROM docs WHERE ".$this->_rawid."='".$id."'";
$res = $this->_conn->query($sql); $res = $this->_conn->query($sql);
$doc = false; $doc = false;
if($res) { if($res) {
@ -255,6 +256,8 @@ class SeedDMS_SQLiteFTS_Indexer {
$doc->addField('users', $rec['users']); $doc->addField('users', $rec['users']);
$doc->addField('status', $rec['status']); $doc->addField('status', $rec['status']);
$doc->addField('path', $rec['path']); $doc->addField('path', $rec['path']);
if($content)
$doc->addField('content', $rec['content']);
} }
return $doc; return $doc;
} /* }}} */ } /* }}} */
@ -265,7 +268,7 @@ class SeedDMS_SQLiteFTS_Indexer {
* @param integer $id id of folder * @param integer $id id of folder
* @return boolean false in case of an error, otherwise true * @return boolean false in case of an error, otherwise true
*/ */
public function getFolder($id) { /* {{{ */ public function __getFolder($id) { /* {{{ */
if(!$this->_conn) if(!$this->_conn)
return false; return false;

View File

@ -45,23 +45,23 @@ class SeedDMS_SQliteFTS_Search {
/** /**
* Get document from index * Get document from index
* *
* @param int $id real document id * @param int $id id of seeddms document
* @return object instance of SeedDMS_SQliteFTS_QueryHit or false * @return object instance of SeedDMS_SQliteFTS_QueryHit or false
*/ */
function getDocument($id) { /* {{{ */ function getDocument($id) { /* {{{ */
$hits = $this->index->find('D'.$id); $hits = $this->index->findById('D'.$id);
return $hits['hits'] ? $hits['hits'][0] : false; return $hits ? $hits[0] : false;
} /* }}} */ } /* }}} */
/** /**
* Get folder from index * Get folder from index
* *
* @param int $id real folder id * @param int $id id of seeddms folder
* @return object instance of SeedDMS_SQliteFTS_QueryHit or false * @return object instance of SeedDMS_SQliteFTS_QueryHit or false
*/ */
function getFolder($id) { /* {{{ */ function getFolder($id) { /* {{{ */
$hits = $this->index->find('F'.$id); $hits = $this->index->findById('F'.$id);
return $hits['hits'] ? $hits['hits'][0] : false; return $hits ? $hits[0] : false;
} /* }}} */ } /* }}} */
/** /**

View File

@ -1048,7 +1048,7 @@ class SeedDMS_FolderTree { /* {{{ */
$iter = new \SeedDMS\RecursiveFolderIterator($folder); $iter = new \SeedDMS\RecursiveFolderIterator($folder);
$iter2 = new RecursiveIteratorIterator($iter, RecursiveIteratorIterator::SELF_FIRST); $iter2 = new RecursiveIteratorIterator($iter, RecursiveIteratorIterator::SELF_FIRST);
foreach($iter2 as $ff) { foreach($iter2 as $ff) {
call_user_func($callback, $ff); call_user_func($callback, $ff, $iter2->getDepth());
// echo $ff->getID().': '.$ff->getFolderPathPlain().'-'.$ff->getName()."<br />"; // echo $ff->getID().': '.$ff->getFolderPathPlain().'-'.$ff->getName()."<br />";
} }
} /* }}} */ } /* }}} */

View File

@ -35,9 +35,9 @@ class SeedDMS_View_Indexer_Process_Folder { /* {{{ */
$this->numdocs = $this->fulltextservice->Indexer()->count(); $this->numdocs = $this->fulltextservice->Indexer()->count();
} /* }}} */ } /* }}} */
public function process($folder) { /* {{{ */ public function process($folder, $depth=0) { /* {{{ */
$lucenesearch = $this->fulltextservice->Search(); $lucenesearch = $this->fulltextservice->Search();
echo "<div class=\"folder\">".$folder->getId().":".htmlspecialchars($folder->getFolderPathPlain()); echo "<div class=\"folder\" style=\"margin-left: ".(($depth+1)*18)."px\"><i class=\"fa fa-folder\"></i> ".$folder->getId().":".htmlspecialchars($folder->getFolderPathPlain());
/* If the document wasn't indexed before then just add it */ /* If the document wasn't indexed before then just add it */
if(($this->numdocs == 0) || !($hit = $lucenesearch->getFolder($folder->getId()))) { if(($this->numdocs == 0) || !($hit = $lucenesearch->getFolder($folder->getId()))) {
echo " <span id=\"status_F".$folder->getID()."\" class=\"indexme indexstatus\" data-docid=\"F".$folder->getID()."\">".getMLText('index_waiting')."</span>"; echo " <span id=\"status_F".$folder->getID()."\" class=\"indexme indexstatus\" data-docid=\"F".$folder->getID()."\">".getMLText('index_waiting')."</span>";
@ -65,7 +65,7 @@ class SeedDMS_View_Indexer_Process_Folder { /* {{{ */
if($documents) { if($documents) {
// echo "<div class=\"folder\">".htmlspecialchars($folder->getFolderPathPlain())."</div>"; // echo "<div class=\"folder\">".htmlspecialchars($folder->getFolderPathPlain())."</div>";
foreach($documents as $document) { foreach($documents as $document) {
echo "<div class=\"document\">".$document->getId().":".htmlspecialchars($document->getName()); echo "<div class=\"document\" style=\"margin-left: ".(($depth+2)*18)."px\">".$document->getId().":".htmlspecialchars($document->getName());
/* If the document wasn't indexed before then just add it */ /* If the document wasn't indexed before then just add it */
if(($this->numdocs == 0) || !($hit = $lucenesearch->getDocument($document->getId()))) { if(($this->numdocs == 0) || !($hit = $lucenesearch->getDocument($document->getId()))) {
echo " <span id=\"status_D".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"D".$document->getID()."\">".getMLText('index_waiting')."</span>"; echo " <span id=\"status_D".$document->getID()."\" class=\"indexme indexstatus\" data-docid=\"D".$document->getID()."\">".getMLText('index_waiting')."</span>";
@ -245,8 +245,8 @@ div.folder {font-weight: bold; line-height: 20px; margin-top: 10px;}
</div> </div>
<?php <?php
$folderprocess = new SeedDMS_View_Indexer_Process_Folder($fulltextservice, $forceupdate); $folderprocess = new SeedDMS_View_Indexer_Process_Folder($fulltextservice, $forceupdate);
call_user_func(array($folderprocess, 'process'), $folder, -1);
$tree = new SeedDMS_FolderTree($folder, array($folderprocess, 'process')); $tree = new SeedDMS_FolderTree($folder, array($folderprocess, 'process'));
call_user_func(array($folderprocess, 'process'), $folder);
echo "</div>"; echo "</div>";
$index->commit(); $index->commit();