From 443e106105b7d4ff9b97d21491a3d0eb89aa9dfe Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 01:02:53 +0100 Subject: [PATCH 01/10] 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 3332f4a08..b35d5507c 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 4e4259170..791d6887c 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 1bb9f2904..c48fa0f67 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 2ac14858f..5f2d9f8a7 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); From ff9eb206631e706c3b7d0b0f8a331c663d98ef9a Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 01:12:11 +0100 Subject: [PATCH 02/10] Fix enotify item link --- include/enotify.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/enotify.php b/include/enotify.php index b35d5507c..a1dbf77b6 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -483,24 +483,24 @@ function notification($params) if ($show_in_notification_page) { $notification = DI::notify()->insert([ - 'name' => $params['source_name'], + 'name' => $params['source_name'], 'name_cache' => strip_tags(BBCode::convert($params['source_name'])), - 'url' => $params['source_link'], - 'photo' => $params['source_photo'], - 'uid' => $params['uid'], - 'iid' => $item_id, - 'parent' => $parent_id, - 'type' => $params['type'], - 'verb' => $params['verb'], - 'otype' => $params['otype'], + 'url' => $params['source_link'], + 'photo' => $params['source_photo'], + 'link' => $itemlink, + 'uid' => $params['uid'], + 'iid' => $item_id, + 'parent' => $parent_id, + 'type' => $params['type'], + 'verb' => $params['verb'], + 'otype' => $params['otype'], ]); - $notification->link = DI::baseUrl() . '/notification/view/' . $notification->id; - $notification->msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $notification->link]); + $notification->msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $notification->link]); DI::notify()->update($notification); - $itemlink = $notification->link; + $itemlink = DI::baseUrl() . '/notification/view/' . $notification->id; $notify_id = $notification->id; } From 52a401012195c5cc4bfb4d39b0dda5732c1d5643 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 01:12:41 +0100 Subject: [PATCH 03/10] enotify: empty out fields instead of using "abort" for addons --- src/Repository/Notify.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Repository/Notify.php b/src/Repository/Notify.php index 5f2d9f8a7..9552eddb9 100644 --- a/src/Repository/Notify.php +++ b/src/Repository/Notify.php @@ -67,7 +67,7 @@ class Notify extends BaseRepository /** * @param array $fields * - * @return Model\Notify + * @return Model\Notify|false * * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws Exception @@ -75,17 +75,14 @@ class Notify extends BaseRepository public function insert(array $fields) { $fields['date'] = DateTimeFormat::utcNow(); - $fields['abort'] = false; Hook::callAll('enotify_store', $fields); - if ($fields['abort']) { + if (empty($fields)) { $this->logger->debug('Abort adding notification entry', ['fields' => $fields]); - return null; + return false; } - unset($fields['abort']); - $this->logger->debug('adding notification entry', ['fields' => $fields]); return parent::insert($fields); From 8f130335a3dad57e06efff3b179435ae3b1e8642 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 01:15:21 +0100 Subject: [PATCH 04/10] remove now empty array from logger --- src/Repository/Notify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repository/Notify.php b/src/Repository/Notify.php index 9552eddb9..ba00d26fa 100644 --- a/src/Repository/Notify.php +++ b/src/Repository/Notify.php @@ -79,7 +79,7 @@ class Notify extends BaseRepository Hook::callAll('enotify_store', $fields); if (empty($fields)) { - $this->logger->debug('Abort adding notification entry', ['fields' => $fields]); + $this->logger->debug('Abort adding notification entry'); return false; } From 4a3544582c570d43f7d274ddbae7ea835176cbd9 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 01:33:29 +0100 Subject: [PATCH 05/10] Add parameter for "toArray()" method --- src/BaseModel.php | 11 +++++++++-- src/BaseRepository.php | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/BaseModel.php b/src/BaseModel.php index 791d6887c..decc62752 100644 --- a/src/BaseModel.php +++ b/src/BaseModel.php @@ -129,9 +129,16 @@ abstract class BaseModel $this->data[$name] = $value; } - public function toArray() + /** + * Returns the values of the current model as an array + * + * @param bool $dbOnly True, if just the db-relevant fields should be returned + * + * @return array The values of the current model + */ + public function toArray(bool $dbOnly = false) { - return $this->mapFields($this->data); + return $dbOnly ? $this->mapFields($this->data) : $this->data; } protected function checkValid() diff --git a/src/BaseRepository.php b/src/BaseRepository.php index cce1c50c1..c14d6f7bc 100644 --- a/src/BaseRepository.php +++ b/src/BaseRepository.php @@ -122,7 +122,7 @@ abstract class BaseRepository extends BaseFactory */ public function update(BaseModel $model) { - if ($this->dba->update(static::$table_name, $model->toArray(), ['id' => $model->id], $model->getOriginalData())) { + if ($this->dba->update(static::$table_name, $model->toArray(true), ['id' => $model->id], $model->getOriginalData())) { $model->resetOriginalData(); return true; } From 582f6bd4a35a864d9425b7c912121346deebdc4b Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 21:28:57 +0100 Subject: [PATCH 06/10] Refactor API notification usage - Remove "mapFields()" from BaseModel - Add new Notification API entity (including collection) - Add new NotificationFactory method "getApiList()" --- include/api.php | 7 +- src/BaseCollection.php | 10 +-- src/BaseEntity.php | 15 +++++ src/BaseModel.php | 29 ++------- src/Collection/Api/Notifications.php | 17 +++++ src/DI.php | 16 ++--- src/Factory/Notification/Notification.php | 24 +++++++ src/Model/Notify.php | 76 +++------------------- src/Object/Api/Friendica/Notification.php | 79 +++++++++++++++++++++++ 9 files changed, 164 insertions(+), 109 deletions(-) create mode 100644 src/Collection/Api/Notifications.php create mode 100644 src/Object/Api/Friendica/Notification.php diff --git a/include/api.php b/include/api.php index a69bd01b4..3f4d5625b 100644 --- a/include/api.php +++ b/include/api.php @@ -5892,10 +5892,11 @@ api_register_func('api/friendica/activity/unattendmaybe', 'api_friendica_activit * Returns notifications * * @param string $type Known types are 'atom', 'rss', 'xml' and 'json' + * * @return string|array - * @throws BadRequestException * @throws ForbiddenException - * @throws InternalServerErrorException + * @throws BadRequestException + * @throws Exception */ function api_friendica_notification($type) { @@ -5908,7 +5909,7 @@ function api_friendica_notification($type) throw new BadRequestException("Invalid argument count"); } - $notifications = DI::notify()->select(['uid' => api_user()], ['order' => ['seen' => 'ASC', 'date' => 'DESC'], 'limit' => 50]); + $notifications = DI::notification()->getApiList(local_user()); if ($type == "xml") { $xmlnotes = false; diff --git a/src/BaseCollection.php b/src/BaseCollection.php index 5a20acee7..9a9efdb06 100644 --- a/src/BaseCollection.php +++ b/src/BaseCollection.php @@ -17,14 +17,14 @@ abstract class BaseCollection extends \ArrayIterator protected $totalCount = 0; /** - * @param BaseModel[] $models - * @param int|null $totalCount + * @param BaseEntity[] $entities + * @param int|null $totalCount */ - public function __construct(array $models = [], int $totalCount = null) + public function __construct(array $entities = [], int $totalCount = null) { - parent::__construct($models); + parent::__construct($entities); - $this->totalCount = $totalCount ?? count($models); + $this->totalCount = $totalCount ?? count($entities); } /** diff --git a/src/BaseEntity.php b/src/BaseEntity.php index 9f0cb31f8..14f95c197 100644 --- a/src/BaseEntity.php +++ b/src/BaseEntity.php @@ -11,7 +11,22 @@ namespace Friendica; */ abstract class BaseEntity implements \JsonSerializable { + /** + * Returns the current entity as an json array + * + * @return array + */ public function jsonSerialize() + { + return $this->toArray(); + } + + /** + * Returns the current entity as an array + * + * @return array + */ + public function toArray() { return get_object_vars($this); } diff --git a/src/BaseModel.php b/src/BaseModel.php index decc62752..2c952888b 100644 --- a/src/BaseModel.php +++ b/src/BaseModel.php @@ -12,7 +12,7 @@ use Psr\Log\LoggerInterface; * * @property int id */ -abstract class BaseModel +abstract class BaseModel extends BaseEntity { /** @var Database */ protected $dba; @@ -48,23 +48,9 @@ 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->mapFields($this->originalData); + return $this->originalData; } public function resetOriginalData() @@ -129,16 +115,9 @@ abstract class BaseModel $this->data[$name] = $value; } - /** - * Returns the values of the current model as an array - * - * @param bool $dbOnly True, if just the db-relevant fields should be returned - * - * @return array The values of the current model - */ - public function toArray(bool $dbOnly = false) + public function toArray() { - return $dbOnly ? $this->mapFields($this->data) : $this->data; + return $this->data; } protected function checkValid() diff --git a/src/Collection/Api/Notifications.php b/src/Collection/Api/Notifications.php new file mode 100644 index 000000000..5bd8983ce --- /dev/null +++ b/src/Collection/Api/Notifications.php @@ -0,0 +1,17 @@ +create(Model\User\Cookie::class); } - /** - * @return Repository\Notify - */ - public static function notify() - { - return self::$dice->create(Repository\Notify::class); - } - /** * @return Model\Storage\IStorage */ @@ -324,6 +316,14 @@ abstract class DI return self::$dice->create(Repository\ProfileField::class); } + /** + * @return Repository\Notify + */ + public static function notify() + { + return self::$dice->create(Repository\Notify::class); + } + // // "Protocol" namespace instances // diff --git a/src/Factory/Notification/Notification.php b/src/Factory/Notification/Notification.php index 5f2c2231b..2b179cca5 100644 --- a/src/Factory/Notification/Notification.php +++ b/src/Factory/Notification/Notification.php @@ -6,6 +6,7 @@ use Exception; use Friendica\App; use Friendica\App\BaseURL; use Friendica\BaseFactory; +use Friendica\Collection\Api\Notifications as ApiNotifications; use Friendica\Content\Text\BBCode; use Friendica\Core\L10n; use Friendica\Core\PConfig\IPConfig; @@ -15,6 +16,7 @@ use Friendica\Database\Database; use Friendica\Model\Item; use Friendica\Module\BaseNotifications; use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Object\Api\Friendica\Notification as ApiNotification; use Friendica\Protocol\Activity; use Friendica\Repository; use Friendica\Util\DateTimeFormat; @@ -352,4 +354,26 @@ class Notification extends BaseFactory return $formattedNotifications; } + + /** + * @param int $uid The user id of the API call + * @param array $params Additional parameters + * + * @return ApiNotifications + * + * @throws Exception + */ + public function getApiList(int $uid, array $params = ['order' => ['seen' => 'ASC', 'date' => 'DESC'], 'limit' => 50]) + { + $notifies = $this->notification->select(['uid' => $uid], $params); + + /** @var ApiNotification[] $notifications */ + $notifications = []; + + foreach ($notifies as $notify) { + $notifications[] = new ApiNotification($notify); + } + + return new ApiNotifications($notifications); + } } diff --git a/src/Model/Notify.php b/src/Model/Notify.php index c48fa0f67..b12eb341b 100644 --- a/src/Model/Notify.php +++ b/src/Model/Notify.php @@ -5,19 +5,12 @@ namespace Friendica\Model; use Exception; use Friendica\BaseModel; use Friendica\Content\Text\BBCode; -use Friendica\Content\Text\HTML; use Friendica\Database\Database; use Friendica\Network\HTTPException\InternalServerErrorException; -use Friendica\Util\DateTimeFormat; -use Friendica\Util\Temporal; use Psr\Log\LoggerInterface; /** * Model for an entry in the notify table - * - Including additional, calculated properties - * - * Is used either for frontend interactions or for API-based interaction - * @see https://github.com/friendica/friendica/blob/develop/doc/API-Entities.md#notification * * @property string hash * @property integer type @@ -36,11 +29,6 @@ use Psr\Log\LoggerInterface; * * @property-read string name_cache Full name of the contact subject * @property-read string msg_cache Plaintext version of the notification text with a placeholder (`{0}`) for the subject contact's name. - * - * @property-read integer timestamp Unix timestamp - * @property-read string dateRel Time since the note was posted, eg "1 hour ago" - * @property-read string $msg_html - * @property-read string $msg_plain */ class Notify extends BaseModel { @@ -59,8 +47,7 @@ class Notify extends BaseModel $this->repo = $repo; $this->setNameCache(); - $this->setTimestamp(); - $this->setMsg(); + $this->setMsgCache(); } /** @@ -81,41 +68,23 @@ class Notify extends BaseModel } } - /** - * Set some extra properties to the notification from db: - * - timestamp as int in default TZ - * - date_rel : relative date string - */ - private function setTimestamp() - { - try { - $this->timestamp = strtotime(DateTimeFormat::local($this->date)); - } catch (Exception $e) { - } - $this->dateRel = Temporal::getRelativeDate($this->date); - } - /** * Sets the pre-formatted name (caching) - * - * @throws InternalServerErrorException */ private function setNameCache() { - $this->name_cache = strip_tags(BBCode::convert($this->source_name ?? '')); + try { + $this->name_cache = strip_tags(BBCode::convert($this->source_name ?? '')); + } catch (InternalServerErrorException $e) { + } } /** - * Set some extra properties to the notification from db: - * - msg_html: message as html string - * - msg_plain: message as plain text string - * - msg_cache: The pre-formatted message (caching) + * Sets the pre-formatted msg (caching) */ - private function setMsg() + private function setMsgCache() { try { - $this->msg_html = BBCode::convert($this->msg, false); - $this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0]; $this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convert($this->msg))); } catch (InternalServerErrorException $e) { } @@ -125,12 +94,8 @@ class Notify extends BaseModel { parent::__set($name, $value); - if ($name == 'date') { - $this->setTimestamp(); - } - if ($name == 'msg') { - $this->setMsg(); + $this->setMsgCache(); } if ($name == 'source_name') { @@ -163,29 +128,4 @@ 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/Object/Api/Friendica/Notification.php b/src/Object/Api/Friendica/Notification.php new file mode 100644 index 000000000..910d5ec68 --- /dev/null +++ b/src/Object/Api/Friendica/Notification.php @@ -0,0 +1,79 @@ +toArray() as $key => $value) { + $this->{$key} = $value; + } + + // add additional attributes for the API + try { + $this->timestamp = strtotime(DateTimeFormat::local($this->date)); + $this->msg_html = BBCode::convert($this->msg, false); + $this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0]; + } catch (\Exception $e) { + } + + $this->date_rel = Temporal::getRelativeDate($this->date); + } +} From 5ccf41a56fd41de9024ca1443714b991001f447c Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 22:00:21 +0100 Subject: [PATCH 07/10] Add API test case for notification --- src/Repository/Notify.php | 2 -- tests/datasets/api.fixture.php | 19 +++++++++++++++++++ tests/include/ApiTest.php | 27 ++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/Repository/Notify.php b/src/Repository/Notify.php index ba00d26fa..8c71fc289 100644 --- a/src/Repository/Notify.php +++ b/src/Repository/Notify.php @@ -37,8 +37,6 @@ class Notify extends BaseRepository { $params['order'] = $params['order'] ?? ['date' => 'DESC']; - $condition = array_merge($condition, ['uid' => local_user()]); - return parent::select($condition, $params); } diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 475fa0385..44501d049 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -189,6 +189,25 @@ return [ 'origin' => 1, ], ], + 'notify' => [ + [ + 'id' => 1, + 'type' => 8, + 'name' => 'Reply to', + 'url' => 'http://localhost/display/1', + 'photo' => 'http://localhost/', + 'date' => '2020-01-01 12:12:02', + 'msg' => 'A test reply from an item', + 'uid' => 42, + 'link' => 'http://localhost/notification/1', + 'iid' => 4, + 'seen' => 0, + 'verb' => '', + 'otype' => 'item', + 'name_cache' => 'Reply to', + 'msg_cache' => 'A test reply from an item', + ], + ], 'thread' => [ [ 'iid' => 1, diff --git a/tests/include/ApiTest.php b/tests/include/ApiTest.php index 466248f65..3ef64b317 100644 --- a/tests/include/ApiTest.php +++ b/tests/include/ApiTest.php @@ -14,6 +14,7 @@ use Friendica\Core\Session; use Friendica\Core\Session\ISession; use Friendica\Core\System; use Friendica\Database\Database; +use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Network\HTTPException; @@ -3916,14 +3917,15 @@ class ApiTest extends DatabaseTest } /** - * Test the api_friendica_notification() function with an argument count. + * Test the api_friendica_notification() function with empty result * * @return void */ - public function testApiFriendicaNotificationWithArgumentCount() + public function testApiFriendicaNotificationWithEmptyResult() { $this->app->argv = ['api', 'friendica', 'notification']; $this->app->argc = count($this->app->argv); + $_SESSION['uid'] = 41; $result = api_friendica_notification('json'); $this->assertEquals(['note' => false], $result); } @@ -3938,7 +3940,26 @@ class ApiTest extends DatabaseTest $this->app->argv = ['api', 'friendica', 'notification']; $this->app->argc = count($this->app->argv); $result = api_friendica_notification('xml'); - $this->assertXml($result, 'notes'); + $assertXml=<< + + + +XML; + $this->assertXmlStringEqualsXmlString($assertXml, $result); + } + + /** + * Test the api_friendica_notification() function with an JSON result. + * + * @return void + */ + public function testApiFriendicaNotificationWithJsonResult() + { + $this->app->argv = ['api', 'friendica', 'notification']; + $this->app->argc = count($this->app->argv); + $result = json_encode(api_friendica_notification('json')); + $this->assertJson($result); } /** From d23008c2f5b400f8e19fa5e326b9160600d46614 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 22:01:42 +0100 Subject: [PATCH 08/10] remove false parameter --- src/BaseRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BaseRepository.php b/src/BaseRepository.php index c14d6f7bc..cce1c50c1 100644 --- a/src/BaseRepository.php +++ b/src/BaseRepository.php @@ -122,7 +122,7 @@ abstract class BaseRepository extends BaseFactory */ public function update(BaseModel $model) { - if ($this->dba->update(static::$table_name, $model->toArray(true), ['id' => $model->id], $model->getOriginalData())) { + if ($this->dba->update(static::$table_name, $model->toArray(), ['id' => $model->id], $model->getOriginalData())) { $model->resetOriginalData(); return true; } From 2b433e0ea6c1310a6ec56a3bcee2b3a695b7cd85 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 22:06:59 +0100 Subject: [PATCH 09/10] fix https://github.com/friendica/friendica/issues/8187 --- src/Object/Notification/Introduction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Object/Notification/Introduction.php b/src/Object/Notification/Introduction.php index 19fda4c15..475728273 100644 --- a/src/Object/Notification/Introduction.php +++ b/src/Object/Notification/Introduction.php @@ -262,7 +262,7 @@ class Introduction implements \JsonSerializable { $this->label = $data['label'] ?? ''; $this->type = $data['str_type'] ?? ''; - $this->intro_id = $data['$intro_id'] ?? -1; + $this->intro_id = $data['intro_id'] ?? -1; $this->madeBy = $data['madeBy'] ?? ''; $this->madeByUrl = $data['madeByUrl'] ?? ''; $this->madeByZrl = $data['madeByZrl'] ?? ''; From 91707a530c52e550d2320ff00f02efaaffc15853 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 28 Jan 2020 22:26:23 +0100 Subject: [PATCH 10/10] Add default values for inserts --- include/enotify.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/enotify.php b/include/enotify.php index a1dbf77b6..7567613b4 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -483,17 +483,17 @@ 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'], - 'link' => $itemlink, - 'uid' => $params['uid'], - 'iid' => $item_id, - 'parent' => $parent_id, - 'type' => $params['type'], - 'verb' => $params['verb'], - 'otype' => $params['otype'], + 'name' => $params['source_name'] ?? '', + 'name_cache' => strip_tags(BBCode::convert($params['source_name'] ?? '')), + 'url' => $params['source_link'] ?? '', + 'photo' => $params['source_photo'] ?? '', + 'link' => $itemlink ?? '', + 'uid' => $params['uid'] ?? 0, + 'iid' => $item_id ?? 0, + 'parent' => $parent_id ?? 0, + 'type' => $params['type'] ?? '', + 'verb' => $params['verb'] ?? '', + 'otype' => $params['otype'] ?? '', ]); $notification->msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $notification->link]);