コード例 #1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return bool
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $root = $this->getContainer()->getParameter('kernel.root_dir') . '/../';
     $time = filemtime($root . 'composer.json');
     if (file_exists($root . 'composer.lock')) {
         $time = max($time, filemtime($root . 'composer.lock'));
     }
     // need update
     if ($time + self::INERVAL_UPDATE < time()) {
         $output->writeln('Application must be updated');
         // send notice
         $notice = new Notice();
         $notice->setMessage($this->getContainer()->get('templating')->render('AnimeDbAppBundle:Notice:propose_update.html.twig'));
         $em = $this->getContainer()->get('doctrine.orm.entity_manager');
         $em->persist($notice);
         $em->flush();
         touch($root . 'composer.json', time() + self::INERVAL_NOTIFICATION - self::INERVAL_UPDATE);
     } else {
         $output->writeln('Application is already updated');
     }
 }
コード例 #2
0
 /**
  * @param string $type
  * @param array $params
  */
 protected function sendNotice($type, array $params)
 {
     $notice = new Notice();
     $notice->setType($type);
     $notice->setMessage($this->templating->render('AnimeDbCatalogBundle:Notice:messages/' . $type . '.html.twig', $params));
     $this->em->persist($notice);
 }
コード例 #3
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postUpdate(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof ItemCatalog && $this->sync_update) {
         /* @var $rep ItemRepository */
         $rep = $args->getEntityManager()->getRepository('AnimeDbMyAnimeListSyncBundle:Item');
         /* @var $mal_item ItemCatalog */
         $mal_item = $rep->findByCatalogItem($entity);
         if ($mal_item instanceof ItemMal) {
             $this->client->sendAction(Client::ACTION_UPDATE, $mal_item->getId(), $this->renderEntry($entity));
         } elseif ($id = $this->getId($entity, $args->getEntityManager())) {
             $this->client->sendAction(Client::ACTION_ADD, $id, $this->renderEntry($entity));
         } else {
             $notice = new Notice();
             $notice->setMessage($this->templating->render('AnimeDbMyAnimeListSyncBundle:Notice:failed_update.html.twig', ['item' => $entity]));
             $args->getEntityManager()->persist($notice);
             $args->getEntityManager()->flush();
         }
     }
 }