seeddms-code/controllers/class.ReviseDocument.php

115 lines
3.2 KiB
PHP
Raw Normal View History

2015-06-01 12:01:56 +00:00
<?php
/**
* Implementation of ReviseDocument 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_ReviseDocument extends SeedDMS_Controller_Common {
public function run() {
$dms = $this->params['dms'];
$user = $this->params['user'];
$settings = $this->params['settings'];
$document = $this->params['document'];
$content = $this->params['content'];
$revisionstatus = $this->params['revisionstatus'];
$revisiontype = $this->params['revisiontype'];
$group = $this->params['group'];
$comment = $this->params['comment'];
/* Get the document id and name before removing the document */
$docname = $document->getName();
$documentid = $document->getID();
2015-06-01 15:34:52 +00:00
if(!$this->callHook('preReviseDocument', $content)) {
2015-06-01 12:01:56 +00:00
}
2015-06-01 15:34:52 +00:00
$result = $this->callHook('reviseDocument', $content);
2015-06-01 12:01:56 +00:00
if($result === null) {
if ($revisiontype == "ind") {
if(0 > $content->setRevision($user, $user, $revisionstatus, $comment)) {
$this->error = 1;
$this->errormsg = "revision_update_failed";
return false;
}
} elseif ($revisiontype == "grp") {
if(0 > $content->setRevision($group, $user, $revisionstatus, $comment)) {
$this->error = 1;
$this->errormsg = "revision_update_failed";
return false;
}
}
}
/* Check to see if the overall status for the document version needs to be
* updated.
*/
2015-06-01 15:34:52 +00:00
$result = $this->callHook('reviseUpdateDocumentStatus', $content);
2015-06-01 12:01:56 +00:00
if($result === null) {
if ($revisionstatus == -1){
if(!$content->setStatus(S_REJECTED,$comment,$user)) {
2015-06-01 12:01:56 +00:00
$this->error = 1;
$this->errormsg = "revision_update_failed";
return false;
}
} else {
$docRevisionStatus = $content->getRevisionStatus();
if (is_bool($docRevisionStatus) && !$docRevisionStatus) {
$this->error = 1;
$this->errormsg = "cannot_retrieve_revision_snapshot";
return false;
}
$revisionCT = 0;
$revisionTotal = 0;
foreach ($docRevisionStatus as $drstat) {
if ($drstat["status"] == 1) {
$revisionCT++;
}
if ($drstat["status"] != -2) {
$revisionTotal++;
}
}
// If all revisions have been received and there are no rejections,
// then release the document otherwise put it back into revision workflow
if ($revisionCT == $revisionTotal) {
$newStatus=S_RELEASED;
if ($content->finishRevision($user, $newStatus, '', getMLText("automatic_status_update"))) {
2017-01-24 13:20:10 +00:00
if(!$this->callHook('finishReviseDocument', $content)) {
}
2015-06-01 12:01:56 +00:00
}
} else {
$newStatus=S_IN_REVISION;
if(!$content->setStatus($newStatus,$comment,$user)) {
2015-06-01 12:01:56 +00:00
$this->error = 1;
$this->errormsg = "revision_update_failed";
return false;
}
}
}
}
2015-06-01 15:34:52 +00:00
if(!$this->callHook('postReviseDocument', $content)) {
2015-06-01 12:01:56 +00:00
}
return true;
}
}