示例#1
0
 /**
  * @return AMQPChannel
  */
 public function getChannel()
 {
     if (empty($this->ch)) {
         $this->ch = $this->conn->channel();
     }
     return $this->ch;
 }
示例#2
0
 protected function process()
 {
     $v = $this->getValues();
     $video = $this->presenter->video;
     $mode = 'edited';
     if (!$video) {
         $video = new Rme\Video();
         $video->author = $this->presenter->userEntity;
         $this->orm->contents->attach($video);
         $mode = 'added';
     }
     $old = $this->orm->contents->getVideoByYoutubeId($v->youtubeId);
     if ($old && ($mode === 'added' || $old->id !== $video->id)) {
         /** @var self|BaseControl[] $this */
         $this['youtubeId']->addError('Toto youtubeId už v databázi existuje.');
         return FALSE;
     }
     $video->title = $v->title;
     $video->description = $v->description;
     $video->youtubeId = $v->youtubeId;
     $video->hidden = !$v->visible;
     $this->orm->flush();
     $producer = $this->queue->getProducer('updateVideo');
     $producer->publish(serialize(['video' => new EntityPointer($video)]));
     $this->presenter->flashSuccess("editor.{$mode}.video");
     $block = $this->presenter->block;
     $schema = $this->presenter->schema;
     $this->presenter->redirect('Video:default', ['videoId' => $video->id, 'blockId' => $block ? $block->id : NULL, 'schemaId' => $schema ? $schema->id : NULL]);
     return TRUE;
 }
示例#3
0
 /**
  * @param InputInterface $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @throws \InvalidArgumentException When the number of messages to consume is less than 0
  * @throws \BadFunctionCallException When the pcntl is not installed and option -s is true
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     if (defined('AMQP_WITHOUT_SIGNALS') === false) {
         define('AMQP_WITHOUT_SIGNALS', $input->getOption('without-signals'));
     }
     if (!AMQP_WITHOUT_SIGNALS && extension_loaded('pcntl')) {
         if (!function_exists('pcntl_signal')) {
             throw new \BadFunctionCallException("Function 'pcntl_signal' is referenced in the php.ini 'disable_functions' and can't be called.");
         }
         pcntl_signal(SIGTERM, [$this, 'signalTerm']);
         pcntl_signal(SIGINT, [$this, 'signalInt']);
         pcntl_signal(SIGHUP, [$this, 'signalHup']);
     }
     if (defined('AMQP_DEBUG') === false) {
         define('AMQP_DEBUG', (bool) $input->getOption('debug'));
     }
     if (($this->amount = $input->getOption('messages')) < 0) {
         throw new \InvalidArgumentException("The -m option should be null or greater than 0");
     }
     $this->consumer = $this->connection->getConsumer($input->getArgument('name'));
     if (!is_null($input->getOption('memory-limit')) && ctype_digit((string) $input->getOption('memory-limit')) && $input->getOption('memory-limit') > 0) {
         $this->consumer->setMemoryLimit($input->getOption('memory-limit'));
     }
     if ($routingKey = $input->getOption('route')) {
         $this->consumer->setRoutingKey($routingKey);
     }
 }
 public function onUpload(Form $form)
 {
     /** @var UploadControl[] $form */
     /** @var FileUpload $json */
     /** @var FileUpload $audio */
     $json = $form['json']->getValue();
     $audio = $form['audio']->getValue();
     $data = Json::decode($json->getContents(), Json::FORCE_ARRAY);
     $blackboard = new Rme\Blackboard();
     $this->orm->contents->attach($blackboard);
     $blackboard->title = 'Nová nahrávka';
     $blackboard->description = ' ';
     $blackboard->hidden = TRUE;
     $blackboard->duration = $data['duration'];
     $blackboard->preview = 'https://placehold.it/480x320&text=...';
     $blackboard->author = $this->userEntity;
     $this->orm->flush();
     $base = $this->paths->getBlackboards() . "/{$blackboard->id}";
     $json->move("{$base}.json");
     $audio->move("{$base}.wav");
     $producer = $this->queue->getProducer('blackboardPreview');
     $producer->publish(serialize(['blackboard' => new EntityPointer($blackboard)]));
     $link = $this->link('BlackboardEditor:default', ['blackboardId' => $blackboard->id]);
     $this->sendJson(['redirect' => $link]);
 }
示例#5
0
 public function __construct(\Kdyby\RabbitMq\Connection $bunny, \Trejjam\Emailing\EmailFactory $emailFactory, \Trejjam\Emailing\ImapFactory $imapFactory, \Trejjam\Emailing\Senders $senders)
 {
     $this->bunny = $bunny;
     $this->rabbitMailer = $this->bunny->getProducer('mailer');
     $this->rabbitImap = $this->bunny->getProducer('imap');
     $this->emailFactory = $emailFactory;
     $this->imapFactory = $imapFactory;
     $this->senders = $senders;
 }
示例#6
0
 /**
  * Executes the current command.
  *
  * @param InputInterface $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return integer 0 if everything went fine, or an error code
  *
  * @throws \InvalidArgumentException When the number of messages to consume is less than 0
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     define('AMQP_DEBUG', (bool) $input->getOption('debug'));
     if (($amount = $input->getOption('messages')) < 0) {
         throw new \InvalidArgumentException("The -m option should be null or greater than 0");
     }
     $rpcServer = $this->connection->getRpcServer($input->getArgument('name'));
     $rpcServer->start($amount);
 }
 /**
  * @param InputInterface $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @throws \InvalidArgumentException When the number of messages to consume is less than 0
  * @throws \BadFunctionCallException When the pcntl is not installed and option -s is true
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     if (defined('AMQP_WITHOUT_SIGNALS') === false) {
         define('AMQP_WITHOUT_SIGNALS', $input->getOption('without-signals'));
     }
     if (defined('AMQP_DEBUG') === false) {
         define('AMQP_DEBUG', (bool) $input->getOption('debug'));
     }
     if (($this->amount = $input->getOption('messages')) < 0) {
         throw new \InvalidArgumentException("The -m option should be null or greater than 0");
     }
     $name = $input->getArgument('name');
     try {
         $this->consumer = $this->connection->getConsumer($name);
     } catch (InvalidArgumentException $e) {
         $names = implode(', ', $this->connection->getDefinedConsumers());
         throw new InvalidArgumentException("Unknown consumer {$name}, expecting one of [{$names}]\nIf you added or renamed a consumer, run 'rabbitmq:setup-fabric'");
     }
     if (!is_null($input->getOption('memory-limit')) && ctype_digit((string) $input->getOption('memory-limit')) && $input->getOption('memory-limit') > 0) {
         $this->consumer->setMemoryLimit($input->getOption('memory-limit'));
     }
     if ($routingKey = $input->getOption('route')) {
         $this->consumer->setRoutingKey($routingKey);
     }
     if (!AMQP_WITHOUT_SIGNALS && extension_loaded('pcntl')) {
         if (!function_exists('pcntl_signal')) {
             throw new \BadFunctionCallException("Function 'pcntl_signal' is referenced in the php.ini 'disable_functions' and can't be called.");
         }
         $this->consumer->onConsume[] = function () {
             pcntl_signal(SIGTERM, function () {
                 if ($this->consumer) {
                     pcntl_signal(SIGTERM, SIG_DFL);
                     $this->consumer->forceStopConsumer();
                 }
             });
             pcntl_signal(SIGINT, function () {
                 if ($this->consumer) {
                     pcntl_signal(SIGINT, SIG_DFL);
                     $this->consumer->forceStopConsumer();
                 }
             });
             pcntl_signal(SIGHUP, function () {
                 if ($this->consumer) {
                     pcntl_signal(SIGHUP, SIG_DFL);
                     $this->consumer->forceStopConsumer();
                 }
                 // TODO: Implement restarting of consumer
             });
         };
         $this->consumer->onConsumeStop[] = function () {
             pcntl_signal(SIGTERM, SIG_DFL);
             pcntl_signal(SIGINT, SIG_DFL);
             pcntl_signal(SIGHUP, SIG_DFL);
         };
     }
 }
 /**
  * @param string $name
  * @return array
  */
 private function getQueueOptions($name) : array
 {
     /** @var Kdyby\RabbitMq\MultipleConsumer $consumer */
     $consumer = $this->rabbit->getConsumer($name);
     if ($consumer instanceof Kdyby\RabbitMq\MultipleConsumer) {
         return $consumer->getQueues();
     }
     return [$consumer->getQueueOptions()];
 }
示例#9
0
 /**
  * Executes the current command.
  *
  * @param InputInterface $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return integer 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     define('AMQP_DEBUG', (bool) $input->getOption('debug'));
     $producer = $this->connection->getProducer($input->getArgument('name'));
     $data = '';
     while (!feof(STDIN)) {
         $data .= fread(STDIN, 8192);
     }
     $producer->publish(serialize($data));
 }
示例#10
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $noConfirmation = (bool) $input->getOption('no-confirmation');
     if (!$noConfirmation && $input->isInteractive()) {
         $confirmation = $this->getHelper('dialog')->askConfirmation($output, sprintf('<question>Are you sure you wish to purge "%s" queue? (y/n)</question>', $input->getArgument('name')), false);
         if (!$confirmation) {
             $output->writeln('<error>Purging cancelled!</error>');
             return 1;
         }
     }
     /** @var Consumer $consumer */
     $consumer = $this->connection->getConsumer($input->getArgument('name'));
     $consumer->purge();
     return 0;
 }
 public function flushSync()
 {
     if ($this->exchangeName === NULL) {
         throw new InvalidStateException('Exchange name is not defined');
     }
     if (!array_filter($this->dirtyEntities)) {
         return;
     }
     $producer = $this->rabbitmq->getProducer($this->exchangeName);
     foreach ($this->dirtyEntities as $type => $entities) {
         foreach ($entities as $id => $data) {
             $producer->publish($this->prepare($type, $id, $data));
         }
     }
     $this->dirtyEntities = [];
 }
示例#12
0
 public function onLogin(User $user, $newUser = FALSE, $service = NULL)
 {
     $this->user->setExpiration('5 years', FALSE);
     $this->flashSuccess('auth.flash.login.' . ($newUser ? 'newUser' : 'returning'), ['name' => $user->firstName]);
     $this->trigger(EventList::LOGIN, [$user]);
     $this->orm->flush();
     if (!$this->userEntity->avatar) {
         $producer = $this->queue->getProducer('updateAvatar');
         $producer->publish(serialize(['user' => new EntityPointer($this->userEntity)]));
     }
     $this->iLog("auth.login.{$service}");
     $section = $this->session->getSection('auth');
     $section->lastUser = ['email' => $user->email, 'avatar' => $user->avatar];
     if ($key = $section->loginBacklink) {
         unset($section->loginBacklink);
         $this->restoreRequest($key);
     }
     $this->redirect('Profile:');
 }
 public function onSuccess()
 {
     $v = $this->getValues();
     /** @var Auth $presenter */
     $presenter = $this->presenter;
     $userEntity = $this->orm->users->getByEmail($v->email);
     if (!$userEntity || !$userEntity->registered) {
         $this->iLog('form.resetPassword.fail', ['email' => $v->email]);
         $this->presenter->flashError('/auth.reset.notFound');
         $this->addError('/auth.reset.notFound.title');
         return;
     }
     $token = Tokens\ResetPassword::createFromUser($userEntity);
     $this->orm->tokens->persist($token);
     $this->orm->flush();
     // prevent race condition with queue
     $producer = $this->queue->getProducer('mail');
     $producer->publish(serialize(['template' => 'resetPassword', 'recipient' => new EntityPointer($userEntity), 'token' => new EntityPointer($token), 'unsafe' => $token->getUnsafe()]));
     $this->iLog('form.resetPassword.ok', ['email' => $v->email]);
     $presenter->flashSuccess('auth.reset.success');
     $presenter->redirect('this');
 }
示例#14
0
 protected function process()
 {
     $v = $this->getValues();
     $parsed = Json::decode($v->layout);
     $parsed = $this->schemaLayout->normalize($parsed);
     $schema = $this->presenter->schema;
     $mode = 'edited';
     if (!$schema) {
         $schema = new Rme\Schema();
         $this->orm->schemas->attach($schema);
         $schema->author = $this->presenter->userEntity;
         $schema->blockSchemaBridges = [];
         $mode = 'added';
     }
     /** @var self|EditorSelector[] $this */
     if ($this['editors']->isEditable()) {
         $schema->editors = $v->editors;
     }
     $schema->title = $v->title;
     $schema->description = $v->description;
     $schema->layout = $parsed;
     foreach ($schema->blocks as $block) {
         $block->dependencies = [];
     }
     foreach ($this->schemaLayout->buildBlockDependencies($parsed) as $blockId => $deps) {
         /** @var Rme\Block $block */
         $block = $this->orm->blocks->getById($blockId);
         $block->dependencies = $deps;
     }
     $this->orm->flush();
     $this->presenter->purgeCacheTag('header');
     $this->presenter->purgeCacheTag("schema-{$schema->id}");
     $producer = $this->queue->getProducer('updateSchema');
     $producer->publish(serialize(['schema' => new EntityPointer($schema)]));
     $this->presenter->flashSuccess("editor.{$mode}.schema");
     $this->presenter->redirect('this', ['schemaId' => $schema->id]);
 }
 /**
  * @param User $teacher
  * @param string $email
  * @throws \Exception
  */
 protected function inviteUser(User $teacher, $email)
 {
     $student = $this->getOrCreateUser($email);
     if ($student->registered) {
         $token = LinkExistingStudent::createFromUser($student);
         $template = 'mentor.linkStudent.existing';
     } else {
         $token = LinkNewStudent::createFromUser($student);
         $template = 'mentor.linkStudent.new';
     }
     $invite = new StudentInvite($teacher, $student);
     $token->studentInvite = $invite;
     $this->orm->tokens->persist($token);
     $this->orm->flush();
     // prevent race condition with queue
     $teacher->studentInvitesSent->add($invite);
     $producer = $this->queue->getProducer('mail');
     $producer->publish(serialize(['template' => $template, 'recipient' => new EntityPointer($student), 'teacher' => new EntityPointer($teacher), 'token' => new EntityPointer($token), 'unsafe' => $token->getUnsafe()]));
 }
 public function append(Order $order, $retryCounter = 0, array $options = [])
 {
     $message = ['orderId' => $order->getId(), 'retryCounter' => $retryCounter, 'options' => $options];
     $this->rabbit->getProducer('submitOrder')->publish(Json::encode($message), $this->getQueue());
 }
 public function publish($to, $from, $body, $highPriority = FALSE)
 {
     $msg = ['to' => $to, 'from' => $from, 'body' => $body];
     $this->rabbit->getProducer('emails')->publish(json_encode($msg), $highPriority ? 'emails.high' : 'emails.low');
 }