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;
 }
 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]);
 }
Exemple #3
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;
 }
 /**
  * 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));
 }
 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 = [];
 }
 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');
 }
 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');
 }