Exemplo n.º 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;
 }
Exemplo n.º 2
0
 function do_savenotifications()
 {
     $oForm = $this->form_editnotifications($this->oState);
     $res = $oForm->validate();
     if (!empty($res['errors'])) {
         return $oForm->handleError();
     }
     $data = $res['results'];
     // now, an annoying problem is that we do *not* have the final set.
     // so we need to get the original, add the new ones, remove the old ones.
     //
     // because its not *really* isolated properly, we need to post-process
     // the data.
     // we need the old one
     $aAllowed = KTWorkflowUtil::getInformedForState($this->oState);
     $user_pattern = '|users\\[(.*)\\]|';
     $group_pattern = '|groups\\[(.*)\\]|';
     $role_pattern = '|roles\\[(.*)\\]|';
     $user = KTUtil::arrayGet($aAllowed, 'user', array());
     $group = KTUtil::arrayGet($aAllowed, 'group', array());
     $role = KTUtil::arrayGet($aAllowed, 'role', array());
     // do a quick overpass
     $newAllowed = array();
     if (!empty($user)) {
         $newAllowed['user'] = array_combine($user, $user);
     } else {
         $newAllowed['user'] = array();
     }
     if (!empty($group)) {
         $newAllowed['group'] = array_combine($group, $group);
     } else {
         $newAllowed['group'] = array();
     }
     if (!empty($role)) {
         $newAllowed['role'] = array_combine($role, $role);
     } else {
         $newAllowed['role'] = array();
     }
     $added = explode(',', $data['users']['added']);
     $removed = explode(',', $data['users']['removed']);
     foreach ($added as $akey) {
         $matches = array();
         if (preg_match($user_pattern, $akey, $matches)) {
             $newAllowed['user'][$matches[1]] = $matches[1];
         } else {
             if (preg_match($group_pattern, $akey, $matches)) {
                 $newAllowed['group'][$matches[1]] = $matches[1];
             } else {
                 if (preg_match($role_pattern, $akey, $matches)) {
                     $newAllowed['role'][$matches[1]] = $matches[1];
                 }
             }
         }
     }
     foreach ($removed as $akey) {
         $matches = array();
         if (preg_match($user_pattern, $akey, $matches)) {
             unset($newAllowed['user'][$matches[1]]);
         } else {
             if (preg_match($group_pattern, $akey, $matches)) {
                 unset($newAllowed['group'][$matches[1]]);
             } else {
                 if (preg_match($role_pattern, $akey, $matches)) {
                     unset($newAllowed['role'][$matches[1]]);
                 }
             }
         }
     }
     // FIXME check that these are all users.
     $res = KTWorkflowUtil::setInformedForState($this->oState, $newAllowed);
     if (PEAR::isError($res)) {
         return $oForm->handleError($res->getMessage());
     }
     $this->successRedirectTo("managenotifications", _kt("Notifications updated."));
 }