use controller RemoveDocument, send mail with notification class

This commit is contained in:
Uwe Steinmann 2021-05-19 08:33:15 +02:00
parent 0852d10df4
commit ba381d8e85

View File

@ -67,37 +67,33 @@ $folder = $document->getFolder();
/* Check if there is just one version. In that case remove the document */
if (count($document->getContent())==1) {
$previewer->deleteDocumentPreviews($document);
$nl = $document->getNotifyList();
$docname = $document->getName();
if (!$document->remove()) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured"));
} else {
$nexturl = "../out/out.ViewFolder.php?folderid=".$folder->getId();
/* Remove the document from the fulltext index */
if($fulltextservice && ($index = $fulltextservice->Index())) {
$lucenesearch = $fulltextservice->Search();
if($hit = $lucenesearch->getDocument($documentid)) {
$index->delete($hit->id);
$index->commit();
}
}
if ($notifier){
$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;
$params['url'] = getBaseUrl().$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID();
$notifier->toList($user, $nl["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
foreach ($nl["groups"] as $grp) {
$notifier->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION);
}
}
/* Get the notify list before removing the document
* Also inform the users/groups of the parent folder
* Getting the list now will keep them in the document object
* even after the document has been deleted.
*/
$dnl = $document->getNotifyList();
$fnl = $folder->getNotifyList();
$docname = $document->getName();
$controller->setParam('document', $document);
$controller->setParam('fulltextservice', $fulltextservice);
if(!$controller->run()) {
if ($controller->getErrorMsg() != '')
$errormsg = $controller->getErrorMsg();
else
$errormsg = "error_remove_document";
UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($docname))),getMLText($errormsg));
}
if ($notifier){
/* $document still has the data from the just deleted document,
* which is just enough to send the email.
*/
$notifier->sendDeleteDocumentMail($document, $user);
}
$nexturl = "../out/out.ViewFolder.php?folderid=".$folder->getId();
}
else {
/* Before deleting the content get a list of all users that should
@ -129,7 +125,7 @@ else {
$previewer->deletePreview($version, $settings->_previewWidthDetail);
$previewer->deletePreview($version, $settings->_previewWidthList);
/* Check if the version to be delete is the latest version. This is
/* Check if the version to be deleted is the latest version. This is
* later used to set the redirect url.
*/
$islatest = $version->getVersion() == $document->getLatestContent()->getVersion();