/**
  * @param ByTimeWorkflowInQueue $model
  * @return string
  */
 public static function renderSummaryContent(ByTimeWorkflowInQueue $model)
 {
     $params = array('label' => strval($model->savedWorkflow), 'wrapLabel' => false);
     $moduleClassName = $model->getModuleClassName();
     $moduleId = $moduleClassName::getDirectoryName();
     $element = new DetailsLinkActionElement('default', $moduleId, $model->savedWorkflow->id, $params);
     return $element->render() . static::resolveModelAndContent($model);
 }
 /**
  * @param ByTimeWorkflowInQueue $model
  * @return string
  */
 public static function renderSummaryContent(ByTimeWorkflowInQueue $model)
 {
     $params = array('label' => strval($model->savedWorkflow), 'wrapLabel' => false);
     $moduleClassName = $model->getModuleClassName();
     $moduleId = $moduleClassName::getDirectoryName();
     $element = new DetailsLinkActionElement('default', $moduleId, $model->savedWorkflow->id, $params);
     $relatedModel = self::resolveModel($model);
     return $element->render() . ' &mdash; <span class="less-pronounced-text">' . self::resolveModelContent($relatedModel) . '</span>';
 }
 public static function createExpiredByTimeWorkflowInQueue(RedBeanModel $model, SavedWorkflow $savedWorkflow)
 {
     $byTimeWorkflowInQueue = new ByTimeWorkflowInQueue();
     $byTimeWorkflowInQueue->modelClassName = get_class($model);
     $byTimeWorkflowInQueue->modelItem = $model;
     $byTimeWorkflowInQueue->processDateTime = '2007-02-02 00:00:00';
     $byTimeWorkflowInQueue->savedWorkflow = $savedWorkflow;
     $saved = $byTimeWorkflowInQueue->save();
     assert($saved);
     // Not Coding Standard
     return $byTimeWorkflowInQueue;
 }
 public function testResolveToAddJobToQueueAfterSaveOfModelIsNotANewModelAndProcessDateTimeHasNotChanged()
 {
     $byTimeWorkflowInQueue = new ByTimeWorkflowInQueue();
     $byTimeWorkflowInQueue->modelClassName = get_class(self::$testModel);
     $byTimeWorkflowInQueue->modelItem = self::$testModel;
     $byTimeWorkflowInQueue->processDateTime = '2007-02-02 00:00:00';
     $byTimeWorkflowInQueue->savedWorkflow = self::$savedWorkflow;
     $saved = $byTimeWorkflowInQueue->save();
     $this->assertTrue($saved);
     Yii::app()->jobQueue->deleteAll();
     $this->assertCount(0, Yii::app()->jobQueue->getAll());
     InQueueUtil::resolveToAddJobToQueueAfterSaveOfModel($byTimeWorkflowInQueue, 'abc');
     $this->assertCount(0, Yii::app()->jobQueue->getAll());
 }
 public function testRun()
 {
     $model = WorkflowTestHelper::createWorkflowModelTestItem('Green', '514');
     $timeTrigger = array('attributeIndexOrDerivedType' => 'string', 'operator' => OperatorRules::TYPE_EQUALS, 'value' => '514', 'durationInterval' => '5');
     $actions = array(array('type' => ActionForWorkflowForm::TYPE_UPDATE_SELF, ActionForWorkflowForm::ACTION_ATTRIBUTES => array('string' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'))));
     $savedWorkflow = WorkflowTestHelper::createByTimeSavedWorkflow($timeTrigger, array(), $actions);
     WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($model, $savedWorkflow);
     $this->assertEquals(1, count(ByTimeWorkflowInQueue::getAll()));
     $job = new ByTimeWorkflowInQueueJob();
     $this->assertTrue($job->run());
     $this->assertEquals(0, count(ByTimeWorkflowInQueue::getAll()));
     $this->assertEquals('jason', $model->string);
 }
Exemplo n.º 6
0
 /**
  * Special method to load ByTimeWorkflowInQueue models
  */
 public function actionLoadByTimeWorkflowInQueue()
 {
     if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) {
         throw new NotSupportedException();
     }
     $model = new Account();
     $model->name = 'test account';
     $saved = $model->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
     $savedWorkflow = new SavedWorkflow();
     $savedWorkflow->name = 'Test for demo Time Queue model';
     $savedWorkflow->description = 'description';
     $savedWorkflow->moduleClassName = 'AccountsModule';
     $savedWorkflow->triggerOn = Workflow::TRIGGER_ON_NEW;
     $savedWorkflow->type = Workflow::TYPE_BY_TIME;
     $savedWorkflow->isActive = false;
     $savedWorkflow->order = 1;
     $savedWorkflow->serializedData = serialize(array(ComponentForWorkflowForm::TYPE_TRIGGERS => array(), ComponentForWorkflowForm::TYPE_ACTIONS => array(), ComponentForWorkflowForm::TYPE_EMAIL_MESSAGES => array()));
     $saved = $savedWorkflow->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
     for ($i = 1; $i < 6; $i++) {
         $byTimeWorkflowInQueue = new ByTimeWorkflowInQueue();
         $byTimeWorkflowInQueue->modelClassName = get_class($model);
         $byTimeWorkflowInQueue->modelItem = $model;
         $byTimeWorkflowInQueue->processDateTime = '2007-02-0' . $i . ' 00:00:00';
         $byTimeWorkflowInQueue->savedWorkflow = $savedWorkflow;
         $saved = $byTimeWorkflowInQueue->save();
         if (!$saved) {
             throw new NotSupportedException();
         }
     }
 }
Exemplo n.º 7
0
 /**
  * @see BaseJob::run()
  */
 public function run()
 {
     try {
         $originalUser = Yii::app()->user->userModel;
         Yii::app()->user->userModel = BaseControlUserConfigUtil::getUserToRunAs();
         foreach (ByTimeWorkflowInQueue::getModelsToProcess(self::$pageSize) as $byTimeWorkflowInQueue) {
             try {
                 $model = $this->resolveModel($byTimeWorkflowInQueue);
                 $this->resolveSavedWorkflowIsValid($byTimeWorkflowInQueue);
                 $this->processByTimeWorkflowInQueue($byTimeWorkflowInQueue, $model);
             } catch (NotFoundException $e) {
                 WorkflowUtil::handleProcessingException($e, 'application.modules.workflows.jobs.ByTimeWorkflowInQueueJob.run');
             }
             $byTimeWorkflowInQueue->delete();
         }
         Yii::app()->user->userModel = $originalUser;
         return true;
     } catch (MissingASuperAdministratorException $e) {
         //skip running workflow, since no super administrators are available.
         $this->errorMessage = Zurmo::t('WorkflowsModule', 'Could not process since no super administrators were found');
         return false;
     }
 }
 /**
  * @see BaseJob::run()
  */
 public function run()
 {
     try {
         $originalUser = Yii::app()->user->userModel;
         Yii::app()->user->userModel = BaseControlUserConfigUtil::getUserToRunAs();
         $processedModelsCount = 0;
         $batchSize = $this->resolveBatchSize();
         if ($batchSize != null) {
             $resolvedBatchSize = $batchSize + 1;
         } else {
             $resolvedBatchSize = null;
         }
         foreach (ByTimeWorkflowInQueue::getModelsToProcess($resolvedBatchSize) as $byTimeWorkflowInQueue) {
             if ($processedModelsCount < $batchSize || $batchSize == null) {
                 try {
                     $model = $this->resolveModel($byTimeWorkflowInQueue);
                     $this->resolveSavedWorkflowIsValid($byTimeWorkflowInQueue);
                     $this->processByTimeWorkflowInQueue($byTimeWorkflowInQueue, $model);
                 } catch (NotFoundException $e) {
                     WorkflowUtil::handleProcessingException($e, 'application.modules.workflows.jobs.ByTimeWorkflowInQueueJob.run');
                 }
                 $byTimeWorkflowInQueue->delete();
                 $processedModelsCount++;
             } else {
                 Yii::app()->jobQueue->add('ByTimeWorkflowInQueue', 5);
                 break;
             }
         }
         Yii::app()->user->userModel = $originalUser;
         return true;
     } catch (MissingASuperAdministratorException $e) {
         //skip running workflow, since no super administrators are available.
         $this->errorMessage = Zurmo::t('WorkflowsModule', 'Could not process since no super administrators were found');
         return false;
     }
 }
 public function testPagedRun()
 {
     $model = WorkflowTestHelper::createWorkflowModelTestItem('Blue', '514');
     $timeTrigger = array('attributeIndexOrDerivedType' => 'string', 'operator' => OperatorRules::TYPE_EQUALS, 'value' => '514', 'durationInterval' => '5');
     $actions = array(array('type' => ActionForWorkflowForm::TYPE_UPDATE_SELF, ActionForWorkflowForm::ACTION_ATTRIBUTES => array('string' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'))));
     $savedWorkflow = WorkflowTestHelper::createByTimeSavedWorkflow($timeTrigger, array(), $actions);
     for ($index = 0; $index < 10; $index++) {
         WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($model, $savedWorkflow);
     }
     InQueueBatchSizeConfigUtil::setBatchSize(5);
     Yii::app()->jobQueue->deleteAll();
     $this->assertCount(0, Yii::app()->jobQueue->getAll());
     $this->assertEquals(10, count(ByTimeWorkflowInQueue::getAll()));
     $job = new ByTimeWorkflowInQueueJob();
     $this->assertTrue($job->run());
     $this->assertEquals(5, count(ByTimeWorkflowInQueue::getAll()));
     $jobs = Yii::app()->jobQueue->getAll();
     $this->assertCount(1, $jobs);
     $this->assertEquals('ByTimeWorkflowInQueue', $jobs[key($jobs)][0]['jobType']);
     Yii::app()->jobQueue->deleteAll();
     $this->assertTrue($job->run());
     $this->assertEquals(0, count(ByTimeWorkflowInQueue::getAll()));
     $this->assertCount(0, Yii::app()->jobQueue->getAll());
 }
 public static function getDefaultMetadata()
 {
     $metadata = parent::getDefaultMetadata();
     $metadata[__CLASS__] = array('noAudit' => array('isNewModel'));
     return $metadata;
 }
Exemplo n.º 11
0
 /**
  * @depends testResolveAfterSaveByModel
  */
 public function testResolveAfterSaveByModelForByTime()
 {
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('aDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(5);
     $workflow->setModuleClassName('WorkflowsTestModule');
     $workflow->setName('myFirstWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_BY_TIME);
     $workflow->setTriggersStructure('1');
     $workflow->setIsActive(true);
     //Add time trigger
     $trigger = new TimeTriggerForWorkflowForm('WorkflowsTestModule', 'WorkflowModelTestItem', $workflow->getType());
     $trigger->attributeIndexOrDerivedType = 'date';
     $trigger->durationSeconds = '500';
     $trigger->valueType = 'Is Time For';
     $workflow->setTimeTrigger($trigger);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $workflow->setId($savedWorkflow->id);
     //set Id back.
     $model = new WorkflowModelTestItem();
     $model->lastName = 'something';
     $model->string = 'aValue';
     $model->date = '2013-03-03';
     $saved = $model->save();
     $this->assertTrue($saved);
     $model->addWorkflowToProcessAfterSave($workflow);
     $this->assertEquals(0, count(ByTimeWorkflowInQueue::getAll()));
     SavedWorkflowsUtil::resolveAfterSaveByModel($model, Yii::app()->user->userModel);
     $this->assertEquals(1, count(ByTimeWorkflowInQueue::getAll()));
 }
 /**
  * @depends testResolveByWorkflowIdAndModel
  */
 public function testGetModelsToProcess($pageSize)
 {
     $this->assertEquals(1, ByTimeWorkflowInQueue::getCount());
     $models = ByTimeWorkflowInQueue::getModelsToProcess(10);
     $this->assertEquals(1, count($models));
     //Now have one that is not ready for processing. It should still only get 1
     $model = new WorkflowModelTestItem();
     $model->lastName = 'Green2';
     $model->string = 'string2';
     $saved = $model->save();
     $this->assertTrue($saved);
     $savedWorkflows = SavedWorkflow::getByName('some workflow2');
     $byTimeWorkflowInQueue = new ByTimeWorkflowInQueue();
     $byTimeWorkflowInQueue->modelClassName = get_class($model);
     $byTimeWorkflowInQueue->modelItem = $model;
     $byTimeWorkflowInQueue->processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 86400);
     $byTimeWorkflowInQueue->savedWorkflow = $savedWorkflows[0];
     $saved = $byTimeWorkflowInQueue->save();
     $this->assertTrue($saved);
     $models = ByTimeWorkflowInQueue::getModelsToProcess(10);
     $this->assertEquals(1, count($models));
 }
 /**
  * @param Workflow $workflow
  * @param RedBeanModel $model
  * @throws FailedToSaveModelException
  */
 protected static function processToByTimeWorkflowInQueue(Workflow $workflow, RedBeanModel $model)
 {
     assert('$workflow->getId() > 0');
     try {
         $byTimeWorkflowInQueue = ByTimeWorkflowInQueue::resolveByWorkflowIdAndModel(SavedWorkflow::getById((int) $workflow->getId()), $model);
         $byTimeWorkflowInQueue->processDateTime = static::resolveProcessDateTimeByWorkflowAndModel($workflow, $model);
         $saved = $byTimeWorkflowInQueue->save();
         if (!$saved) {
             throw new FailedToSaveModelException();
         }
     } catch (ValueForProcessDateTimeIsNullException $e) {
         //For now just log this exception. If this exception is thrown it means a date or dateTime
         //somehow was set to empty, so we can't properly process this.
         WorkflowUtil::handleProcessingException($e, 'application.modules.workflows.utils.SavedWorkflowsUtil.processToByTimeWorkflowInQueue');
     }
 }
 public function testMassDeletePagesProperlyAndRemovesAllSelectedForByTimeWorkflowInQueue()
 {
     //MassDelete for selected Record Count
     $byTimeWorkflowInQueue01 = WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($this->model, $this->savedWorkflow);
     $byTimeWorkflowInQueue02 = WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($this->model, $this->savedWorkflow);
     $byTimeWorkflowInQueue03 = WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($this->model, $this->savedWorkflow);
     $byTimeWorkflowInQueue04 = WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($this->model, $this->savedWorkflow);
     $byTimeWorkflowInQueue05 = WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($this->model, $this->savedWorkflow);
     $byTimeWorkflowInQueue06 = WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($this->model, $this->savedWorkflow);
     $byTimeWorkflowInQueue07 = WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($this->model, $this->savedWorkflow);
     $byTimeWorkflowInQueue08 = WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($this->model, $this->savedWorkflow);
     $byTimeWorkflowInQueue09 = WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($this->model, $this->savedWorkflow);
     $byTimeWorkflowInQueue10 = WorkflowTestHelper::createExpiredByTimeWorkflowInQueue($this->model, $this->savedWorkflow);
     //save Model MassDelete for entire search result
     $this->setGetArray(array('selectAll' => '1', 'ByTimeWorkflowInQueue_page' => 1));
     $this->setPostArray(array('selectedRecordCount' => 10));
     //Run Mass Delete using progress save for page1.
     $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
     $this->assertEquals(5, $pageSize);
     $this->runControllerWithExitExceptionAndGetContent('workflows/defaultTimeQueue/massDelete');
     //check for previous mass delete progress
     $models = ByTimeWorkflowInQueue::getAll();
     $this->assertEquals(5, count($models));
     $this->setGetArray(array('selectAll' => '1', 'ByTimeWorkflowInQueue_page' => 2));
     $this->setPostArray(array('selectedRecordCount' => 10));
     //Run Mass Delete using progress save for page2.
     $pageSize = Yii::app()->pagination->getForCurrentUserByType('massDeleteProgressPageSize');
     $this->assertEquals(5, $pageSize);
     $this->runControllerWithNoExceptionsAndGetContent('workflows/defaultTimeQueue/massDeleteProgress');
     //calculating count
     $models = ByTimeWorkflowInQueue::getAll();
     $this->assertEquals(0, count($models));
 }