]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/Notifier.php
Fixed E_NOTICE in boot.php and DBA class (#5430)
[friendica.git] / src / Worker / Notifier.php
index 6ad6827f7c8d980ecd469a9eb9fd071cb56e8cae..efdccb6b1f4c2fded64d47a588bb0c7497fa8364 100644 (file)
@@ -4,20 +4,21 @@
  */
 namespace Friendica\Worker;
 
+use Friendica\BaseObject;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
+use Friendica\Database\DBA;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
-use Friendica\Model\User;
+use Friendica\Model\Item;
 use Friendica\Model\PushSubscriber;
+use Friendica\Model\User;
 use Friendica\Network\Probe;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\Salmon;
-use Friendica\Worker\Delivery;
-use dba;
 
 require_once 'include/dba.php';
 require_once 'include/items.php';
@@ -47,9 +48,11 @@ require_once 'include/items.php';
  * and ITEM_ID is the id of the item in the database that needs to be sent to others.
  */
 
-class Notifier {
-       public static function execute($cmd, $item_id) {
-               global $a;
+class Notifier
+{
+       public static function execute($cmd, $item_id)
+       {
+               $a = BaseObject::getApp();
 
                logger('notifier: invoked: '.$cmd.': '.$item_id, LOGGER_DEBUG);
 
@@ -62,7 +65,7 @@ class Notifier {
 
                if ($cmd == Delivery::MAIL) {
                        $normal_mode = false;
-                       $message = dba::selectFirst('mail', ['uid', 'contact-id'], ['id' => $item_id]);
+                       $message = DBA::selectFirst('mail', ['uid', 'contact-id'], ['id' => $item_id]);
                        if (!DBM::is_result($message)) {
                                return;
                        }
@@ -70,7 +73,7 @@ class Notifier {
                        $recipients[] = $message['contact-id'];
                } elseif ($cmd == Delivery::SUGGESTION) {
                        $normal_mode = false;
-                       $suggest = dba::selectFirst('fsuggest', ['uid', 'cid'], ['id' => $item_id]);
+                       $suggest = DBA::selectFirst('fsuggest', ['uid', 'cid'], ['id' => $item_id]);
                        if (!DBM::is_result($suggest)) {
                                return;
                        }
@@ -104,27 +107,27 @@ class Notifier {
                                                intval($uid), NETWORK_DFRN, NETWORK_DIASPORA);
                } else {
                        // find ancestors
-                       $target_item = dba::fetch_first("SELECT `item`.*, `contact`.`uid` AS `cuid` FROM `item`
-                                               INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
-                                               WHERE `item`.`id` = ? AND `visible` AND NOT `moderated`", $item_id);
+                       $condition = ['id' => $item_id, 'visible' => true, 'moderated' => false];
+                       $target_item = Item::selectFirst([], $condition);
 
                        if (!DBM::is_result($target_item) || !intval($target_item['parent'])) {
                                return;
                        }
 
                        $parent_id = intval($target_item['parent']);
-                       $uid = $target_item['cuid'];
+                       $uid = $target_item['contact-uid'];
                        $updated = $target_item['edited'];
 
-                       $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
-                               FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d AND visible AND NOT moderated ORDER BY `id` ASC",
-                               intval($parent_id)
-                       );
+                       $condition = ['parent' => $parent_id, 'visible' => true, 'moderated' => false];
+                       $params = ['order' => ['id']];
+                       $ret = Item::select([], $condition, $params);
 
-                       if (!count($items)) {
+                       if (!DBM::is_result($ret)) {
                                return;
                        }
 
+                       $items = Item::inArray($ret);
+
                        // avoid race condition with deleting entries
                        if ($items[0]['deleted']) {
                                foreach ($items as $item) {
@@ -166,7 +169,7 @@ class Notifier {
 
                        $fields = ['network', 'author-id', 'owner-id'];
                        $condition = ['uri' => $target_item["thr-parent"], 'uid' => $target_item["uid"]];
-                       $thr_parent = dba::selectFirst('item', $fields, $condition);
+                       $thr_parent = Item::selectFirst($fields, $condition);
 
                        logger('GUID: '.$target_item["guid"].': Parent is '.$parent['network'].'. Thread parent is '.$thr_parent['network'], LOGGER_DEBUG);
 
@@ -220,7 +223,7 @@ class Notifier {
 
                                $fields = ['forum', 'prv'];
                                $condition = ['id' => $target_item['contact-id']];
-                               $contact = dba::selectFirst('contact', $fields, $condition);
+                               $contact = DBA::selectFirst('contact', $fields, $condition);
                                if (!DBM::is_result($contact)) {
                                        // Should never happen
                                        return false;
@@ -340,14 +343,14 @@ class Notifier {
                                logger('Some parent is OStatus for '.$target_item["guid"]." - Author: ".$thr_parent['author-id']." - Owner: ".$thr_parent['owner-id'], LOGGER_DEBUG);
 
                                // Send a salmon to the parent author
-                               $probed_contact = dba::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['author-id']]);
+                               $probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['author-id']]);
                                if (DBM::is_result($probed_contact) && !empty($probed_contact["notify"])) {
                                        logger('Notify parent author '.$probed_contact["url"].': '.$probed_contact["notify"]);
                                        $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
                                }
 
                                // Send a salmon to the parent owner
-                               $probed_contact = dba::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['owner-id']]);
+                               $probed_contact = DBA::selectFirst('contact', ['url', 'notify'], ['id' => $thr_parent['owner-id']]);
                                if (DBM::is_result($probed_contact) && !empty($probed_contact["notify"])) {
                                        logger('Notify parent owner '.$probed_contact["url"].': '.$probed_contact["notify"]);
                                        $url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
@@ -377,7 +380,7 @@ class Notifier {
                }
 
                // If this is a public message and pubmail is set on the parent, include all your email contacts
-               if (function_exists('imap_open') && !Config::get('system','imap_disabled')) {
+               if (!empty($target_item) && function_exists('imap_open') && !Config::get('system','imap_disabled')) {
                        if (!strlen($target_item['allow_cid']) && !strlen($target_item['allow_gid'])
                                && !strlen($target_item['deny_cid']) && !strlen($target_item['deny_gid'])
                                && intval($target_item['pubmail'])) {
@@ -404,14 +407,14 @@ class Notifier {
                        if (!empty($networks)) {
                                $condition['network'] = $networks;
                        }
-                       $contacts = dba::select('contact', ['id', 'url', 'network'], $condition);
-                       $r = dba::inArray($contacts);
+                       $contacts = DBA::select('contact', ['id', 'url', 'network'], $condition);
+                       $r = DBA::inArray($contacts);
                }
 
                // delivery loop
                if (DBM::is_result($r)) {
                        foreach ($r as $contact) {
-                               logger("Deliver ".$target_item["guid"]." to ".$contact['url']." via network ".$contact['network'], LOGGER_DEBUG);
+                               logger("Deliver ".$item_id." to ".$contact['url']." via network ".$contact['network'], LOGGER_DEBUG);
 
                                Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
                                                'Delivery', $cmd, $item_id, (int)$contact['id']);
@@ -455,7 +458,7 @@ class Notifier {
 
                        $condition = ['network' => NETWORK_DFRN, 'uid' => $owner['uid'], 'blocked' => false,
                                'pending' => false, 'archive' => false, 'rel' => [CONTACT_IS_FOLLOWER, CONTACT_IS_FRIEND]];
-                       $r2 = dba::inArray(dba::select('contact', ['id', 'name', 'network'], $condition));
+                       $r2 = DBA::inArray(DBA::select('contact', ['id', 'name', 'network'], $condition));
 
                        $r = array_merge($r2, $r1);