Skip to content
Snippets Groups Projects
Commit f3d12943 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

slim down variables in JSUpdater::coreInformation() and it's used method, fixes #4383

Closes #4383

Merge request studip/studip!3193
parent f03e67bc
No related branches found
No related tags found
No related merge requests found
...@@ -60,8 +60,7 @@ class JsupdaterController extends AuthenticatedController ...@@ -60,8 +60,7 @@ class JsupdaterController extends AuthenticatedController
$data = UpdateInformation::getInformation(); $data = UpdateInformation::getInformation();
$data = array_merge($data, $this->coreInformation()); $data = array_merge($data, $this->coreInformation());
$this->set_content_type('application/json;charset=utf-8'); $this->render_json($data);
$this->render_text(json_encode($data));
} }
/** /**
...@@ -111,15 +110,15 @@ class JsupdaterController extends AuthenticatedController ...@@ -111,15 +110,15 @@ class JsupdaterController extends AuthenticatedController
*/ */
protected function coreInformation() protected function coreInformation()
{ {
$pageInfo = Request::getArray("page_info"); $pageInfo = Request::getArray('page_info');
$data = [ $data = [
'coursewareclipboard' => $this->getCoursewareClipboardUpdates($pageInfo), 'coursewareclipboard' => $this->getCoursewareClipboardUpdates($pageInfo['coursewareclipboard'] ?? null),
'blubber' => $this->getBlubberUpdates($pageInfo), 'blubber' => $this->getBlubberUpdates($pageInfo['blubber'] ?? null),
'messages' => $this->getMessagesUpdates($pageInfo), 'messages' => $this->getMessagesUpdates($pageInfo['messages'] ?? null),
'personalnotifications' => $this->getPersonalNotificationUpdates($pageInfo), 'personalnotifications' => $this->getPersonalNotificationUpdates(),
'questionnaire' => $this->getQuestionnaireUpdates($pageInfo), 'questionnaire' => $this->getQuestionnaireUpdates($pageInfo['questionnaire'] ?? null),
'wiki_page_content' => $this->getWikiPageContents($pageInfo), 'wiki_page_content' => $this->getWikiPageContents($pageInfo['wiki_page_content'] ?? null),
'wiki_editor_status' => $this->getWikiEditorStatus($pageInfo), 'wiki_editor_status' => $this->getWikiEditorStatus($pageInfo['wiki_editor_status'] ?? null),
]; ];
return array_filter($data); return array_filter($data);
...@@ -128,9 +127,9 @@ class JsupdaterController extends AuthenticatedController ...@@ -128,9 +127,9 @@ class JsupdaterController extends AuthenticatedController
private function getBlubberUpdates($pageInfo) private function getBlubberUpdates($pageInfo)
{ {
$data = []; $data = [];
if (isset($pageInfo['blubber']['threads']) && is_array($pageInfo['blubber']['threads'])) { if (isset($pageInfo['threads']) && is_array($pageInfo['threads'])) {
$blubber_data = []; $blubber_data = [];
foreach ($pageInfo['blubber']['threads'] as $thread_id) { foreach ($pageInfo['threads'] as $thread_id) {
$thread = new BlubberThread($thread_id); $thread = new BlubberThread($thread_id);
if ($thread->isReadable()) { if ($thread->isReadable()) {
$comments = BlubberComment::findBySQL( $comments = BlubberComment::findBySQL(
...@@ -150,7 +149,7 @@ class JsupdaterController extends AuthenticatedController ...@@ -150,7 +149,7 @@ class JsupdaterController extends AuthenticatedController
FROM blubber_events_queue FROM blubber_events_queue
WHERE blubber_events_queue.event_type = 'delete' WHERE blubber_events_queue.event_type = 'delete'
"); ");
$statement->execute([$pageInfo['blubber']['threads']]); $statement->execute([$pageInfo['threads']]);
$comment_ids = $statement->fetchAll(PDO::FETCH_COLUMN, 0); $comment_ids = $statement->fetchAll(PDO::FETCH_COLUMN, 0);
if (count($comment_ids)) { if (count($comment_ids)) {
$data['removeDeletedComments'] = $comment_ids; $data['removeDeletedComments'] = $comment_ids;
...@@ -190,15 +189,15 @@ class JsupdaterController extends AuthenticatedController ...@@ -190,15 +189,15 @@ class JsupdaterController extends AuthenticatedController
if (mb_stripos(Request::get("page"), "dispatch.php/messages") !== false) { if (mb_stripos(Request::get("page"), "dispatch.php/messages") !== false) {
$messages = Message::findNew( $messages = Message::findNew(
$GLOBALS["user"]->id, $GLOBALS["user"]->id,
$pageInfo['messages']['received'], $pageInfo['received'],
$pageInfo['messages']['since'], $pageInfo['since'],
$pageInfo['messages']['tag'] $pageInfo['tag']
); );
$templateFactory = $this->get_template_factory(); $templateFactory = $this->get_template_factory();
foreach ($messages as $message) { foreach ($messages as $message) {
$attributes = [ $attributes = [
'message' => $message, 'message' => $message,
'received' => $pageInfo['messages']['received'], 'received' => $pageInfo['received'],
'controller' => $this, 'controller' => $this,
]; ];
$html = $templateFactory->open("messages/_message_row.php") $html = $templateFactory->open("messages/_message_row.php")
...@@ -213,32 +212,29 @@ class JsupdaterController extends AuthenticatedController ...@@ -213,32 +212,29 @@ class JsupdaterController extends AuthenticatedController
/** /**
* @SuppressWarnings(UnusedFormalParameter) * @SuppressWarnings(UnusedFormalParameter)
*/ */
private function getPersonalNotificationUpdates($pageInfo) private function getPersonalNotificationUpdates()
{ {
$data = []; $data = [];
if (PersonalNotifications::isActivated()) { if (PersonalNotifications::isActivated()) {
$notifications = PersonalNotifications::getMyNotifications(); $data['notifications'] = array_map(
if ($notifications && count($notifications)) { function ($notification) {
$ret = [];
foreach ($notifications as $notification) {
$info = $notification->toArray(); $info = $notification->toArray();
$info['html'] = $notification->getLiElement(); $info['html'] = $notification->getLiElement();
$ret[] = $info; return $info;
} },
$data['notifications'] = $ret; PersonalNotifications::getMyNotifications()
} else { );
$data['notifications'] = [];
}
} }
return $data; return array_filter($data);
} }
private function getQuestionnaireUpdates($pageInfo) private function getQuestionnaireUpdates($pageInfo)
{ {
if ( if (
!isset($pageInfo['questionnaire']['questionnaire_ids']) !isset($pageInfo['questionnaire_ids'])
|| !is_array($pageInfo['questionnaire']['questionnaire_ids']) || !is_array($pageInfo['questionnaire_ids'])
) { ) {
return []; return [];
} }
...@@ -246,17 +242,17 @@ class JsupdaterController extends AuthenticatedController ...@@ -246,17 +242,17 @@ class JsupdaterController extends AuthenticatedController
$data = []; $data = [];
Questionnaire::findEachMany( Questionnaire::findEachMany(
function (Questionnaire $questionnaire) use ($pageInfo, &$data) { function (Questionnaire $questionnaire) use ($pageInfo, &$data) {
if ($questionnaire->latestAnswerTimestamp() > $pageInfo['questionnaire']['last_update']) { if ($questionnaire->latestAnswerTimestamp() > $pageInfo['last_update']) {
$template = $this->get_template_factory()->open('questionnaire/evaluate'); $template = $this->get_template_factory()->open('questionnaire/evaluate');
$template->questionnaire = $questionnaire; $template->questionnaire = $questionnaire;
$template->filtered = $pageInfo['questionnaire']['filtered'] ?? []; $template->filtered = $pageInfo['filtered'] ?? [];
$template->set_layout(null); $template->set_layout(null);
$data[$questionnaire->id] = [ $data[$questionnaire->id] = [
'html' => $template->render() 'html' => $template->render()
]; ];
} }
}, },
$pageInfo['questionnaire']['questionnaire_ids'] $pageInfo['questionnaire_ids']
); );
return $data; return $data;
...@@ -265,8 +261,8 @@ class JsupdaterController extends AuthenticatedController ...@@ -265,8 +261,8 @@ class JsupdaterController extends AuthenticatedController
private function getWikiPageContents($pageInfo): array private function getWikiPageContents($pageInfo): array
{ {
$data = []; $data = [];
if (!empty($pageInfo['wiki_page_content'])) { if (!empty($pageInfo)) {
foreach ($pageInfo['wiki_page_content'] as $page_id) { foreach ($pageInfo as $page_id) {
$page = WikiPage::find($page_id); $page = WikiPage::find($page_id);
if ($page && $page->isReadable() && ($page->chdate >= Request::int('server_timestamp'))) { if ($page && $page->isReadable() && ($page->chdate >= Request::int('server_timestamp'))) {
$data['contents'][$page_id] = wikiReady($page->content, true, $page->range_id, $page->id); $data['contents'][$page_id] = wikiReady($page->content, true, $page->range_id, $page->id);
...@@ -279,9 +275,9 @@ class JsupdaterController extends AuthenticatedController ...@@ -279,9 +275,9 @@ class JsupdaterController extends AuthenticatedController
private function getWikiEditorStatus($pageInfo): array private function getWikiEditorStatus($pageInfo): array
{ {
$data = []; $data = [];
if (!empty($pageInfo['wiki_editor_status']['page_ids'])) { if (!empty($pageInfo['page_ids'])) {
$user = User::findCurrent(); $user = User::findCurrent();
foreach ((array) $pageInfo['wiki_editor_status']['page_ids'] as $page_id) { foreach ((array) $pageInfo['page_ids'] as $page_id) {
WikiOnlineEditingUser::deleteBySQL( WikiOnlineEditingUser::deleteBySQL(
"`page_id` = :page_id AND `chdate` < UNIX_TIMESTAMP() - :threshold", "`page_id` = :page_id AND `chdate` < UNIX_TIMESTAMP() - :threshold",
[ [
...@@ -293,11 +289,11 @@ class JsupdaterController extends AuthenticatedController ...@@ -293,11 +289,11 @@ class JsupdaterController extends AuthenticatedController
if ($page) { if ($page) {
if ($page->isEditable()) { if ($page->isEditable()) {
if ( if (
$pageInfo['wiki_editor_status']['focussed'] == $page_id $pageInfo['focussed'] == $page_id
&& !empty($pageInfo['wiki_editor_status']['page_content']) && !empty($pageInfo['page_content'])
) { ) {
$page->content = \Studip\Markup::markAsHtml( $page->content = \Studip\Markup::markAsHtml(
$pageInfo['wiki_editor_status']['page_content'] $pageInfo['page_content']
); );
if ($page->isDirty()) { if ($page->isDirty()) {
$page['user_id'] = User::findCurrent()->id; $page['user_id'] = User::findCurrent()->id;
...@@ -334,7 +330,7 @@ class JsupdaterController extends AuthenticatedController ...@@ -334,7 +330,7 @@ class JsupdaterController extends AuthenticatedController
$online->editing = 1; $online->editing = 1;
} }
} else { } else {
if ($pageInfo['wiki_editor_status']['focussed'] == $page_id) { if ($pageInfo['focussed'] == $page_id) {
$online->editing = 1; $online->editing = 1;
} else { } else {
$other_users = WikiOnlineEditingUser::countBySql("`page_id` = ? AND `user_id` != ?", [ $other_users = WikiOnlineEditingUser::countBySql("`page_id` = ? AND `user_id` != ?", [
...@@ -368,7 +364,11 @@ class JsupdaterController extends AuthenticatedController ...@@ -368,7 +364,11 @@ class JsupdaterController extends AuthenticatedController
private function getCoursewareClipboardUpdates($pageInfo) private function getCoursewareClipboardUpdates($pageInfo)
{ {
$counter = $pageInfo['coursewareclipboard']['counter'] ?? 0; if (!isset($pageInfo['counter'])) {
return null;
}
$counter = $pageInfo['counter'] ?? 0;
return \Courseware\Clipboard::countByUser_id($GLOBALS['user']->id) != $counter; return \Courseware\Clipboard::countByUser_id($GLOBALS['user']->id) != $counter;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment