function generateWorkflowTriggers()
 {
     require_once KT_LIB_DIR . '/workflow/workflowutil.inc.php';
     // get all the transitions, and add a trigger to the util with the appropriate settings.
     $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton();
     $aTransitions = KTWorkflowTransition::getList();
     foreach ($aTransitions as $oTransition) {
         // guard perm
         $iGuardPerm = $oTransition->getGuardPermissionId();
         if (!is_null($iGuardPerm)) {
             $sNamespace = 'ktcore.workflowtriggers.permissionguard';
             $oPerm = KTPermission::get($iGuardPerm);
             $oTrigger = $KTWFTriggerReg->getWorkflowTrigger($sNamespace);
             $oTriggerConfig = KTWorkflowTriggerInstance::createFromArray(array('transitionid' => KTUtil::getId($oTransition), 'namespace' => $sNamespace, 'config' => array('perms' => array($oPerm->getName()))));
         }
         // guard group
         $iGuardGroup = $oTransition->getGuardGroupId();
         if (!is_null($iGuardGroup)) {
             $sNamespace = 'ktcore.workflowtriggers.groupguard';
             $oTrigger = $KTWFTriggerReg->getWorkflowTrigger($sNamespace);
             $oTriggerConfig = KTWorkflowTriggerInstance::createFromArray(array('transitionid' => KTUtil::getId($oTransition), 'namespace' => $sNamespace, 'config' => array('group_id' => $iGuardGroup)));
         }
         // guard role
         $iGuardRole = $oTransition->getGuardRoleId();
         if (!is_null($iGuardRole)) {
             $sNamespace = 'ktcore.workflowtriggers.roleguard';
             $oTrigger = $KTWFTriggerReg->getWorkflowTrigger($sNamespace);
             $oTriggerConfig = KTWorkflowTriggerInstance::createFromArray(array('transitionid' => KTUtil::getId($oTransition), 'namespace' => $sNamespace, 'config' => array('role_id' => $iGuardRole)));
         }
         // guard condition
         $iGuardCondition = $oTransition->getGuardConditionId();
         if (!is_null($iGuardCondition)) {
             $sNamespace = 'ktcore.workflowtriggers.conditionguard';
             $oTrigger = $KTWFTriggerReg->getWorkflowTrigger($sNamespace);
             $oTriggerConfig = KTWorkflowTriggerInstance::createFromArray(array('transitionid' => KTUtil::getId($oTransition), 'namespace' => $sNamespace, 'config' => array('condition_id' => $iGuardCondition)));
         }
     }
 }
Beispiel #2
0
 function do_addactiontrigger()
 {
     $oForm = $this->form_addtransitionaction();
     $res = $oForm->validate();
     $data = $res['results'];
     $errors = $res['errors'];
     if (!empty($errors)) {
         return $oForm->handleError();
     }
     $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton();
     $this->startTransaction();
     $oTrigger = $KTWFTriggerReg->getWorkflowTrigger(KTUtil::arrayGet($data, 'action_name'));
     if (PEAR::isError($oTrigger)) {
         return $oForm->handleError(_kt('Unable to add trigger.'));
     }
     $oTriggerConfig = KTWorkflowTriggerInstance::createFromArray(array('transitionid' => KTUtil::getId($this->oTransition), 'namespace' => KTUtil::arrayGet($data, 'action_name'), 'config' => array()));
     if (PEAR::isError($oTriggerConfig)) {
         return $oForm->handleError(_kt('Unable to add trigger.') . $oTriggerConfig->getMessage());
     }
     // now, if the trigger is editable...
     $oTrigger->loadConfig($oTriggerConfig);
     if ($oTrigger->bIsConfigurable) {
         $this->successRedirectTo('editactiontrigger', _kt("New action added. This action requires configuration:  please specify this below."), array('fTriggerInstanceId' => $oTriggerConfig->getId()));
     } else {
         $this->successRedirectTo('managetransitionactions', _kt("New restriction added."));
     }
     exit(0);
 }