mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-09 13:06:14 +00:00
move most of functionality into controller
This commit is contained in:
parent
21aeeb2caf
commit
25a38e27a3
58
controllers/class.RemoveDocument.php
Normal file
58
controllers/class.RemoveDocument.php
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Implementation of RemoveDocument 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_RemoveDocument extends SeedDMS_Controller_Common {
|
||||||
|
|
||||||
|
public function run() {
|
||||||
|
$dms = $this->params['dms'];
|
||||||
|
$user = $this->params['user'];
|
||||||
|
$settings = $this->params['settings'];
|
||||||
|
$document = $this->params['document'];
|
||||||
|
$index = $this->params['index'];
|
||||||
|
|
||||||
|
$folder = $document->getFolder();
|
||||||
|
|
||||||
|
/* Get the notify list before removing the document */
|
||||||
|
$docname = $document->getName();
|
||||||
|
$documentid = $document->getID();
|
||||||
|
|
||||||
|
if(!$this->callHook('preRemoveDocument')) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$document->remove()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if(!$this->callHook('postRemoveDocument')) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove the document from the fulltext index */
|
||||||
|
if($index && $hits = $index->find('document_id:'.$documentid)) {
|
||||||
|
$hit = $hits[0];
|
||||||
|
$index->delete($hit->id);
|
||||||
|
$index->commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,7 +23,12 @@ include("../inc/inc.ClassEmail.php");
|
||||||
include("../inc/inc.DBInit.php");
|
include("../inc/inc.DBInit.php");
|
||||||
include("../inc/inc.Language.php");
|
include("../inc/inc.Language.php");
|
||||||
include("../inc/inc.ClassUI.php");
|
include("../inc/inc.ClassUI.php");
|
||||||
|
include("../inc/inc.ClassController.php");
|
||||||
include("../inc/inc.Authentication.php");
|
include("../inc/inc.Authentication.php");
|
||||||
|
include("../inc/inc.Extension.php");
|
||||||
|
|
||||||
|
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
|
||||||
|
$controller = Controller::factory($tmp[1]);
|
||||||
|
|
||||||
/* Check if the form data comes for a trusted request */
|
/* Check if the form data comes for a trusted request */
|
||||||
if(!checkFormKey('removedocument')) {
|
if(!checkFormKey('removedocument')) {
|
||||||
|
@ -44,86 +49,40 @@ if ($document->getAccessMode($user) < M_ALL) {
|
||||||
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("access_denied"));
|
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("access_denied"));
|
||||||
}
|
}
|
||||||
|
|
||||||
$folder = $document->getFolder();
|
if($settings->_enableFullSearch) {
|
||||||
|
if(!empty($settings->_luceneClassDir))
|
||||||
|
require_once($settings->_luceneClassDir.'/Lucene.php');
|
||||||
|
else
|
||||||
|
require_once('SeedDMS/Lucene.php');
|
||||||
|
|
||||||
/* Get the notify list before removing the document */
|
$index = SeedDMS_Lucene_Indexer::open($settings->_luceneDir);
|
||||||
|
} else {
|
||||||
|
$index = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* save this for notification later on */
|
||||||
$nl = $document->getNotifyList();
|
$nl = $document->getNotifyList();
|
||||||
|
$folder = $document->getFolder();
|
||||||
$docname = $document->getName();
|
$docname = $document->getName();
|
||||||
|
|
||||||
$hookObjectsArr = array();
|
$controller->setParam('document', $document);
|
||||||
if (is_array($GLOBALS['SEEDDMS_HOOKS']['RemoveDocument'])) {
|
$controller->setParam('index', $index);
|
||||||
foreach($GLOBALS['SEEDDMS_HOOKS']['RemoveDocument'] as $_classRef) {
|
if(!$controller->run()) {
|
||||||
$hookObjectsArr[] = & new $_classRef;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($hookObjectsArr as $_hookObj) {
|
|
||||||
if (method_exists($_hookObj, 'preRemoveDocument')) {
|
|
||||||
$ret = $_hookObj->preRemoveDocument($dms, $document);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$document->remove()) {
|
|
||||||
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("error_occured"));
|
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("error_occured"));
|
||||||
} else {
|
}
|
||||||
|
|
||||||
foreach($hookObjectsArr as $_hookObj) {
|
if ($notifier){
|
||||||
if (method_exists($_hookObj, 'postRemoveDocument')) {
|
$subject = "document_deleted_email_subject";
|
||||||
$_hookObj->postRemoveDocument($dms, $documentid);
|
$message = "document_deleted_email_body";
|
||||||
}
|
$params = array();
|
||||||
}
|
$params['name'] = $docname;
|
||||||
|
$params['folder_path'] = $folder->getFolderPathPlain();
|
||||||
/* Remove the document from the fulltext index */
|
$params['username'] = $user->getFullName();
|
||||||
if($settings->_enableFullSearch) {
|
$params['sitename'] = $settings->_siteName;
|
||||||
if(!empty($settings->_luceneClassDir))
|
$params['http_root'] = $settings->_httpRoot;
|
||||||
require_once($settings->_luceneClassDir.'/Lucene.php');
|
$notifier->toList($user, $nl["users"], $subject, $message, $params);
|
||||||
else
|
foreach ($nl["groups"] as $grp) {
|
||||||
require_once('SeedDMS/Lucene.php');
|
$notifier->toGroup($user, $grp, $subject, $message, $params);
|
||||||
|
|
||||||
$index = SeedDMS_Lucene_Indexer::open($settings->_luceneDir);
|
|
||||||
if($index && $hits = $index->find('document_id:'.$documentid)) {
|
|
||||||
$hit = $hits[0];
|
|
||||||
$index->delete($hit->id);
|
|
||||||
$index->commit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($notifier){
|
|
||||||
/*
|
|
||||||
$path = "";
|
|
||||||
$folderPath = $folder->getPath();
|
|
||||||
for ($i = 0; $i < count($folderPath); $i++) {
|
|
||||||
$path .= $folderPath[$i]->getName();
|
|
||||||
if ($i +1 < count($folderPath))
|
|
||||||
$path .= " / ";
|
|
||||||
}
|
|
||||||
|
|
||||||
$subject = "###SITENAME###: ".$document->getName()." - ".getMLText("document_deleted_email");
|
|
||||||
$message = getMLText("document_deleted_email")."\r\n";
|
|
||||||
$message .=
|
|
||||||
getMLText("document").": ".$document->getName()."\r\n".
|
|
||||||
getMLText("folder").": ".$path."\r\n".
|
|
||||||
getMLText("comment").": ".$document->getComment()."\r\n".
|
|
||||||
getMLText("user").": ".$user->getFullName()." <". $user->getEmail() ."> ";
|
|
||||||
|
|
||||||
// Send notification to subscribers.
|
|
||||||
$notifier->toList($user, $nl["users"], $subject, $message);
|
|
||||||
foreach ($nl["groups"] as $grp) {
|
|
||||||
$notifier->toGroup($user, $grp, $subject, $message);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
$subject = "document_deleted_email_subject";
|
|
||||||
$message = "document_deleted_email_body";
|
|
||||||
$params = array();
|
|
||||||
$params['name'] = $docname;
|
|
||||||
$params['folder_path'] = $folder->getFolderPathPlain();
|
|
||||||
$params['username'] = $user->getFullName();
|
|
||||||
$params['sitename'] = $settings->_siteName;
|
|
||||||
$params['http_root'] = $settings->_httpRoot;
|
|
||||||
$notifier->toList($user, $nl["users"], $subject, $message, $params);
|
|
||||||
foreach ($nl["groups"] as $grp) {
|
|
||||||
$notifier->toGroup($user, $grp, $subject, $message, $params);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user