Exemplo n.º 1
0
 public function notify(DojoCreatedEvent $event)
 {
     $attachment = new Attachment();
     $attachment->setFallback(sprintf('Er is een nieuwe dojo toegevoegd! %s (Website: $s)', $event->getName(), $event->getWebsite()));
     $attachment->setText('Er is een nieuwe dojo toegevoegd, welkom! Is dit jouw dojo? Claim hem op coderdojo.nl');
     $attachment->setColor('good');
     $nameField = new AttachmentField();
     $nameField->setTitle('Name');
     $nameField->setValue($event->getName());
     $nameField->setShort(true);
     $cityField = new AttachmentField();
     $cityField->setTitle('City');
     $cityField->setValue($event->getCity());
     $cityField->setShort(true);
     $emailField = new AttachmentField();
     $emailField->setTitle('Email:');
     $emailField->setValue($event->getEmail());
     $emailField->setShort(true);
     $websiteField = new AttachmentField();
     $websiteField->setTitle('Website');
     $websiteField->setValue($event->getWebsite());
     $websiteField->setShort(true);
     $attachment->addField($nameField);
     $attachment->addField($cityField);
     $attachment->addField($emailField);
     $attachment->addField($websiteField);
     $this->slackService->sendToChannel('#website-nl', '', [$attachment]);
 }
 /**
  * Created notification for slack to keep us up to date on the sync process
  */
 private function notifySlack()
 {
     $message = "Zen synchronizer just handled dojo's.";
     $attachments = [];
     $attachment = new Attachment();
     $attachment->setFallback($this->countNew . " dojo's added.");
     $attachment->setText($this->countNew . " dojo's added.");
     $attachment->setColor('good');
     $attachments[] = $attachment;
     $attachment = new Attachment();
     $attachment->setFallback($this->countUpdated . " dojo's updated.");
     $attachment->setText($this->countUpdated . " dojo's updated.");
     $attachment->setColor('warning');
     $attachments[] = $attachment;
     $attachment = new Attachment();
     $attachment->setFallback($this->countRemoved . " dojo's removed.");
     $attachment->setText($this->countRemoved . " dojo's removed.");
     $attachment->setColor('danger');
     $attachments[] = $attachment;
     $this->slackService->sendToChannel('#website-nl', $message, $attachments);
     foreach ($this->unmatched as $unmatched) {
         $attachment = new Attachment();
         $attachment->setFallback(sprintf('This dojo resulted in multiple internal possibilities: %s (zen: $s)', $unmatched->getName(), $unmatched->getZenId()));
         $attachment->setText('A dojo resulted in multiple internal possibilities');
         $attachment->setColor('danger');
         $nameField = new AttachmentField();
         $nameField->setTitle('Name');
         $nameField->setValue($unmatched->getName());
         $nameField->setShort(true);
         $cityField = new AttachmentField();
         $cityField->setTitle('City');
         $cityField->setValue($unmatched->getCity());
         $cityField->setShort(true);
         $zenIdField = new AttachmentField();
         $zenIdField->setTitle('Zen ID');
         $zenIdField->setValue($unmatched->getZenId());
         $zenIdField->setShort(true);
         $zenUrlField = new AttachmentField();
         $zenUrlField->setTitle('Zen Url');
         $zenUrlField->setValue($unmatched->getZenUrl());
         $zenUrlField->setShort(true);
         $attachment->addField($nameField);
         $attachment->addField($cityField);
         $attachment->addField($zenIdField);
         $attachment->addField($zenUrlField);
         $this->slackService->sendToChannel('#website-nl', 'We couldn\'t match this dojo internally.', [$attachment]);
     }
 }
 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);
 }