seeddms-code/controllers/class.RemoveFolder.php

99 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2014-01-10 07:22:25 +00:00
<?php
/**
* Implementation of RemoveFolder controller
*
* @category DMS
* @package SeedDMS
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
* @version Release: @package_version@
*/
/**
* Class which does the busines logic for downloading a document
*
* @category DMS
* @package SeedDMS
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_Controller_RemoveFolder extends SeedDMS_Controller_Common {
2022-07-08 11:16:40 +00:00
/* Register a callback which removes each document/folder from the fulltext index
* The callback must return null otherwise the removal will be canceled.
*/
2022-07-08 11:16:40 +00:00
static function removeFromIndex($arr, $object) { /* {{{ */
$fulltextservice = $arr[0];
$lucenesearch = $fulltextservice->Search();
$hit = null;
2022-07-08 11:16:40 +00:00
if($object->isType('document'))
$hit = $lucenesearch->getDocument($object->getID());
elseif($object->isType('folder'))
$hit = $lucenesearch->getFolder($object->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() { /* {{{ */
2014-01-10 07:22:25 +00:00
$dms = $this->params['dms'];
$user = $this->params['user'];
$settings = $this->params['settings'];
$folder = $this->params['folder'];
$fulltextservice = $this->params['fulltextservice'];
2014-01-10 07:22:25 +00:00
2022-07-08 11:16:40 +00:00
/* Get the folder id and name before removing the folder */
2014-01-10 07:22:25 +00:00
$foldername = $folder->getName();
$folderid = $folder->getID();
if(false === $this->callHook('preRemoveFolder')) {
if(empty($this->errormsg))
$this->errormsg = 'hook_preRemoveFolder_failed';
return false;
2014-01-10 07:22:25 +00:00
}
$result = $this->callHook('removeFolder', $folder);
if($result === null) {
2020-12-14 06:08:14 +00:00
if($fulltextservice && ($index = $fulltextservice->Indexer())) {
/* 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));
2020-12-14 06:08:14 +00:00
}
/* Register another callback which removes the preview images of the document */
$previewer = new SeedDMS_Preview_Previewer($settings->_cacheDir);
$dms->addCallback('onPreRemoveDocument', 'SeedDMS_Controller_RemoveFolder::removePreviews', array($previewer));
2014-01-10 07:22:25 +00:00
if (!$folder->remove()) {
2018-03-22 14:12:24 +00:00
$this->errormsg = 'error_occured';
2014-01-10 07:22:25 +00:00
return false;
}
2019-01-17 17:25:01 +00:00
} elseif($result === false) {
if(empty($this->errormsg))
$this->errormsg = 'hook_removeFolder_failed';
return false;
}
if(false === $this->callHook('postRemoveFolder')) {
2019-01-17 17:25:01 +00:00
}
2014-01-10 07:22:25 +00:00
return true;
} /* }}} */
2014-01-10 07:22:25 +00:00
}