/**
  * @param WorkflowMessageInQueue $workflowMessageInQueue
  * @param RedBeanModel $model
  */
 protected function processWorkflowMessageInQueue(WorkflowMessageInQueue $workflowMessageInQueue, RedBeanModel $model)
 {
     $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($workflowMessageInQueue->savedWorkflow);
     if (!$workflow->getIsActive()) {
         return;
     }
     WorkflowEmailMessagesUtil::processOnWorkflowMessageInQueueJob($workflow, $model, self::resolveTriggeredByUser($workflowMessageInQueue));
 }
 protected function resolveSavedWorkflowAndWorkflowByPostData(array $postData, &$savedWorkflow, &$workflow, $type, $id = null, $isBeingCopied = false)
 {
     if ($id == null) {
         $this->resolveCanCurrentUserAccessWorkflows();
         $savedWorkflow = new SavedWorkflow();
         $workflow = new Workflow();
         $workflow->setType($type);
     } elseif ($isBeingCopied) {
         $savedWorkflow = new SavedWorkflow();
         $oldWorkflow = SavedWorkflow::getById(intval($id));
         ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($oldWorkflow);
         ZurmoCopyModelUtil::copy($oldWorkflow, $savedWorkflow);
         $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
     } else {
         $savedWorkflow = SavedWorkflow::getById(intval($id));
         ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($savedWorkflow);
         $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
     }
     DataToWorkflowUtil::resolveWorkflowByWizardPostData($workflow, $postData, WorkflowToWizardFormAdapter::getFormClassNameByType($type));
 }
Ejemplo n.º 3
0
 /**
  * @param ByTimeWorkflowInQueue $byTimeWorkflowInQueue
  * @param RedBeanModel $model
  * @throws FailedToSaveModelException
  */
 protected function processByTimeWorkflowInQueue(ByTimeWorkflowInQueue $byTimeWorkflowInQueue, RedBeanModel $model)
 {
     $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($byTimeWorkflowInQueue->savedWorkflow);
     if (!$workflow->getIsActive()) {
         return;
     }
     $workflow->setTimeTriggerRequireChangeToProcessToFalse();
     if (WorkflowTriggersUtil::areTriggersTrueOnByTimeWorkflowQueueJob($workflow, $model)) {
         WorkflowActionsUtil::processOnByTimeWorkflowInQueueJob($workflow, $model, Yii::app()->user->userModel);
         WorkflowEmailMessagesUtil::processAfterSave($workflow, $model, Yii::app()->user->userModel);
         if ($model->isModified()) {
             $saved = $model->save();
             if (!$saved) {
                 throw new FailedToSaveModelException();
             }
         }
     }
 }
 /**
  * Check if picklist modification caused some issues with workflow triggers and if yes notify users
  * @return array
  * @throws NotSupportedException
  */
 public static function getWorkflowsWithInvalidTriggerCustomFieldValue()
 {
     $savedWorkflows = SavedWorkflow::getAll();
     $workflows = array();
     foreach ($savedWorkflows as $savedWorkflow) {
         $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
         $hasInvalidCustomFieldValue = false;
         foreach ($workflow->getTriggers() as $trigger) {
             $modelClassName = $trigger->getModelClassName();
             $customFieldAttributeNames = CustomFieldUtil::getCustomFieldAttributeNames($modelClassName);
             $triggerAttributeName = $trigger->getAttribute();
             if (in_array($triggerAttributeName, $customFieldAttributeNames)) {
                 $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($modelClassName, $triggerAttributeName);
                 $allCustomFieldValues = unserialize($customFieldData->serializedData);
                 // Check with triggers that allow single value
                 if (in_array($trigger->getOperator(), array(OperatorRules::TYPE_EQUALS, OperatorRules::TYPE_DOES_NOT_EQUAL, OperatorRules::TYPE_BECOMES, OperatorRules::TYPE_WAS))) {
                     if (!in_array($trigger->value, $allCustomFieldValues)) {
                         $hasInvalidCustomFieldValue = true;
                         break;
                     }
                 } elseif (in_array($trigger->getOperator(), array(OperatorRules::TYPE_BECOMES_ONE_OF, OperatorRules::TYPE_WAS_ONE_OF, OperatorRules::TYPE_ONE_OF))) {
                     $triggerSelectedCustomFieldValues = MultiSelectDropDownSanitizerUtil::getCustomFieldValuesFromValueString($trigger->value);
                     foreach ($triggerSelectedCustomFieldValues as $triggerValue) {
                         if (!in_array($triggerValue, $allCustomFieldValues)) {
                             $hasInvalidCustomFieldValue = true;
                             break 2;
                         }
                     }
                 }
             }
         }
         if ($hasInvalidCustomFieldValue) {
             $workflows[] = $workflow;
         }
     }
     return $workflows;
 }
 /**
  * Given a RedBeanModel, query workflow rules and process any beforeSave triggers for either on-save or
  * by-time workflows.  Called from @see WokflowsObserver->processWorkflowBeforeSave
  * @param Item $model
  * @param User $triggeredByUser
  * @throws NotSupportedException if the workflow type is not valid
  */
 public static function resolveBeforeSaveByModel(Item $model, User $triggeredByUser)
 {
     $savedWorkflows = SavedWorkflow::getActiveByModuleClassNameAndIsNewModel($model::getModuleClassName(), $model->getIsNewModel());
     foreach ($savedWorkflows as $savedWorkflow) {
         $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
         if (WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $model)) {
             if ($workflow->getType() == Workflow::TYPE_BY_TIME) {
                 $model->addWorkflowToProcessAfterSave($workflow);
             } elseif ($workflow->getType() == Workflow::TYPE_ON_SAVE) {
                 WorkflowActionsUtil::processBeforeSave($workflow, $model, $triggeredByUser);
                 $model->addWorkflowToProcessAfterSave($workflow);
             } else {
                 throw new NotSupportedException();
             }
         }
     }
 }
 /**
  * @depends testGetWorkflowsMissingRequiredActionAttributesWhereActionIsOk
  */
 public function testGetWorkflowsMissingRequiredActionAttributesWhereActionIsMissingRequiredAttribute()
 {
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('aDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(5);
     $workflow->setModuleClassName('WorkflowsTest2Module');
     $workflow->setName('myFirstWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     //Add action that is missing required owner
     $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_CREATE;
     $action->relation = 'hasMany2';
     $attributes = array('string' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'), 'lastName' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'));
     $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
     $workflow->addAction($action);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
     $this->assertTrue($saved);
     $this->assertEquals(array($workflow), WorkflowActionsUtil::getWorkflowsMissingRequiredActionAttributes());
 }
 /**
  * @depends testResolveWorkflowToSavedWorkflow
  */
 public function testMakeWorkflowBySavedWorkflow()
 {
     $savedWorkflows = SavedWorkflow::getAll();
     $this->assertEquals(1, count($savedWorkflows));
     $savedWorkflow = $savedWorkflows[0];
     $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
     $triggers = $workflow->getTriggers();
     $this->assertEquals('WorkflowsTestModule', $workflow->getModuleClassName());
     $this->assertEquals('myFirstWorkflow', $workflow->getName());
     $this->assertEquals('aDescription', $workflow->getDescription());
     $this->assertTrue($workflow->getIsActive());
     $this->assertEquals(5, $workflow->getOrder());
     $this->assertEquals(Workflow::TRIGGER_ON_NEW, $workflow->getTriggerOn());
     $this->assertEquals(Workflow::TYPE_ON_SAVE, $workflow->getType());
     $this->assertEquals('1 and 2 or 3 or 4', $workflow->getTriggersStructure());
     $this->assertCount(4, $triggers);
 }
 public static function getWorkflowsMissingRequiredActionAttributes()
 {
     $savedWorkflows = SavedWorkflow::getAll();
     $workflows = array();
     foreach ($savedWorkflows as $savedWorkflow) {
         $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
         $missingRequired = false;
         foreach ($workflow->getActions() as $action) {
             if ($action->isModelActionVariant() && !$action->isTypeAnUpdateVariant() && $action->isMissingRequiredActionAttributes()) {
                 $missingRequired = true;
                 break;
             }
         }
         if ($missingRequired) {
             $workflows[] = $workflow;
         }
     }
     return $workflows;
 }