/**
  *
  * Allows to ajax all Announcements
  *
  */
 public function removeajaxAction($notif)
 {
     $dm = $this->get('doctrine_mongodb')->getManager();
     $notifications = $dm->getRepository("BackBundle:Notifications")->find($notif);
     $dm = $this->get('doctrine_mongodb')->getManager();
     $dm->remove($notifications);
     $dm->flush();
     $redis = new \Redis();
     $redis->connect('127.0.0.1', '6379');
     $emitter = new Emitter($redis);
     // Emit a notification on channel 'notification'
     $emitter->emit('announcement', ['action' => 'remove']);
     return new JsonResponse(array(true));
 }
Пример #2
0
 public function afterUpdate($event, $news)
 {
     if (!$news->id) {
         return;
     }
     $config = $news->getDI()->getConfig();
     $newsString = '';
     if ($config->livenews->broadcastEnable) {
         $emitter = new Emitter(array('host' => $config->livenews->socketIoRedis->host, 'port' => $config->livenews->socketIoRedis->port));
         $newsString = json_encode($news->dump(NewsManager::$simpleDump));
         $emitter->emit('livenews:update', $newsString);
     }
     if (true === in_array($news->status, array('published', 'deleted')) && $config->livenews->realtimeCacheEnable) {
         $newsString = $newsString ?: json_encode($news->dump(NewsManager::$simpleDump));
         $redis = $news->getDI()->getFastCache();
         $redis->zAdd('livenews', (int) $news->updatedAt, $newsString);
     }
 }
Пример #3
0
 public function testPublishKeyNameWithNamespaceAndRoomSet()
 {
     $p = new Process('redis-cli monitor > redis.log');
     sleep(1);
     // Running this should produce something that's visible in `redis-cli monitor`
     $emitter = new Emitter(NULL, array('host' => '127.0.0.1', 'port' => '6379'));
     $emitter->of('/nsp')->to('rm')->emit('yolo', 'data');
     $p->stop();
     $contents = file_get_contents('redis.log');
     unlink('redis.log');
     $this->assertTrue(strpos($contents, 'socket.io#/nsp#rm#') !== FALSE);
 }
Пример #4
0
 /**
  * Flush in notification
  */
 protected function flushNotification(Announcement $entity, $title = "Nouvelle Action", $criticity = "success")
 {
     $notification = $this->dm->getRepository('BackBundle:Notifications')->findOneByAid($entity->getId());
     if (!$notification) {
         $notification = new Notifications();
     }
     $notification->setAid($entity->getId());
     $notification->setTitle($title);
     $notification->setObject($entity->getTitle());
     $notification->setCriticity($criticity);
     $notification->setAuthor($entity->getUser());
     $this->dm->persist($notification);
     $this->dm->flush();
     $redis = new \Redis();
     $redis->connect('127.0.0.1', '6379');
     $emitter = new Emitter($redis);
     $now = new \DateTime('now');
     $emitter->emit('notification', ['title' => $title, 'date' => $now->format('Y-m-d H:i:s'), 'author' => $entity->getUser()->getPseudo(), 'objet' => $entity->getTitle(), 'criticity' => $criticity]);
 }