/** * Updates properties of current session content. * * @param ConnectionInterface $from * @param MessageHandlerContext $context * @param array $msg * * @return array * * @throws PreviewNotStartedException * @throws MissingParameterException */ private function update(ConnectionInterface $from, MessageHandlerContext $context, $msg) { // check context parameters if (!$context->has('content') && !$context->has('locale') && !$context->has('webspaceKey') && !$context->has('user')) { throw new PreviewNotStartedException(); } // get user id $user = $context->get('user'); // get session vars $contentUuid = $context->get('content'); $locale = $context->get('locale'); $webspaceKey = $context->get('webspaceKey'); // init msg vars if (!array_key_exists('data', $msg) && is_array($msg['data'])) { throw new MissingParameterException('data'); } $changes = $msg['data']; $this->requestAnalyzer->setWebspaceKey($webspaceKey); $this->requestAnalyzer->setLocalizationCode($locale); foreach ($changes as $property => $data) { // update property $this->preview->updateProperty($user, $contentUuid, $webspaceKey, $locale, $property, $data); } return ['command' => 'update', 'content' => $contentUuid, 'data' => $this->preview->getChanges($user, $contentUuid, $webspaceKey, $locale)]; }
/** * Start preview with given parameters. * * @param MessageHandlerContext $context * @param array $message * * @return array */ private function start(MessageHandlerContext $context, $message) { if ($context->has('previewToken') && $this->preview->exists($context->get('previewToken'))) { $this->preview->stop($context->get('previewToken')); } $token = $this->preview->start($message['class'], $message['id'], $message['user'], $message['webspaceKey'], $message['locale'], $message['data'] ?: []); $response = $this->preview->render($token, $message['webspaceKey'], $message['locale']); $context->set('previewToken', $token); $context->set('locale', $message['locale']); return ['command' => 'start', 'token' => $token, 'response' => $response, 'msg' => 'OK']; }