mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-11 09:35:00 +00:00
new function and controller for emptying a folder
This commit is contained in:
parent
d2614ba79d
commit
c9d9bf6c7b
|
@ -1038,6 +1038,12 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object {
|
|||
* Remove recursively a folder
|
||||
*
|
||||
* Removes a folder, all its subfolders and documents
|
||||
* This method triggers the callbacks onPreRemoveFolder and onPostRemoveFolder.
|
||||
* If onPreRemoveFolder returns a boolean then this method will return
|
||||
* imediately with the value returned by the callback. Otherwise the
|
||||
* regular removal is executed, which in turn
|
||||
* triggers further onPreRemoveFolder and onPostRemoveFolder callbacks
|
||||
* and its counterparts for documents (onPreRemoveDocument, onPostRemoveDocument).
|
||||
*
|
||||
* @return boolean true on success, false in case of an error
|
||||
*/
|
||||
|
@ -1093,6 +1099,62 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object {
|
|||
return $ret;
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Empty recursively a folder
|
||||
*
|
||||
* Removes all subfolders and documents of a folder but not the folder itself
|
||||
* This method will call remove() on all its children.
|
||||
* This method triggers the callbacks onPreEmptyFolder and onPostEmptyFolder.
|
||||
* If onPreEmptyFolder returns a boolean then this method will return
|
||||
* imediately.
|
||||
* Be aware that the recursive calls of remove() will trigger the callbacks
|
||||
* onPreRemoveFolder, onPostRemoveFolder, onPreRemoveDocument and onPostRemoveDocument.
|
||||
*
|
||||
* @return boolean true on success, false in case of an error
|
||||
*/
|
||||
function empty() { /* {{{ */
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
$db = $this->_dms->getDB();
|
||||
|
||||
/* Check if 'onPreEmptyFolder' callback is set */
|
||||
if(isset($this->_dms->callbacks['onPreEmptyFolder'])) {
|
||||
foreach($this->_dms->callbacks['onPreEmptyFolder'] as $callback) {
|
||||
$ret = call_user_func($callback[0], $callback[1], $this);
|
||||
if(is_bool($ret))
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
//Entfernen der Unterordner und Dateien
|
||||
$res = $this->getSubFolders();
|
||||
if (is_bool($res) && !$res) return false;
|
||||
$res = $this->getDocuments();
|
||||
if (is_bool($res) && !$res) return false;
|
||||
|
||||
foreach ($this->_subFolders as $subFolder) {
|
||||
$res = $subFolder->remove();
|
||||
if (!$res) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->_documents as $document) {
|
||||
$res = $document->remove();
|
||||
if (!$res) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if 'onPostEmptyFolder' callback is set */
|
||||
if(isset($this->_dms->callbacks['onPostEmptyFolder'])) {
|
||||
foreach($this->_dms->callbacks['onPostEmptyFolder'] as $callback) {
|
||||
call_user_func($callback[0], $callback[1], $this);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Returns a list of access privileges
|
||||
*
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
- add SeedDMS_Core_Folder::hasSubFolderByName()
|
||||
- fix SeedDMS_Core_Folder::hasDocumentByName() which returned an int > 0 if documents
|
||||
has been loaded before and even if the document searching for was not among them.
|
||||
- add new method SeedDMS_Core_Folder::empty()
|
||||
</notes>
|
||||
<contents>
|
||||
<dir baseinstalldir="SeedDMS" name="/">
|
||||
|
|
76
controllers/class.EmptyFolder.php
Normal file
76
controllers/class.EmptyFolder.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/**
|
||||
* Implementation of EmptyFolder 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_EmptyFolder extends SeedDMS_Controller_Common {
|
||||
|
||||
public function run() {
|
||||
$dms = $this->params['dms'];
|
||||
$user = $this->params['user'];
|
||||
$settings = $this->params['settings'];
|
||||
$folder = $this->params['folder'];
|
||||
$index = $this->params['index'];
|
||||
$indexconf = $this->params['indexconf'];
|
||||
|
||||
/* Get the document id and name before removing the document */
|
||||
$foldername = $folder->getName();
|
||||
$folderid = $folder->getID();
|
||||
|
||||
if(false === $this->callHook('preEmptyFolder')) {
|
||||
if(empty($this->errormsg))
|
||||
$this->errormsg = 'hook_preEmptyFolder_failed';
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = $this->callHook('emptyFolder', $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) {
|
||||
$index = $arr[0];
|
||||
$indexconf = $arr[1];
|
||||
$lucenesearch = new $indexconf['Search']($index);
|
||||
if($hit = $lucenesearch->getDocument($document->getID())) {
|
||||
$index->delete($hit->id);
|
||||
$index->commit();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if($index)
|
||||
$dms->setCallback('onPreEmptyDocument', 'removeFromIndex', array($index, $indexconf));
|
||||
|
||||
if (!$folder->empty()) {
|
||||
$this->errormsg = 'error_occured';
|
||||
return false;
|
||||
}
|
||||
} elseif($result === false) {
|
||||
if(empty($this->errormsg))
|
||||
$this->errormsg = 'hook_emptyFolder_failed';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$this->callHook('postEmptyFolder')) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user