/**
  * @param RemoveDojoCommand $command
  */
 public function handle(RemoveDojoCommand $command)
 {
     $dojo = $this->doctrine->getRepository('CoderDojoWebsiteBundle:Dojo')->find($command->getId());
     $this->doctrine->remove($dojo);
     $this->doctrine->flush();
     $event = new DojoRemovedEvent($command->getId());
     $this->eventRecorder->record($event);
 }
 public function run(OutputInterface $output)
 {
     $output->writeln('**********************************');
     $output->writeln('Starting sync for dojos');
     $this->progressBar = $this->newProgressBar($output);
     $externalDojos = $this->zen->getDojos();
     $this->progressBar->start(count($externalDojos));
     $this->progressBar->setMessage('Iterating dojos...');
     foreach ($externalDojos as $externalDojo) {
         $this->progressBar->setMessage('Handling ' . $externalDojo->getName());
         if (true === $externalDojo->isRemoved()) {
             $this->removeInternalDojo($externalDojo);
             continue;
         }
         try {
             $internalDojo = $this->getInternalDojo($externalDojo->getZenId(), $externalDojo->getCity(), $externalDojo->getTwitter(), $externalDojo->getEmail());
         } catch (NonUniqueResultException $exception) {
             $this->unmatched[] = $externalDojo;
             continue;
         }
         if (null !== $internalDojo) {
             $this->updateInternalDojo($internalDojo, $externalDojo);
             continue;
         }
         $this->createDojo($externalDojo);
     }
     $this->progressBar->setMessage('Flushing');
     $this->doctrine->flush();
     $this->progressBar->setMessage('Finished syncing dojos!');
     $this->progressBar->finish();
     $output->writeln($this->countNew . ' New dojos added');
     $output->writeln($this->countUpdated . ' Existing dojos updated');
     $output->writeln($this->countRemoved . ' Existing dojos removed');
     $this->notifySlack();
 }
 /**
  * @param CreateEventCommand $command
  */
 public function handle(CreateEventCommand $command)
 {
     $dojo = $this->doctrine->getRepository('CoderDojoWebsiteBundle:Dojo')->find($command->getDojoId());
     $event = new DojoEvent();
     $event->setName($command->getName());
     $event->setDate($command->getDate());
     $event->setType($command->getType());
     $event->setZenId($command->getZenId());
     $event->setUrl($command->getUrl());
     $event->setDojo($dojo);
     $dojo->addEvent($event);
     $this->doctrine->persist($event);
     $this->doctrine->flush();
     $event = new EventCreatedEvent($command->getDojoId(), $command->getName(), $command->getDate(), $command->getUrl(), $command->getZenId(), $command->getType());
     $this->eventRecorder->record($event);
 }
 /**
  * Execute the command. Get all the deposits needing to be harvested. Each
  * deposit will be passed to the commands processDeposit() function.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected final function execute(InputInterface $input, OutputInterface $output)
 {
     $this->preExecute();
     $deposits = $this->getDeposits($input->getOption('retry'), $input->getArgument('deposit-id'));
     if ($input->hasOption('limit')) {
         $deposits = array_slice($deposits, 0, $input->getOption('limit'));
     }
     $count = count($deposits);
     $this->logger->info("Processing {$count} deposits.");
     $this->preprocessDeposits($deposits);
     foreach ($deposits as $deposit) {
         try {
             $result = $this->processDeposit($deposit);
         } catch (Exception $e) {
             $this->logger->error($e->getMessage());
             $deposit->setState($this->errorState());
             $deposit->addToProcessingLog($this->failureLogMessage());
             $deposit->addErrorLog(get_class($e) . $e->getMessage());
             $this->em->flush($deposit);
             continue;
         }
         if ($input->getOption('dry-run')) {
             continue;
         }
         if ($result) {
             $deposit->setState($this->nextState());
             $deposit->addToProcessingLog($this->successLogMessage());
         } else {
             $deposit->setState($this->errorState());
             $deposit->addToProcessingLog($this->failureLogMessage());
         }
         $this->em->flush($deposit);
     }
 }
Example #5
0
 /**
  * "Success" form handler
  *
  * @param OrderItem $entity
  */
 protected function onSuccess(OrderItem $entity)
 {
     $this->manager->persist($entity);
     $this->manager->flush();
 }
 public function run(OutputInterface $output)
 {
     $output->writeln('**********************************');
     $output->writeln('Starting sync for Events');
     $progressbar = $this->newProgressBar($output);
     $zenIds = $this->doctrine->getRepository('CoderDojoWebsiteBundle:Dojo')->getZenIds();
     $externalEvents = $this->zen->getEvents($zenIds);
     $progressbar->start(count($externalEvents));
     $progressbar->setMessage('Iterating Events...');
     $countNew = 0;
     $countUpdated = 0;
     $countNoMatch = 0;
     foreach ($externalEvents as $externalEvent) {
         $progressbar->setMessage('Handling ' . $externalEvent->getName());
         $internalEvent = $this->doctrine->getRepository('CoderDojoWebsiteBundle:DojoEvent')->findOneBy(['zenId' => $externalEvent->getZenId()]);
         /** @var Dojo $dojo */
         $internalDojo = $this->doctrine->getRepository('CoderDojoWebsiteBundle:Dojo')->findOneBy(['zenId' => $externalEvent->getZenDojoId()]);
         if (null === $internalDojo) {
             $progressbar->setMessage('No internal dojo found!');
             $progressbar->advance();
             $countNoMatch++;
             continue;
         }
         if (null === $internalEvent) {
             $progressbar->setMessage('No internal event found');
             $command = new CreateEventCommand($internalDojo->getId(), $externalEvent->getName(), $externalEvent->getStartTime(), $internalDojo->getZenUrl(), $externalEvent->getZenId(), DojoEvent::TYPE_ZEN);
             $this->commandBus->handle($command);
             $progressbar->advance();
             $countNew++;
         } else {
             $progressbar->setMessage('Internal event found');
             $internalEvent->setName($externalEvent->getName());
             $internalEvent->setDate($externalEvent->getStartTime());
             $internalEvent->setUrl($internalDojo->getZenUrl());
             $progressbar->advance();
             $countUpdated++;
         }
     }
     $progressbar->setMessage('Flushing');
     $this->doctrine->flush();
     $progressbar->setMessage('Finished syncing Events!');
     $progressbar->finish();
     $output->writeln($countNew . ' New events added');
     $output->writeln($countUpdated . ' Existing events updated');
     $output->writeln($countNoMatch . ' events could not be matched with a dojo');
     $message = "Zen synchronizer just handled events.";
     $attachments = [];
     $attachment = new Attachment();
     $attachment->setFallback($countNew . " events added.");
     $attachment->setText($countNew . " events added.");
     $attachment->setColor('good');
     $attachments[] = $attachment;
     $attachment = new Attachment();
     $attachment->setFallback($countUpdated . " events updated.");
     $attachment->setText($countUpdated . " events updated.");
     $attachment->setColor('warning');
     $attachments[] = $attachment;
     $attachment = new Attachment();
     $attachment->setFallback($countNoMatch . " events not matched.");
     $attachment->setText($countNoMatch . " events not matched.");
     $attachment->setColor('danger');
     $attachments[] = $attachment;
     $this->slackService->sendToChannel('#website-nl', $message, $attachments);
 }