From 443e106105b7d4ff9b97d21491a3d0eb89aa9dfe Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 01:02:53 +0100 Subject: [PATCH] Fix missing notifications: - Add namecache in enotify - Add "unset()" in notify repository for additional field "abort" - Add possibility for additional, non-saved fields in model --- include/enotify.php | 1 + src/BaseModel.php | 18 ++++++++++++++++-- src/Model/Notify.php | 25 +++++++++++++++++++++++++ src/Repository/Notify.php | 2 ++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/include/enotify.php b/include/enotify.php index 3332f4a082..b35d5507cc 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -484,6 +484,7 @@ function notification($params) if ($show_in_notification_page) { $notification = DI::notify()->insert([ 'name' => $params['source_name'], + 'name_cache' => strip_tags(BBCode::convert($params['source_name'])), 'url' => $params['source_link'], 'photo' => $params['source_photo'], 'uid' => $params['uid'], diff --git a/src/BaseModel.php b/src/BaseModel.php index 4e42591708..791d6887c1 100644 --- a/src/BaseModel.php +++ b/src/BaseModel.php @@ -48,9 +48,23 @@ abstract class BaseModel $this->originalData = $data; } + /** + * Maps a data array (original/current) to a known field list of the chosen model + * + * This is useful to filter out additional attributes, which aren't part of the db-table (like readonly cached fields) + * + * @param array $data The data array to map to db-fields + * + * @return array the mapped data array + */ + protected function mapFields(array $data) + { + return $data; + } + public function getOriginalData() { - return $this->originalData; + return $this->mapFields($this->originalData); } public function resetOriginalData() @@ -117,7 +131,7 @@ abstract class BaseModel public function toArray() { - return $this->data; + return $this->mapFields($this->data); } protected function checkValid() diff --git a/src/Model/Notify.php b/src/Model/Notify.php index 1bb9f29047..c48fa0f679 100644 --- a/src/Model/Notify.php +++ b/src/Model/Notify.php @@ -163,4 +163,29 @@ class Notify extends BaseModel return $message; } + + /** + * {@inheritDoc} + */ + protected function mapFields(array $data) + { + return [ + 'hash' => $data['hash'] ?? '', + 'type' => $data['type'] ?? 0, + 'name' => $data['name'] ?? '', + 'url' => $data['url'] ?? '', + 'photo' => $data['photo'] ?? '', + 'date' => $data['date'] ?? DateTimeFormat::utcNow(), + 'msg' => $data['msg'] ?? '', + 'uid' => $data['uid'] ?? 0, + 'link' => $data['link'] ?? '', + 'iid' => $data['iid'] ?? 0, + 'parent' => $data['parent'] ?? 0, + 'seen' => $data['seen'] ?? false, + 'verb' => $data['verb'] ?? '', + 'otype' => $data['otype'] ?? '', + 'name_cache' => $data['name_cache'] ?? null, + 'msg_cache' => $data['msg_cache'] ?? null, + ]; + } } diff --git a/src/Repository/Notify.php b/src/Repository/Notify.php index 2ac14858f5..5f2d9f8a7f 100644 --- a/src/Repository/Notify.php +++ b/src/Repository/Notify.php @@ -84,6 +84,8 @@ class Notify extends BaseRepository return null; } + unset($fields['abort']); + $this->logger->debug('adding notification entry', ['fields' => $fields]); return parent::insert($fields);