mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 15:32:13 +00:00
do not declare callback function in run(), uses static method instead
This commit is contained in:
parent
a3d2f844b0
commit
756b38a067
|
@ -22,7 +22,33 @@
|
|||
*/
|
||||
class SeedDMS_Controller_RemoveFolder extends SeedDMS_Controller_Common {
|
||||
|
||||
public function run() {
|
||||
/* Register a callback which removes each document from the fulltext index
|
||||
* The callback must return null otherwise the removal will be canceled.
|
||||
*/
|
||||
static function removeFromIndex($arr, $document) { /* {{{ */
|
||||
$fulltextservice = $arr[0];
|
||||
$lucenesearch = $fulltextservice->Search();
|
||||
$hit = null;
|
||||
if($document->isType('document'))
|
||||
$hit = $lucenesearch->getDocument($document->getID());
|
||||
elseif($document->isType('folder'))
|
||||
$hit = $lucenesearch->getFolder($document->getID());
|
||||
if($hit) {
|
||||
$index = $fulltextservice->Indexer();
|
||||
$index->delete($hit->id);
|
||||
$index->commit();
|
||||
}
|
||||
return null;
|
||||
} /* }}} */
|
||||
|
||||
static function removePreviews($arr, $document) { /* {{{ */
|
||||
$previewer = $arr[0];
|
||||
|
||||
$previewer->deleteDocumentPreviews($document);
|
||||
return null;
|
||||
} /* }}} */
|
||||
|
||||
public function run() { /* {{{ */
|
||||
$dms = $this->params['dms'];
|
||||
$user = $this->params['user'];
|
||||
$settings = $this->params['settings'];
|
||||
|
@ -41,38 +67,19 @@ class SeedDMS_Controller_RemoveFolder extends SeedDMS_Controller_Common {
|
|||
|
||||
$result = $this->callHook('removeFolder', $folder);
|
||||
if($result === null) {
|
||||
/* Register a callback which removes each document from the fulltext index
|
||||
* The callback must return null other the removal will be canceled.
|
||||
*/
|
||||
function removeFromIndex($arr, $document) {
|
||||
$fulltextservice = $arr[0];
|
||||
$lucenesearch = $fulltextservice->Search();
|
||||
$hit = null;
|
||||
if($document->isType('document'))
|
||||
$hit = $lucenesearch->getDocument($document->getID());
|
||||
elseif($document->isType('folder'))
|
||||
$hit = $lucenesearch->getFolder($document->getID());
|
||||
if($hit) {
|
||||
$index = $fulltextservice->Indexer();
|
||||
$index->delete($hit->id);
|
||||
$index->commit();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if($fulltextservice && ($index = $fulltextservice->Indexer())) {
|
||||
$dms->addCallback('onPreRemoveDocument', 'removeFromIndex', array($fulltextservice));
|
||||
$dms->addCallback('onPreRemoveFolder', 'removeFromIndex', array($fulltextservice));
|
||||
/* Register a callback which is called by SeedDMS_Core when a folder
|
||||
* or document is removed. The second parameter passed to this callback
|
||||
* is the document or folder to be removed.
|
||||
*/
|
||||
$dms->addCallback('onPreRemoveDocument', 'SeedDMS_Controller_RemoveFolder::removeFromIndex', array($fulltextservice));
|
||||
$dms->addCallback('onPreRemoveFolder', 'SeedDMS_Controller_RemoveFolder::removeFromIndex', array($fulltextservice));
|
||||
}
|
||||
|
||||
function removePreviews($arr, $document) {
|
||||
$previewer = $arr[0];
|
||||
|
||||
$previewer->deleteDocumentPreviews($document);
|
||||
return null;
|
||||
}
|
||||
/* Register another callback which removes the preview images of the document */
|
||||
require_once("SeedDMS/Preview.php");
|
||||
$previewer = new SeedDMS_Preview_Previewer($settings->_cacheDir);
|
||||
$dms->addCallback('onPreRemoveDocument', 'removePreviews', array($previewer));
|
||||
$dms->addCallback('onPreRemoveDocument', 'SeedDMS_Controller_RemoveFolder::removePreviews', array($previewer));
|
||||
|
||||
if (!$folder->remove()) {
|
||||
$this->errormsg = 'error_occured';
|
||||
|
@ -88,5 +95,5 @@ class SeedDMS_Controller_RemoveFolder extends SeedDMS_Controller_Common {
|
|||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} /* }}} */
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user