X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fenotify.php;h=becf672b2aaa4cddae79f208d963f9901c099990;hb=4810ca570fbaecc432c32497fcbd5b985c1da86d;hp=800158d9ae98df54b6687791e2c53ec0469b0b69;hpb=7f2dc4060119f49eaaefb01ce3f32907e4c7761d;p=friendica.git diff --git a/include/enotify.php b/include/enotify.php index 800158d9ae..becf672b2a 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -11,8 +11,8 @@ use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; -use Friendica\Model\Contact; use Friendica\Model\Item; +use Friendica\Model\User; use Friendica\Util\DateTimeFormat; use Friendica\Util\Emailer; use Friendica\Util\Strings; @@ -25,7 +25,7 @@ use Friendica\Util\Strings; * link, subject, body, to_name, to_email, source_name, * source_link, activity, preamble, notify_flags, * language, show_in_notification_page - * @return bool|object + * @return bool * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ function notification($params) @@ -33,8 +33,8 @@ function notification($params) $a = \get_app(); // Temporary logging for finding the origin - if (!isset($params['language']) || !isset($params['uid'])) { - Logger::log('Missing parameters.' . System::callstack()); + if (!isset($params['uid'])) { + Logger::notice('Missing parameters "uid".', ['params' => $params, 'callstack' => System::callstack()]); } // Ensure that the important fields are set at any time @@ -42,8 +42,8 @@ function notification($params) $user = DBA::selectFirst('user', $fields, ['uid' => $params['uid']]); if (!DBA::isResult($user)) { - Logger::log('Unknown user ' . $params['uid']); - return; + Logger::error('Unknown user', ['uid' => $params['uid']]); + return false; } $params['notify_flags'] = defaults($params, 'notify_flags', $user['notify-flags']); @@ -79,7 +79,7 @@ function notification($params) // There is no need to create notifications for forum accounts if (!DBA::isResult($user) || in_array($user["page-flags"], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP])) { - return; + return false; } $nickname = $user["nickname"]; } else { @@ -146,7 +146,7 @@ function notification($params) if (DBA::isResult($thread) && $thread['ignored']) { Logger::log('Thread ' . $parent_id . ' will be ignored', Logger::DEBUG); L10n::popLang(); - return; + return false; } // Check to see if there was already a tag notify or comment notify for this post. @@ -155,7 +155,7 @@ function notification($params) 'link' => $params['link'], 'uid' => $params['uid']]; if (DBA::exists('notify', $condition)) { L10n::popLang(); - return; + return false; } // if it's a post figure out who's post it is. @@ -453,11 +453,20 @@ function notification($params) // It will be used by the system to send emails to users (like // password reset, invitations and so) using one look (but without // add a notification to the user, with could be inexistent) - $subject = $params['subject']; + if (!isset($params['subject'])) { + Logger::warning('subject isn\'t set.', ['type' => $params['type']]); + } + $subject = defaults($params, 'subject', ''); - $preamble = $params['preamble']; + if (!isset($params['preamble'])) { + Logger::warning('preamble isn\'t set.', ['type' => $params['type'], 'subject' => $subject]); + } + $preamble = defaults($params, 'preamble', ''); - $body = $params['body']; + if (!isset($params['body'])) { + Logger::warning('body isn\'t set.', ['type' => $params['type'], 'subject' => $subject, 'preamble' => $preamble]); + } + $body = defaults($params, 'body', ''); $show_in_notification_page = false; } @@ -522,7 +531,7 @@ function notification($params) if ($datarray['abort']) { L10n::popLang(); - return False; + return false; } // create notification entry in DB @@ -671,8 +680,7 @@ function notification($params) L10n::popLang(); // use the Emailer class to send the message - return Emailer::send( - [ + return Emailer::send([ 'uid' => $params['uid'], 'fromName' => $sender_name, 'fromEmail' => $sender_email, @@ -681,8 +689,8 @@ function notification($params) 'messageSubject' => $datarray['subject'], 'htmlVersion' => $email_html_body, 'textVersion' => $email_text_body, - 'additionalMailHeader' => $datarray['headers']] - ); + 'additionalMailHeader' => $datarray['headers'] + ]); } L10n::popLang(); @@ -776,9 +784,9 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { 'author-link', 'author-name', 'author-avatar', 'author-id', 'guid', 'parent-uri', 'uri', 'contact-id', 'network']; $condition = ['id' => $itemid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]; - $item = Item::selectFirst($fields, $condition); + $item = Item::selectFirstForUser($uid, $fields, $condition); if (!DBA::isResult($item) || in_array($item['author-id'], $contacts)) { - return; + return false; } // Generate the notification array