/**
* 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)];
}