/** * @param Notice $notice * * @return JsonResponse */ public function closeAction(Notice $notice) { // mark as closed $notice->setStatus(Notice::STATUS_CLOSED); $em = $this->getDoctrine()->getManager(); $em->persist($notice); $em->flush(); return new JsonResponse([]); }
/** * @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'); } }
/** * @param int $status * @param string $type * * @return QueryBuilder */ public function getFilteredQuery($status, $type) { $query = $this->createQueryBuilder('n'); if (is_int($status) && in_array($status, NoticeEntity::getStatuses())) { $query->where('n.status = :status')->setParameter('status', $status); } if ($type) { $query->andWhere('n.type = :type')->setParameter('type', $type); } return $query; }
/** * @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); }
/** * @dataProvider getStatuses * * @param int $status */ public function testStatus($status) { $this->assertEquals(Notice::STATUS_CREATED, $this->notice->getStatus()); $this->assertEquals($this->notice, $this->notice->setStatus($status)); $this->assertEquals($status, $this->notice->getStatus()); }
/** * @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(); } } }