/** * @param bool $isOn */ protected function onMode($isOn) { $userId = $this->securityFacade->getLoggedUserId(); try { $this->publisher->send('oro/maintenance', array('isOn' => (bool) $isOn, 'userId' => $userId)); } catch (\Exception $e) { $this->logger->error($e->getMessage()); } }
/** * Send message into topic * * @param array $usersWithNewEmails */ public function send($usersWithNewEmails) { if ($usersWithNewEmails) { foreach ($usersWithNewEmails as $item) { /** @var EmailUser $emailUser */ $emailUser = $item['entity']; $messageData = ['hasNewEmail' => array_key_exists('new', $item) === true && $item['new'] > 0 ?: false]; $this->publisher->send(self::getUserTopic($emailUser->getOwner(), $emailUser->getOrganization()), json_encode($messageData)); } } }
/** * Send payload into topic * * @param array $tags */ public function send(array $tags) { /** @var SecurityContextInterface $securityContext */ $securityContext = $this->securityContextLink->getService(); $userName = $securityContext->getToken() && is_object($securityContext->getToken()->getUser()) ? $securityContext->getToken()->getUser()->getUserName() : null; if (!empty($tags)) { $tags = array_map(function ($tag) use($userName) { return ['username' => $userName, 'tagname' => $tag]; }, $tags); $this->publisher->send(self::UPDATE_TOPIC, json_encode($tags)); } }
public function testSend() { $user = $this->getMockForAbstractClass('Symfony\\Component\\Security\\Core\\User\\UserInterface'); $user->expects($this->any())->method('getUserName')->will($this->returnValue(self::TEST_USERNAME)); $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $token->expects($this->any())->method('getUser')->will($this->returnValue($user)); $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token)); $that = $this; $this->publisher->expects($this->once())->method('send')->will($this->returnCallback(function ($topic, $payload) use($that) { $that->assertSame('oro/data/update', $topic, 'Should be the same as frontend code expects'); $tags = json_decode($payload, true); $that->assertCount(2, $tags); foreach ($tags as $tag) { $that->assertArrayHasKey('username', $tag); $that->assertArrayHasKey('tagname', $tag); $that->assertSame(self::TEST_USERNAME, $tag['username']); } })); $tags = [self::TEST_TAG1, self::TEST_TAG2]; $this->sender->send($tags); }
public function onModeOff() { $this->publisher->send('oro/maintenance', array('isOn' => false, 'msg' => 'Maintenance mode is OFF')); }
/** * @param array $messageData * @param int $recipientId * @return bool */ protected function sendMessage(array $messageData, $recipientId) { return $this->topicPublisher->send(sprintf('oro/reminder/remind_user_%s', $recipientId), json_encode($messageData)); }
public function onModeOff() { $userId = $this->securityFacade->getLoggedUserId(); $this->publisher->send('oro/maintenance', array('isOn' => false, 'userId' => $userId)); }
/** * Check WebSocket server connection * * @return bool True on success, false otherwise */ public function checkWsConnected() { return $this->publisher->check(); }