/** * * 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)); }
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); } }
public function testPublishContainsExpectedDataWhenEmittingBinaryWithWrapper() { $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')); $binarydata = pack('CCCCC', 0, 1, 2, 3, 4); $emitter->emit('binary event', new SocketIO\Binary($binarydata)); $p->stop(); $contents = file_get_contents('redis.log'); unlink('redis.log'); $this->assertTrue(strpos($contents, '\\x00\\x01\\x02\\x03\\x04') !== FALSE); }
/** * 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]); }