move most of functionality into controller

This commit is contained in:
Uwe Steinmann 2013-09-20 13:44:47 +02:00
parent 21aeeb2caf
commit 25a38e27a3
2 changed files with 91 additions and 74 deletions

View 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;
}
}

View File

@ -23,7 +23,12 @@ include("../inc/inc.ClassEmail.php");
include("../inc/inc.DBInit.php");
include("../inc/inc.Language.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.ClassController.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 */
if(!checkFormKey('removedocument')) {
@ -44,36 +49,6 @@ if ($document->getAccessMode($user) < M_ALL) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("access_denied"));
}
$folder = $document->getFolder();
/* Get the notify list before removing the document */
$nl = $document->getNotifyList();
$docname = $document->getName();
$hookObjectsArr = array();
if (is_array($GLOBALS['SEEDDMS_HOOKS']['RemoveDocument'])) {
foreach($GLOBALS['SEEDDMS_HOOKS']['RemoveDocument'] as $_classRef) {
$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"));
} else {
foreach($hookObjectsArr as $_hookObj) {
if (method_exists($_hookObj, 'postRemoveDocument')) {
$_hookObj->postRemoveDocument($dms, $documentid);
}
}
/* Remove the document from the fulltext index */
if($settings->_enableFullSearch) {
if(!empty($settings->_luceneClassDir))
require_once($settings->_luceneClassDir.'/Lucene.php');
@ -81,37 +56,22 @@ if (!$document->remove()) {
require_once('SeedDMS/Lucene.php');
$index = SeedDMS_Lucene_Indexer::open($settings->_luceneDir);
if($index && $hits = $index->find('document_id:'.$documentid)) {
$hit = $hits[0];
$index->delete($hit->id);
$index->commit();
} else {
$index = null;
}
/* save this for notification later on */
$nl = $document->getNotifyList();
$folder = $document->getFolder();
$docname = $document->getName();
$controller->setParam('document', $document);
$controller->setParam('index', $index);
if(!$controller->run()) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("error_occured"));
}
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();
@ -125,7 +85,6 @@ if (!$document->remove()) {
$notifier->toGroup($user, $grp, $subject, $message, $params);
}
}
}
add_log_line("?documentid=".$documentid);