Пример #1
0
 /**
  * Performs a workflow transition on a document, changing it from
  * one workflow state to another, with potential side effects (user
  * scripts, and so forth).
  *
  * This function currently assumes that the user in question is
  * allowed to perform the transition and that all the guard
  * functionality on the transition has passed.
  */
 function performTransitionOnDocument($oTransition, $oDocument, $oUser, $sComments)
 {
     $oWorkflow =& KTWorkflow::getByDocument($oDocument);
     if (empty($oWorkflow)) {
         return PEAR::raiseError(_kt("Document has no workflow"));
     }
     if (PEAR::isError($oWorkflow)) {
         return $oWorkflow;
     }
     $oSourceState =& KTWorkflowUtil::getWorkflowStateForDocument($oDocument);
     // walk the action triggers.
     $aActionTriggers = KTWorkflowUtil::getActionTriggersForTransition($oTransition);
     if (PEAR::isError($aActionTriggers)) {
         return $aActionTriggers;
         // error out?
     }
     foreach ($aActionTriggers as $oTrigger) {
         $res = $oTrigger->precheckTransition($oDocument, $oUser);
         if (PEAR::isError($res)) {
             return $res;
         }
     }
     $iPreviousMetadataVersion = $oDocument->getMetadataVersionId();
     $oDocument->startNewMetadataVersion($oUser);
     KTDocumentUtil::copyMetadata($oDocument, $iPreviousMetadataVersion);
     $iStateId = $oTransition->getTargetStateId();
     $oDocument->setWorkflowStateId($iStateId);
     $res = $oDocument->update();
     if (PEAR::isError($res)) {
         return $res;
     }
     $oTargetState =& KTWorkflowState::get($iStateId);
     $sSourceState = $oSourceState->getName();
     $sTargetState = $oTargetState->getName();
     // create the document transaction record
     $sTransactionComments = sprintf(_kt("Workflow state changed from %s to %s"), $sSourceState, $sTargetState);
     if ($sComments) {
         $sTransactionComments .= _kt("; Reason given was: ") . $sComments;
     }
     $oDocumentTransaction = new DocumentTransaction($oDocument, $sTransactionComments, 'ktcore.transactions.workflow_state_transition');
     $oDocumentTransaction->create();
     // walk the action triggers.
     foreach ($aActionTriggers as $oTrigger) {
         $res = $oTrigger->performTransition($oDocument, $oUser);
         if (PEAR::isError($res)) {
             return $res;
         }
     }
     KTPermissionUtil::updatePermissionLookup($oDocument);
     KTWorkflowUtil::informUsersForState($oTargetState, KTWorkflowUtil::getInformedForState($oTargetState), $oDocument, $oUser, $sComments);
     return true;
 }
Пример #2
0
 function rename($oDocument, $sNewFilename, $oUser)
 {
     $oStorage =& KTStorageManagerUtil::getSingleton();
     $oKTConfig = KTConfig::getSingleton();
     $updateVersion = $oKTConfig->get('tweaks/incrementVersionOnRename', true);
     $iPreviousMetadataVersion = $oDocument->getMetadataVersionId();
     $oOldContentVersion = $oDocument->_oDocumentContentVersion;
     if ($updateVersion) {
         $bSuccess = $oDocument->startNewContentVersion($oUser);
         if (PEAR::isError($bSuccess)) {
             return $bSuccess;
         }
         KTDocumentUtil::copyMetadata($oDocument, $iPreviousMetadataVersion);
     }
     $res = $oStorage->renameDocument($oDocument, $oOldContentVersion, $sNewFilename);
     if (!$res) {
         return PEAR::raiseError(_kt('An error occurred while storing the new file'));
     }
     $oDocument->setLastModifiedDate(getCurrentDateTime());
     $oDocument->setModifiedUserId($oUser->getId());
     if ($updateVersion) {
         // Update version number
         $oDocument->setMinorVersionNumber($oDocument->getMinorVersionNumber() + 1);
     }
     $oDocument->_oDocumentContentVersion->setFilename($sNewFilename);
     $sType = KTMime::getMimeTypeFromFile($sNewFilename);
     $iMimeTypeId = KTMime::getMimeTypeID($sType, $sNewFilename);
     $oDocument->setMimeTypeId($iMimeTypeId);
     $bSuccess = $oDocument->update();
     if ($bSuccess !== true) {
         if (PEAR::isError($bSuccess)) {
             return $bSuccess;
         }
         return PEAR::raiseError(_kt('An error occurred while storing this document in the database'));
     }
     // create the document transaction record
     $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document renamed'), 'ktcore.transactions.update');
     $oDocumentTransaction->create();
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('renameDocument', 'postValidate');
     foreach ($aTriggers as $aTrigger) {
         $sTrigger = $aTrigger[0];
         $oTrigger = new $sTrigger();
         $aInfo = array('document' => $oDocument);
         $oTrigger->setInfo($aInfo);
         $ret = $oTrigger->postValidate();
         if (PEAR::isError($ret)) {
             return $ret;
         }
     }
     // fire subscription alerts for the checked in document
     $oSubscriptionEvent = new SubscriptionEvent();
     $oFolder = Folder::get($oDocument->getFolderID());
     $oSubscriptionEvent->ModifyDocument($oDocument, $oFolder);
     return true;
 }