/** * Handles sync task complete event. * * @param SyncTaskCompleteEvent $event */ public function handleEvent($event) { switch ($event->getTaskType()) { case SyncTaskCompleteEvent::TASK_TYPE_DOWNLOAD: $task = new SyncTask(SyncTask::SYNC_TASK_PRESERVEHOST); $task->setName(SyncTaskCompleteEvent::TASK_TYPE_CONVERT); $task->setArguments([$event->getProvider(), $event->getOutputFile()]); if ($event->getDataDescription()) { $task->setArguments(array_merge($task->getArguments(), ['-t', $event->getDataDescription()])); } $this->publisher->publish($task); break; case SyncTaskCompleteEvent::TASK_TYPE_CONVERT: $task = new SyncTask(SyncTask::SYNC_TASK_PRESERVEHOST); $task->setName(SyncTaskCompleteEvent::TASK_TYPE_PUSH); $task->setArguments([$event->getOutputFile(), '-p', $event->getProvider()]); switch ($event->getDataType()) { case SyncTaskCompleteEvent::DATA_TYPE_PARTIAL_DOCUMENTS: $task->setArguments(array_merge($task->getArguments(), ['-d'])); break; default: // No other cases. break; } $this->publisher->publish($task); break; default: // No other cases. break; } }
/** * Test event listener which is registered with foo_publisher. */ public function testListener() { $event = new SyncTaskCompleteEvent(); $event->setTaskType(SyncTaskCompleteEvent::TASK_TYPE_CONVERT); $event->setInputFile('file.xml'); $event->setProvider('test_provider'); $event->setDataType(SyncTaskCompleteEvent::DATA_TYPE_FULL_DOCUMENTS); $event->setOutputFile('file.xml.converted.json'); $dispatcher = $this->getContainer()->get('event_dispatcher'); $dispatcher->dispatch(SyncTaskCompleteEvent::EVENT_NAME, $event); $redis = new Predis\Client(); $this->verifyMessage($redis->get('test'), ['taskType' => SyncTaskCompleteEvent::TASK_TYPE_PUSH, 'commandName' => 'ongr:sync:execute-file -e test file.xml.converted.json -p test_provider']); }
/** * @return array */ public function getTestHandleEventData() { $out = []; // Case #0 convert. $event = new SyncTaskCompleteEvent(); $event->setTaskType(SyncTaskCompleteEvent::TASK_TYPE_CONVERT); $event->setInputFile('file.xml'); $event->setProvider('testProvider'); $event->setDataType(SyncTaskCompleteEvent::DATA_TYPE_FULL_DOCUMENTS); $event->setOutputFile('file.xml.converted.json'); $expected = new SyncTask(SyncTask::SYNC_TASK_PRESERVEHOST); $expected->setName(SyncTaskCompleteEvent::TASK_TYPE_PUSH); $expected->setArguments(['file.xml.converted.json', '-p', 'testProvider']); $out[] = [$event, $expected]; // Case #1 download. $event = new SyncTaskCompleteEvent(); $event->setTaskType(SyncTaskCompleteEvent::TASK_TYPE_DOWNLOAD); $event->setProvider('testProvider'); $event->setDataType(SyncTaskCompleteEvent::DATA_TYPE_FULL_DOCUMENTS); $event->setOutputFile('file.xml'); $event->setDataDescription('delta'); $expected = new SyncTask(SyncTask::SYNC_TASK_PRESERVEHOST); $expected->setName(SyncTaskCompleteEvent::TASK_TYPE_CONVERT); $expected->setArguments(['testProvider', 'file.xml', '-t', 'delta']); $out[] = [$event, $expected]; // Case #2 push. $event = new SyncTaskCompleteEvent(); $event->setTaskType(SyncTaskCompleteEvent::TASK_TYPE_PUSH); $event->setProvider('testProvider'); $event->setDataType(SyncTaskCompleteEvent::DATA_TYPE_FULL_DOCUMENTS); $out[] = [$event]; // Case #3 convert partial. $event = new SyncTaskCompleteEvent(); $event->setTaskType(SyncTaskCompleteEvent::TASK_TYPE_CONVERT); $event->setInputFile('file.xml'); $event->setProvider('testProvider'); $event->setDataType(SyncTaskCompleteEvent::DATA_TYPE_PARTIAL_DOCUMENTS); $event->setOutputFile('file.xml.converted.json'); $expected = new SyncTask(SyncTask::SYNC_TASK_PRESERVEHOST); $expected->setName(SyncTaskCompleteEvent::TASK_TYPE_PUSH); $expected->setArguments(['file.xml.converted.json', '-p', 'testProvider', '-d']); $out[] = [$event, $expected]; return $out; }
/** * Handles SyncTaskCompleteEvent and stops propagation if needed. * * @param SyncTaskCompleteEvent $event */ public function handleEvent(SyncTaskCompleteEvent $event) { if ($this->halt) { $event->stopPropagation(); } }