validate($request); if (!$entry = ForumEntry::find($args['id'])) { throw new RecordNotFoundException('Entry has not been found.'); } if (!$course = \Course::find($entry->seminar_id)) { throw new RecordNotFoundException('Course does not exist.'); } if (!ForumAuthority::has($this->getUser($request), 'view', $course)) { throw new AuthorizationFailedException(); } if (!$entry = $this->updateEntryFromJSON($entry, $json)) { throw new InternalServerError('Could not update the entry.'); } return $this->getContentResponse($entry); } protected function updateEntryFromJSON($entry, $json) { $title = self::arrayGet($json, 'data.attributes.title'); $content = self::arrayGet($json, 'data.attributes.content'); if (!empty($title)) { $entry->name = $title; } if (!empty($content)) { $content = \Studip\Markup::purifyHtml($content); $entry->content = $content; } if ($entry->isDirty()) { $entry->store(); } return $entry; } protected function validateResourceDocument($json, $data) { $title = self::arrayGet($json, 'data.attributes.title'); $content = self::arrayGet($json, 'data.attributes.content'); if (empty($title) && empty($content)) { return 'You must change entry-data to update.'; } } }