/** * @param array $configuration * @param ProcessDefinition $definition * @return ProcessTrigger * @throws InvalidParameterException */ public function buildProcessTrigger(array $configuration, ProcessDefinition $definition) { $this->assertConfigurationOptions($configuration, array('event')); $event = $configuration['event']; if (!in_array($event, ProcessTrigger::getAllowedEvents())) { throw new InvalidParameterException(sprintf('Event "%s" is not allowed', $event)); } $field = $this->getConfigurationOption($configuration, 'field', null); $priority = $this->getConfigurationOption($configuration, 'priority', Job::PRIORITY_DEFAULT); $queued = $this->getConfigurationOption($configuration, 'queued', false); $timeShift = $this->getConfigurationOption($configuration, 'time_shift', null); if ($timeShift && !is_int($timeShift) && !$timeShift instanceof \DateInterval) { throw new InvalidParameterException('Time shift parameter must be either integer or DateInterval'); } if ($field && $event != ProcessTrigger::EVENT_UPDATE) { throw new InvalidParameterException('Field is only allowed for update event'); } $trigger = new ProcessTrigger(); $trigger->setEvent($event)->setField($field)->setPriority($priority)->setQueued($queued)->setDefinition($definition); if ($timeShift instanceof \DateInterval) { $trigger->setTimeShiftInterval($timeShift); } else { $trigger->setTimeShift($timeShift); } return $trigger; }
/** * @param bool $hasLogger * @dataProvider debugDataProvider */ public function testDebug($hasLogger) { $doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock(); $definitionName = 'test_definition'; $definition = new ProcessDefinition(); $definition->setName($definitionName); $triggerEvent = ProcessTrigger::EVENT_UPDATE; $trigger = new ProcessTrigger(); $trigger->setEvent($triggerEvent)->setDefinition($definition); $entity = new \stdClass(); $entityId = 1; $data = new ProcessData(array('data' => $entity)); $message = 'Test debug message'; $context = array('definition' => $definitionName, 'event' => $triggerEvent, 'entityId' => $entityId); if ($hasLogger) { $doctrineHelper->expects($this->once())->method('getSingleEntityIdentifier')->with($entity, false)->will($this->returnValue($entityId)); $logger = $this->getMock('Psr\\Log\\LoggerInterface'); $logger->expects($this->once())->method('debug')->with($message, $context); } else { $doctrineHelper->expects($this->never())->method('getSingleEntityIdentifier'); $logger = null; } $processLogger = new ProcessLogger($doctrineHelper, $logger); $processLogger->debug($message, $trigger, $data); }
/** * @param array $configuration * @param ProcessDefinition $definition * @return ProcessTrigger * @throws InvalidParameterException */ public function buildProcessTrigger(array $configuration, ProcessDefinition $definition) { $event = $this->getConfigurationOption($configuration, 'event', null); $cron = $this->getCronExpression($configuration); $this->validateEventAndCronParameters($event, $cron); $field = $this->getConfigurationOption($configuration, 'field', null); $priority = $this->getConfigurationOption($configuration, 'priority', Job::PRIORITY_DEFAULT); $queued = $this->getConfigurationOption($configuration, 'queued', false); $timeShift = $this->getConfigurationOption($configuration, 'time_shift', null); if ($timeShift && !is_int($timeShift) && !$timeShift instanceof \DateInterval) { throw new InvalidParameterException('Time shift parameter must be either integer or DateInterval'); } if ($field && $event !== ProcessTrigger::EVENT_UPDATE) { throw new InvalidParameterException('Field is only allowed for update event'); } $trigger = new ProcessTrigger(); $trigger->setEvent($event)->setField($field)->setPriority($priority)->setQueued($queued)->setDefinition($definition)->setCron($cron); if ($timeShift instanceof \DateInterval) { $trigger->setTimeShiftInterval($timeShift); } else { $trigger->setTimeShift($timeShift); } return $trigger; }
public function testImport() { $importedDefinition = new ProcessDefinition(); $importedEntity = new ProcessTrigger(); $importedEntity->setEvent(ProcessTrigger::EVENT_UPDATE)->setField('testField')->setPriority(Job::PRIORITY_HIGH)->setQueued(true)->setTimeShift(123)->setDefinition($importedDefinition); $this->assertProcessTriggerEntitiesEquals($importedEntity, $this->entity, false); $this->entity->import($importedEntity); $this->assertProcessTriggerEntitiesEquals($importedEntity, $this->entity); }