From e0b421dcca4a56410e31f93862ae4061a1a46196 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 2 Apr 2024 20:33:34 +0200 Subject: [PATCH] convert checkin into controller --- controllers/class.CheckInDocument.php | 114 ++++++++++++ op/op.CheckInDocument.php | 242 ++++++++------------------ op/op.UpdateDocument.php | 2 +- 3 files changed, 191 insertions(+), 167 deletions(-) create mode 100644 controllers/class.CheckInDocument.php diff --git a/controllers/class.CheckInDocument.php b/controllers/class.CheckInDocument.php new file mode 100644 index 000000000..969d18d17 --- /dev/null +++ b/controllers/class.CheckInDocument.php @@ -0,0 +1,114 @@ + + * @copyright Copyright (C) 2010-2024 Uwe Steinmann + * @version Release: @package_version@ + */ + +/** + * Class which does the busines logic for downloading a document + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2010-2024 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_Controller_CheckInDocument extends SeedDMS_Controller_Common { + + public function run() { /* {{{ */ + $name = $this->getParam('name'); + $comment = $this->getParam('comment'); + + /* Call preCheckInDocument early, because it might need to modify some + * of the parameters. + */ + if(false === $this->callHook('preCheckInDocument', $this->params['document'])) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_preCheckInDocument_failed'; + return null; + } + + $comment = $this->getParam('comment'); + $dms = $this->params['dms']; + $user = $this->params['user']; + $document = $this->params['document']; + $settings = $this->params['settings']; + $fulltextservice = $this->params['fulltextservice']; + $folder = $this->params['folder']; + $userfiletmp = $this->getParam('userfiletmp'); + $userfilename = $this->getParam('userfilename'); + $filetype = $this->getParam('filetype'); + $userfiletype = $this->getParam('userfiletype'); + $reviewers = $this->getParam('reviewers'); + $approvers = $this->getParam('approvers'); + $recipients = $this->getParam('recipients'); + $reqversion = $this->getParam('reqversion'); + $comment = $this->getParam('comment'); + $attributes = $this->getParam('attributes'); + $workflow = $this->getParam('workflow'); + $maxsizeforfulltext = $this->getParam('maxsizeforfulltext'); + $initialdocumentstatus = $this->getParam('initialdocumentstatus'); + + $content = $this->callHook('checkinDocument'); + if($content === null) { + if($contentResult=$document->checkIn($comment, $user, $reviewers, $approvers, $version=0, $attributes, $workflow, $initialdocumentstatus)) { + + if ($this->hasParam('expires')) { + if($document->setExpires($this->getParam('expires'))) { + } else { + } + } + + if(!empty($recipients['i'])) { + foreach($recipients['i'] as $uid) { + if($u = $dms->getUser($uid)) { + $res = $contentResult->getContent()->addIndRecipient($u, $user); + } + } + } + if(!empty($recipients['g'])) { + foreach($recipients['g'] as $gid) { + if($g = $dms->getGroup($gid)) { + $res = $contentResult->getContent()->addGrpRecipient($g, $user); + } + } + } + + $content = $contentResult->getContent(); + } else { + $this->errormsg = 'error_checkin_document'; + $result = false; + } + } elseif($result === false) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_checkinDocument_failed'; + return false; + } + + if($fulltextservice && ($index = $fulltextservice->Indexer()) && $content) { + $idoc = $fulltextservice->IndexedDocument($document); + if(false !== $this->callHook('preIndexDocument', $document, $idoc)) { + $lucenesearch = $fulltextservice->Search(); + if($hit = $lucenesearch->getDocument((int) $document->getId())) { + $index->delete($hit->id); + } + $index->addDocument($idoc); + $index->commit(); + } + } + + if(false === $this->callHook('postCheckInDocument', $document, $content)) { + } + + return $content; + } /* }}} */ +} + + diff --git a/op/op.CheckInDocument.php b/op/op.CheckInDocument.php index 72f9ce03f..e540e73ab 100644 --- a/op/op.CheckInDocument.php +++ b/op/op.CheckInDocument.php @@ -23,10 +23,23 @@ include("../inc/inc.Language.php"); include("../inc/inc.Init.php"); include("../inc/inc.Extension.php"); include("../inc/inc.DBInit.php"); -include("../inc/inc.ClassUI.php"); include("../inc/inc.Authentication.php"); +include("../inc/inc.ClassUI.php"); +include("../inc/inc.ClassController.php"); +$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME'])); +$controller = Controller::factory($tmp[1], array('dms'=>$dms, 'user'=>$user)); $accessop = new SeedDMS_AccessOperation($dms, $user, $settings); +if (!$accessop->check_controller_access($controller, $_POST)) { + UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("access_denied")); +} + +/* if post_max_size is to small, then $_POST will not be set and the content + * lenght will exceed post_max_size + */ +if(empty($_POST) && $_SERVER['CONTENT_LENGTH'] > SeedDMS_Core_File::parse_filesize(ini_get('post_max_size'))) { + UI::exitError(getMLText("folder_title", array("foldername" => '')),getMLText("uploading_postmaxsize")); +} /* Check if the form data comes from a trusted request */ if(!checkFormKey('checkindocument')) { @@ -45,7 +58,7 @@ if (!is_object($document)) { UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id")); } -if ($document->getAccessMode($user) < M_READWRITE) { +if ($document->getAccessMode($user, 'checkinDocument') < M_READWRITE) { UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("access_denied")); } @@ -73,6 +86,34 @@ if(isset($_POST["comment"])) else $comment = ""; +$oldexpires = $document->getExpires(); +switch($_POST["presetexpdate"]) { +case "date": + $expires = makeTsFromDate($_POST["expdate"]); +// $tmp = explode('-', $_POST["expdate"]); +// $expires = mktime(0,0,0, $tmp[1], $tmp[2], $tmp[0]); + break; +case "1w": + $tmp = explode('-', date('Y-m-d')); + $expires = mktime(0,0,0, $tmp[1], $tmp[2]+7, $tmp[0]); + break; +case "1m": + $tmp = explode('-', date('Y-m-d')); + $expires = mktime(0,0,0, $tmp[1]+1, $tmp[2], $tmp[0]); + break; +case "1y": + $tmp = explode('-', date('Y-m-d')); + $expires = mktime(0,0,0, $tmp[1], $tmp[2], $tmp[0]+1); + break; +case "2y": + $tmp = explode('-', date('Y-m-d')); + $expires = mktime(0,0,0, $tmp[1], $tmp[2], $tmp[0]+2); + break; +case "never": +default: + $expires = null; + break; +} // Get the list of reviewers and approvers for this document. $reviewers = array(); @@ -196,7 +237,7 @@ else if($group = $dms->getGroup($grp)) { $members = $group->getUsers(); foreach($members as $member) { - /* Do not add the uploader itself and reviewers */ + /* Do not add the uploader itself as recipient */ if(!$settings->_enableFilterReceipt || ($member->getID() != $user->getID() && !in_array($member->getID(), $reviewers['i']))) if(!in_array($member->getID(), $recipients["i"])) $recipients["i"][] = $member->getID(); @@ -227,175 +268,44 @@ else $attributes = array(); } - $contentResult=$document->checkIn($comment, $user, $reviewers, $approvers, $version=0, $attributes, $workflow, $settings->_initialDocumentStatus); - if (is_bool($contentResult) && !$contentResult) { - UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured")); - } elseif (is_bool($contentResult) && $contentResult) { - UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_no_checkin")); - $session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('splash_error_checkin_ended'))); + $controller->setParam('documentsource', 'checkin'); + $controller->setParam('folder', $folder); + $controller->setParam('document', $document); + $controller->setParam('fulltextservice', $fulltextservice); + $controller->setParam('comment', $comment); + if($oldexpires != $expires) + $controller->setParam('expires', $expires); + $controller->setParam('reviewers', $reviewers); + $controller->setParam('approvers', $approvers); + $controller->setParam('recipients', $recipients); + $controller->setParam('attributes', $attributes); + $controller->setParam('workflow', $workflow); + $controller->setParam('initialdocumentstatus', $settings->_initialDocumentStatus); + $controller->setParam('maxsizeforfulltext', $settings->_maxSizeForFullText); + + if(!$content = $controller()) { + $err = $controller->getErrorMsg(); + if(is_string($err)) + $errmsg = getMLText($err); + elseif(is_array($err)) { + $errmsg = getMLText($err[0], $err[1]); + } else { + $errmsg = $err; + } + UI::exitError(getMLText("document_title", array("documentname" => $document->getName())), $errmsg); } else { + if($controller->hasHook('cleanUpDocument')) { + $controller->callHook('cleanUpDocument', $document, $file); + } // Send notification to subscribers. - if ($notifier){ - $notifyList = $document->getNotifyList(); - $folder = $document->getFolder(); + if($notifier) { + $notifier->sendNewDocumentVersionMail($document, $user); - $subject = "document_updated_email_subject"; - $message = "document_updated_email_body"; - $params = array(); - $params['name'] = $document->getName(); - $params['folder_path'] = $folder->getFolderPathPlain(); - $params['username'] = $user->getFullName(); - $params['comment'] = $document->getComment(); - $params['version_comment'] = $contentResult->getContent()->getComment(); - $params['url'] = getBaseUrl().$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID(); - $params['sitename'] = $settings->_siteName; - $params['http_root'] = $settings->_httpRoot; - $notifier->toList($user, $notifyList["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION); - foreach ($notifyList["groups"] as $grp) { - $notifier->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION); - } - - if($workflow && $settings->_enableNotificationWorkflow) { - $subject = "request_workflow_action_email_subject"; - $message = "request_workflow_action_email_body"; - $params = array(); - $params['name'] = $document->getName(); - $params['version'] = $contentResult->getContent()->getVersion(); - $params['workflow'] = $workflow->getName(); - $params['folder_path'] = $folder->getFolderPathPlain(); - $params['current_state'] = $workflow->getInitState()->getName(); - $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(); - - foreach($workflow->getNextTransitions($workflow->getInitState()) as $ntransition) { - foreach($ntransition->getUsers() as $tuser) { - $notifier->toIndividual($user, $tuser->getUser(), $subject, $message, $params, SeedDMS_NotificationService::RECV_WORKFLOW); - } - foreach($ntransition->getGroups() as $tuser) { - $notifier->toGroup($user, $tuser->getGroup(), $subject, $message, $params, SeedDMS_NotificationService::RECV_WORKFLOW); - } - } - } - - if($settings->_enableNotificationAppRev) { - /* Reviewers and approvers will be informed about the new document */ - if($reviewers['i'] || $reviewers['g']) { - $subject = "review_request_email_subject"; - $message = "review_request_email_body"; - $params = array(); - $params['name'] = $document->getName(); - $params['folder_path'] = $folder->getFolderPathPlain(); - $params['version'] = $contentResult->getContent()->getVersion(); - $params['comment'] = $comment; - $params['username'] = $user->getFullName(); - $params['url'] = getBaseUrl().$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID(); - $params['sitename'] = $settings->_siteName; - $params['http_root'] = $settings->_httpRoot; - - foreach($reviewers['i'] as $reviewerid) { - $notifier->toIndividual($user, $dms->getUser($reviewerid), $subject, $message, $params, SeedDMS_NotificationService::RECV_REVIEWER); - } - foreach($reviewers['g'] as $reviewergrpid) { - $notifier->toGroup($user, $dms->getGroup($reviewergrpid), $subject, $message, $params, SeedDMS_NotificationService::RECV_REVIEWER); - } - } - - elseif($approvers['i'] || $approvers['g']) { - $subject = "approval_request_email_subject"; - $message = "approval_request_email_body"; - $params = array(); - $params['name'] = $document->getName(); - $params['folder_path'] = $folder->getFolderPathPlain(); - $params['version'] = $contentResult->getContent()->getVersion(); - $params['comment'] = $comment; - $params['username'] = $user->getFullName(); - $params['url'] = getBaseUrl().$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID(); - $params['sitename'] = $settings->_siteName; - $params['http_root'] = $settings->_httpRoot; - - foreach($approvers['i'] as $approverid) { - $notifier->toIndividual($user, $dms->getUser($approverid), $subject, $message, $params, SeedDMS_NotificationService::RECV_APPROVER); - } - foreach($approvers['g'] as $approvergrpid) { - $notifier->toGroup($user, $dms->getGroup($approvergrpid), $subject, $message, $params, SeedDMS_NotificationService::RECV_APPROVER); - } - } - } + $notifier->sendChangedExpiryMail($document, $user, $oldexpires); } - if($recipients['i']) { - foreach($recipients['i'] as $uid) { - if($u = $dms->getUser($uid)) { - $res = $contentResult->getContent()->addIndRecipient($u, $user); - } - } - } - if($recipients['g']) { - foreach($recipients['g'] as $gid) { - if($g = $dms->getGroup($gid)) { - $res = $contentResult->getContent()->addGrpRecipient($g, $user); - } - } - } - - $oldexpires = $document->getExpires(); - switch($_POST["presetexpdate"]) { - case "date": - $tmp = explode('-', $_POST["expdate"]); - $expires = mktime(0,0,0, $tmp[1], $tmp[2], $tmp[0]); - break; - case "1w": - $tmp = explode('-', date('Y-m-d')); - $expires = mktime(0,0,0, $tmp[1], $tmp[2]+7, $tmp[0]); - break; - case "1m": - $tmp = explode('-', date('Y-m-d')); - $expires = mktime(0,0,0, $tmp[1]+1, $tmp[2], $tmp[0]); - break; - case "1y": - $tmp = explode('-', date('Y-m-d')); - $expires = mktime(0,0,0, $tmp[1], $tmp[2], $tmp[0]+1); - break; - case "2y": - $tmp = explode('-', date('Y-m-d')); - $expires = mktime(0,0,0, $tmp[1], $tmp[2], $tmp[0]+2); - break; - case "never": - default: - $expires = null; - break; - } - - if($oldexpires != $expires) { - if($document->setExpires($expires)) { - if($notifier) { - $notifyList = $document->getNotifyList(); - $folder = $document->getFolder(); - - // Send notification to subscribers. - $subject = "expiry_changed_email_subject"; - $message = "expiry_changed_email_body"; - $params = array(); - $params['name'] = $document->getName(); - $params['folder_path'] = $folder->getFolderPathPlain(); - $params['username'] = $user->getFullName(); - $params['url'] = getBaseUrl().$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$document->getID(); - $params['sitename'] = $settings->_siteName; - $params['http_root'] = $settings->_httpRoot; - $notifier->toList($user, $notifyList["users"], $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION); - foreach ($notifyList["groups"] as $grp) { - $notifier->toGroup($user, $grp, $subject, $message, $params, SeedDMS_NotificationService::RECV_NOTIFICATION); - } - } - } else { - UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("error_occured")); - } - } - $session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_checked_in'))); } -add_log_line("?documentid=".$documentid); +add_log_line("checkin document ".$documentid." with version ".$content->getVersion()); header("Location:../out/out.ViewDocument.php?documentid=".$documentid); diff --git a/op/op.UpdateDocument.php b/op/op.UpdateDocument.php index b88e13b86..a1a798f38 100644 --- a/op/op.UpdateDocument.php +++ b/op/op.UpdateDocument.php @@ -333,7 +333,7 @@ default: if($group = $dms->getGroup($grp)) { $members = $group->getUsers(); foreach($members as $member) { - /* Do not add the uploader itself and approvers */ + /* Do not add the uploader itself as recipient */ if(!$settings->_enableFilterReceipt || ($member->getID() != $user->getID() && !in_array($member->getID(), $reviewers['i']))) if(!in_array($member->getID(), $recipients["i"])) $recipients["i"][] = $member->getID();