From 392bb7d5aa75e4549584ce618d8dbb8a9a6764db Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 Jun 2018 06:20:47 +0000 Subject: [PATCH 1/5] Remove direct item sql queries --- .../advancedcontentfilter.php | 2 +- mailstream/mailstream.php | 6 +- pumpio/pumpio.php | 61 -------- statusnet/statusnet.php | 137 +---------------- twitter/twitter.php | 138 +----------------- windowsphonepush/windowsphonepush.php | 7 +- 6 files changed, 20 insertions(+), 331 deletions(-) diff --git a/advancedcontentfilter/advancedcontentfilter.php b/advancedcontentfilter/advancedcontentfilter.php index dd04e769..43946049 100644 --- a/advancedcontentfilter/advancedcontentfilter.php +++ b/advancedcontentfilter/advancedcontentfilter.php @@ -405,7 +405,7 @@ function advancedcontentfilter_get_variables_guid(ServerRequestInterface $reques $condition = ["`guid` = ? AND (`uid` = ? OR `uid` = 0)", $args['guid'], local_user()]; $params = ['order' => ['uid' => true]]; - $item = Item::selectFirst(local_user(), [], $condition, $params); + $item = Item::selectFirst(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params); if (!\Friendica\Database\DBM::is_result($item)) { throw new HTTPException\NotFoundException(L10n::t('Unknown post with guid: %s', $args['guid'])); diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 6c057b21..a68e0b36 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -13,6 +13,7 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Database\DBM; use Friendica\Util\Network; +use Friendica\Model\Item; function mailstream_install() { Addon::registerHook('addon_settings', 'addon/mailstream/mailstream.php', 'mailstream_addon_settings'); @@ -329,14 +330,13 @@ function mailstream_cron($a, $b) { // send the email itself before cron jumps in. Only if // mailstream_post_remote_hook fails for some reason will this get // used, and in that case it's worth holding off a bit anyway. - $ms_item_ids = q("SELECT `mailstream_item`.`message-id`, `mailstream_item`.`uri`, `item`.`id` FROM `mailstream_item` JOIN `item` ON (`mailstream_item`.`uid` = `item`.`uid` AND `mailstream_item`.`uri` = `item`.`uri` AND `mailstream_item`.`contact-id` = `item`.`contact-id`) WHERE `mailstream_item`.`completed` IS NULL AND `mailstream_item`.`created` < DATE_SUB(NOW(), INTERVAL 1 HOUR) AND `item`.`visible` = 1 ORDER BY `mailstream_item`.`created` LIMIT 100"); + $ms_item_ids = q("SELECT `mailstream_item`.`message-id`, `mailstream_item`.`uri`, `mailstream_item`.`uid`, `item`.`id` FROM `mailstream_item` JOIN `item` ON (`mailstream_item`.`uid` = `item`.`uid` AND `mailstream_item`.`uri` = `item`.`uri` AND `mailstream_item`.`contact-id` = `item`.`contact-id`) WHERE `mailstream_item`.`completed` IS NULL AND `mailstream_item`.`created` < DATE_SUB(NOW(), INTERVAL 1 HOUR) AND `item`.`visible` = 1 ORDER BY `mailstream_item`.`created` LIMIT 100"); logger('mailstream_cron processing ' . count($ms_item_ids) . ' items', LOGGER_DEBUG); foreach ($ms_item_ids as $ms_item_id) { if (!$ms_item_id['message-id'] || !strlen($ms_item_id['message-id'])) { logger('mailstream_cron: Item ' . $ms_item_id['id'] . ' URI ' . $ms_item_id['uri'] . ' has no message-id', LOGGER_NORMAL); } - $items = q('SELECT * FROM `item` WHERE `id` = %d', $ms_item_id['id']); - $item = $items[0]; + $item = Item::selectFirst($ms_item_id['uid'], Item::DISPLAY_FIELDLIST, ['id' => $ms_item_id['id']]); $users = q("SELECT * FROM `user` WHERE `uid` = %d", intval($item['uid'])); $user = $users[0]; if ($user && $item) { diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index cf659225..d57f1485 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -1217,14 +1217,6 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet DateTimeFormat::utc($post->object->created), $post->links->self->href). $postarray['body']."[/share]"; - - /* - $postarray['body'] = "[share author='".$share_author. - "' profile='".$post->object->author->url. - "' avatar='".$post->object->author->image->url. - "' posted='".DateTimeFormat::convert($post->object->created, 'UTC', 'UTC', ). - "' link='".$post->links->self->href."']".$postarray['body']."[/share]"; - */ } else { // Let shares look like wall-to-wall posts $postarray['author-name'] = $post->object->author->displayName; @@ -1249,59 +1241,6 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet if ($threadcompletion) pumpio_fetchallcomments($a, $uid, $postarray['parent-uri']); - - $user = q("SELECT * FROM `user` WHERE `uid` = %d AND `account_expired` = 0 LIMIT 1", - intval($uid) - ); - - if(!count($user)) - return $top_item; - - $importer_url = $a->get_baseurl() . '/profile/' . $user[0]['nickname']; - - if (link_compare($own_id, $postarray['author-link'])) - return $top_item; - - if (!function_exists("check_item_notification")) { - $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0", - dbesc($postarray['parent-uri']), - intval($uid) - ); - - if(count($myconv)) { - - foreach($myconv as $conv) { - // now if we find a match, it means we're in this conversation - - if(!link_compare($conv['author-link'],$importer_url) && !link_compare($conv['author-link'],$own_id)) - continue; - - require_once('include/enotify.php'); - - $conv_parent = $conv['parent']; - - notification([ - 'type' => NOTIFY_COMMENT, - 'notify_flags' => $user[0]['notify-flags'], - 'language' => $user[0]['language'], - 'to_name' => $user[0]['username'], - 'to_email' => $user[0]['email'], - 'uid' => $user[0]['uid'], - 'item' => $postarray, - 'link' => $a->get_baseurl().'/display/'.urlencode(Item::getGuidById($top_item)), - 'source_name' => $postarray['author-name'], - 'source_link' => $postarray['author-link'], - 'source_photo' => $postarray['author-avatar'], - 'verb' => ACTIVITY_POST, - 'otype' => 'item', - 'parent' => $conv_parent, - ]); - - // only send one notification - break; - } - } - } } return $top_item; diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index a297baeb..56639117 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -461,21 +461,15 @@ function statusnet_post_hook(App $a, &$b) return; } - $r = q("SELECT `item`.`author-link`, `item`.`uri`, `contact`.`nick` AS contact_nick - FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uri` = '%s' AND `item`.`uid` = %d LIMIT 1", dbesc($b["thr-parent"]), intval($b["uid"])); - - if (!count($r)) { + $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; + $orig_post = Item::selectFirst($b["uid"], ['author-link', 'uri'], $condition); + if (!count($orig_post)) { logger("statusnet_post_hook: no parent found " . $b["thr-parent"]); return; } else { $iscomment = true; - $orig_post = $r[0]; } - //$nickname = "@[url=".$orig_post["author-link"]."]".$orig_post["contact_nick"]."[/url]"; - //$nicknameplain = "@".$orig_post["contact_nick"]; - $nick = preg_replace("=https?://(.*)/(.*)=ism", "$2", $orig_post["author-link"]); $nickname = "@[url=" . $orig_post["author-link"] . "]" . $nick . "[/url]"; @@ -688,17 +682,9 @@ function statusnet_prepare_body(App $a, &$b) $item = $b["item"]; $item["plink"] = $a->get_baseurl() . "/display/" . $a->user["nickname"] . "/" . $item["parent"]; - $r = q("SELECT `item`.`author-link`, `item`.`uri`, `contact`.`nick` AS contact_nick - FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uri` = '%s' AND `item`.`uid` = %d LIMIT 1", - dbesc($item["thr-parent"]), - intval(local_user())); - - if (count($r)) { - $orig_post = $r[0]; - //$nickname = "@[url=".$orig_post["author-link"]."]".$orig_post["contact_nick"]."[/url]"; - //$nicknameplain = "@".$orig_post["contact_nick"]; - + $condition = ['uri' => $item["thr-parent"], 'uid' => local_user()]; + $orig_post = Item::selectFirst(local_user(), ['author-link', 'uri'], $condition); + if (count($orig_post)) { $nick = preg_replace("=https?://(.*)/(.*)=ism", "$2", $orig_post["author-link"]); $nickname = "@[url=" . $orig_post["author-link"] . "]" . $nick . "[/url]"; @@ -1214,75 +1200,6 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex return $postarray; } -function statusnet_checknotification(App $a, $uid, $own_url, $top_item, $postarray) -{ - // This function necer worked and need cleanup - $user = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", - intval($uid) - ); - - if (!count($user)) { - return; - } - - // Is it me? - if (link_compare($user[0]["url"], $postarray['author-link'])) { - return; - } - - $own_user = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", - intval($uid), - dbesc($own_url) - ); - - if (!count($own_user)) { - return; - } - - // Is it me from GNU Social? - if (link_compare($own_user[0]["url"], $postarray['author-link'])) { - return; - } - - $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0", - dbesc($postarray['parent-uri']), - intval($uid) - ); - - if (count($myconv)) { - foreach ($myconv as $conv) { - // now if we find a match, it means we're in this conversation - if (!link_compare($conv['author-link'], $user[0]["url"]) && !link_compare($conv['author-link'], $own_user[0]["url"])) { - continue; - } - - require_once 'include/enotify.php'; - - $conv_parent = $conv['parent']; - - notification([ - 'type' => NOTIFY_COMMENT, - 'notify_flags' => $user[0]['notify-flags'], - 'language' => $user[0]['language'], - 'to_name' => $user[0]['username'], - 'to_email' => $user[0]['email'], - 'uid' => $user[0]['uid'], - 'item' => $postarray, - 'link' => $a->get_baseurl() . '/display/' . urlencode(Item::getGuidById($top_item)), - 'source_name' => $postarray['author-name'], - 'source_link' => $postarray['author-link'], - 'source_photo' => $postarray['author-avatar'], - 'verb' => ACTIVITY_POST, - 'otype' => 'item', - 'parent' => $conv_parent, - ]); - - // only send one notification - break; - } - } -} - function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) { $conversations = []; @@ -1395,10 +1312,6 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) $postarray["id"] = $item; logger('statusnet_fetchhometimeline: User ' . $self["nick"] . ' posted home timeline item ' . $item); - - if ($item && !function_exists("check_item_notification")) { - statusnet_checknotification($a, $uid, $nick, $item, $postarray); - } } } } @@ -1447,42 +1360,8 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) } $item = Item::insert($postarray); - $postarray["id"] = $item; logger('statusnet_fetchhometimeline: User ' . $self["nick"] . ' posted mention timeline item ' . $item); - - if ($item && function_exists("check_item_notification")) { - check_item_notification($item, $uid, NOTIFY_TAGSELF); - } - } - - $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", - dbesc($postarray['uri']), - intval($uid) - ); - if (count($r)) { - $item = $r[0]['id']; - $parent_id = $r[0]['parent']; - } - - if (($item != 0) && !function_exists("check_item_notification")) { - require_once 'include/enotify.php'; - notification([ - 'type' => NOTIFY_TAGSELF, - 'notify_flags' => $u[0]['notify-flags'], - 'language' => $u[0]['language'], - 'to_name' => $u[0]['username'], - 'to_email' => $u[0]['email'], - 'uid' => $u[0]['uid'], - 'item' => $postarray, - 'link' => $a->get_baseurl() . '/display/' . urlencode(Item::getGuidById($item)), - 'source_name' => $postarray['author-name'], - 'source_link' => $postarray['author-link'], - 'source_photo' => $postarray['author-avatar'], - 'verb' => ACTIVITY_TAG, - 'otype' => 'item', - 'parent' => $parent_id, - ]); } } } @@ -1518,10 +1397,6 @@ function statusnet_complete_conversation(App $a, $uid, $self, $create_user, $nic $postarray["id"] = $item; logger('statusnet_complete_conversation: User ' . $self["nick"] . ' posted home timeline item ' . $item); - - if ($item && !function_exists("check_item_notification")) { - statusnet_checknotification($a, $uid, $nick, $item, $postarray); - } } } } diff --git a/twitter/twitter.php b/twitter/twitter.php index e69ebb8e..0b8f5c38 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -454,16 +454,13 @@ function twitter_post_hook(App $a, &$b) return; } - $r = q("SELECT * FROM item WHERE item.uri = '%s' AND item.uid = %d LIMIT 1", - dbesc($b["thr-parent"]), - intval($b["uid"])); - - if (!DBM::is_result($r)) { + $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; + $orig_post = Item::selectFirst($b["uid"], [], $condition); + if (!DBM::is_result($orig_post)) { logger("twitter_post_hook: no parent found " . $b["thr-parent"]); return; } else { $iscomment = true; - $orig_post = $r[0]; } @@ -761,13 +758,9 @@ function twitter_prepare_body(App $a, &$b) $item = $b["item"]; $item["plink"] = $a->get_baseurl() . "/display/" . $a->user["nickname"] . "/" . $item["parent"]; - $r = q("SELECT `author-link` FROM item WHERE item.uri = '%s' AND item.uid = %d LIMIT 1", - dbesc($item["thr-parent"]), - intval(local_user())); - - if (DBM::is_result($r)) { - $orig_post = $r[0]; - + $condition = ['uri' => $item["thr-parent"], 'uid' => local_user()]; + $orig_post = Item::selectFirst(local_user(), ['author-link'], $condition); + if (DBM::is_result($orig_post)) { $nicknameplain = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $orig_post["author-link"]); $nickname = "@[url=" . $orig_post["author-link"] . "]" . $nicknameplain . "[/url]"; $nicknameplain = "@" . $nicknameplain; @@ -1493,75 +1486,6 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis return $postarray; } -function twitter_checknotification(App $a, $uid, $own_id, $top_item, $postarray) -{ - /// TODO: this whole function doesn't seem to work. Needs complete check - $user = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", - intval($uid) - ); - - if (!DBM::is_result($user)) { - return; - } - - // Is it me? - if (link_compare($user[0]["url"], $postarray['author-link'])) { - return; - } - - $own_user = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", - intval($uid), - dbesc("twitter::".$own_id) - ); - - if (!DBM::is_result($own_user)) { - return; - } - - // Is it me from twitter? - if (link_compare($own_user[0]["url"], $postarray['author-link'])) { - return; - } - - $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0", - dbesc($postarray['parent-uri']), - intval($uid) - ); - - if (DBM::is_result($myconv)) { - foreach ($myconv as $conv) { - // now if we find a match, it means we're in this conversation - if (!link_compare($conv['author-link'], $user[0]["url"]) && !link_compare($conv['author-link'], $own_user[0]["url"])) { - continue; - } - - require_once 'include/enotify.php'; - - $conv_parent = $conv['parent']; - - notification([ - 'type' => NOTIFY_COMMENT, - 'notify_flags' => $user[0]['notify-flags'], - 'language' => $user[0]['language'], - 'to_name' => $user[0]['username'], - 'to_email' => $user[0]['email'], - 'uid' => $user[0]['uid'], - 'item' => $postarray, - 'link' => $a->get_baseurl() . '/display/' . urlencode(Item::getGuidById($top_item)), - 'source_name' => $postarray['author-name'], - 'source_link' => $postarray['author-link'], - 'source_photo' => $postarray['author-avatar'], - 'verb' => ACTIVITY_POST, - 'otype' => 'item', - 'parent' => $conv_parent, - ]); - - // only send one notification - break; - } - } -} - function twitter_fetchparentposts(App $a, $uid, $post, $connection, $self, $own_id) { logger("twitter_fetchparentposts: Fetching for user " . $uid . " and post " . $post->id_str, LOGGER_DEBUG); @@ -1616,10 +1540,6 @@ function twitter_fetchparentposts(App $a, $uid, $post, $connection, $self, $own_ $postarray["id"] = $item; logger('twitter_fetchparentpost: User ' . $self["nick"] . ' posted parent timeline item ' . $item); - - if ($item && !function_exists("check_item_notification")) { - twitter_checknotification($a, $uid, $own_id, $item, $postarray); - } } } } @@ -1751,10 +1671,6 @@ function twitter_fetchhometimeline(App $a, $uid) $postarray["id"] = $item; logger('twitter_fetchhometimeline: User ' . $self["nick"] . ' posted home timeline item ' . $item); - - if ($item && !function_exists("check_item_notification")) { - twitter_checknotification($a, $uid, $own_id, $item, $postarray); - } } } PConfig::set($uid, 'twitter', 'lasthometimelineid', $lastid); @@ -1805,50 +1721,8 @@ function twitter_fetchhometimeline(App $a, $uid) } $item = Item::insert($postarray); - $postarray["id"] = $item; - - if ($item && function_exists("check_item_notification")) { - check_item_notification($item, $uid, NOTIFY_TAGSELF); - } - - if (!isset($postarray["parent"]) || ($postarray["parent"] == 0)) { - $postarray["parent"] = $item; - } logger('twitter_fetchhometimeline: User ' . $self["nick"] . ' posted mention timeline item ' . $item); - - if ($item == 0) { - $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", - dbesc($postarray['uri']), - intval($uid) - ); - if (DBM::is_result($r)) { - $item = $r[0]['id']; - $parent_id = $r[0]['parent']; - } - } else { - $parent_id = $postarray['parent']; - } - - if (($item != 0) && !function_exists("check_item_notification")) { - require_once 'include/enotify.php'; - notification([ - 'type' => NOTIFY_TAGSELF, - 'notify_flags' => $u[0]['notify-flags'], - 'language' => $u[0]['language'], - 'to_name' => $u[0]['username'], - 'to_email' => $u[0]['email'], - 'uid' => $u[0]['uid'], - 'item' => $postarray, - 'link' => $a->get_baseurl() . '/display/' . urlencode(Item::getGuidById($item)), - 'source_name' => $postarray['author-name'], - 'source_link' => $postarray['author-link'], - 'source_photo' => $postarray['author-avatar'], - 'verb' => ACTIVITY_TAG, - 'otype' => 'item', - 'parent' => $parent_id - ]); - } } } diff --git a/windowsphonepush/windowsphonepush.php b/windowsphonepush/windowsphonepush.php index 3aaf1d30..a7453b1d 100644 --- a/windowsphonepush/windowsphonepush.php +++ b/windowsphonepush/windowsphonepush.php @@ -33,6 +33,7 @@ use Friendica\Core\Addon; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Model\User; +use Friendica\Model\Item; function windowsphonepush_install() { @@ -196,19 +197,19 @@ function windowsphonepush_cron() $senditemtext = PConfig::get($rr['uid'], 'windowsphonepush', 'senditemtext'); if ($senditemtext == 1) { // load item with the max id - $item = q("SELECT `author-name` as author, `body` as body FROM `item` where `id` = %d", intval($count[0]['max'])); + $item = Item::selectFirst(local_user(), ['author-name', 'body'], ['id' => $count[0]['max']]); // as user allows to send the item, we want to show the sender of the item in the toast // toasts are limited to one line, therefore place is limited - author shall be in // max. 15 chars (incl. dots); author is displayed in bold font - $author = $item[0]['author']; + $author = $item['author-name']; $author = ((strlen($author) > 12) ? substr($author, 0, 12) . "..." : $author); // normally we show the body of the item, however if it is an url or an image we cannot // show this in the toast (only test), therefore changing to an alternate text // Otherwise BBcode-Tags will be eliminated and plain text cutted to 140 chars (incl. dots) // BTW: information only possible in English - $body = $item[0]['body']; + $body = $item['body']; if (substr($body, 0, 4) == "[url") { $body = "URL/Image ..."; } else { From ef0a2f6f8d5140d67f108a8bc8cee780bd3385e0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 Jun 2018 06:26:22 +0000 Subject: [PATCH 2/5] Don't store the twitter protocol content by default --- twitter/twitter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/twitter/twitter.php b/twitter/twitter.php index e0a29665..d9f6ece3 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -800,7 +800,7 @@ function twitter_do_mirrorpost(App $a, $uid, $post) $datarray["profile_uid"] = $uid; $datarray["extid"] = NETWORK_TWITTER; $datarray['message_id'] = Item::newURI($uid, NETWORK_TWITTER . ":" . $post->id); - $datarray['object'] = json_encode($post); + // $datarray['object'] = json_encode($post); // Activate for debugging $datarray["title"] = ""; if (is_object($post->retweeted_status)) { @@ -1319,7 +1319,7 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis $postarray['uid'] = $uid; $postarray['wall'] = 0; $postarray['uri'] = "twitter::" . $post->id_str; - $postarray['object'] = json_encode($post); + // $postarray['object'] = json_encode($post); // Activate for debugging // Don't import our own comments $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", From c66dcf96ac69e12396d3a952cee722b3a90ac6b3 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 Jun 2018 17:04:23 +0000 Subject: [PATCH 3/5] New user based item function --- advancedcontentfilter/advancedcontentfilter.php | 2 +- mailstream/mailstream.php | 2 +- statusnet/statusnet.php | 4 ++-- twitter/twitter.php | 4 ++-- windowsphonepush/windowsphonepush.php | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/advancedcontentfilter/advancedcontentfilter.php b/advancedcontentfilter/advancedcontentfilter.php index 43946049..eebec4b0 100644 --- a/advancedcontentfilter/advancedcontentfilter.php +++ b/advancedcontentfilter/advancedcontentfilter.php @@ -405,7 +405,7 @@ function advancedcontentfilter_get_variables_guid(ServerRequestInterface $reques $condition = ["`guid` = ? AND (`uid` = ? OR `uid` = 0)", $args['guid'], local_user()]; $params = ['order' => ['uid' => true]]; - $item = Item::selectFirst(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params); + $item = Item::selectFirstForUser(local_user(), [], $condition, $params); if (!\Friendica\Database\DBM::is_result($item)) { throw new HTTPException\NotFoundException(L10n::t('Unknown post with guid: %s', $args['guid'])); diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index a68e0b36..bc6d490c 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -336,7 +336,7 @@ function mailstream_cron($a, $b) { if (!$ms_item_id['message-id'] || !strlen($ms_item_id['message-id'])) { logger('mailstream_cron: Item ' . $ms_item_id['id'] . ' URI ' . $ms_item_id['uri'] . ' has no message-id', LOGGER_NORMAL); } - $item = Item::selectFirst($ms_item_id['uid'], Item::DISPLAY_FIELDLIST, ['id' => $ms_item_id['id']]); + $item = Item::selectFirst([], ['id' => $ms_item_id['id']]); $users = q("SELECT * FROM `user` WHERE `uid` = %d", intval($item['uid'])); $user = $users[0]; if ($user && $item) { diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 56639117..6a3090da 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -462,7 +462,7 @@ function statusnet_post_hook(App $a, &$b) } $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; - $orig_post = Item::selectFirst($b["uid"], ['author-link', 'uri'], $condition); + $orig_post = Item::selectFirst(['author-link', 'uri'], $condition); if (!count($orig_post)) { logger("statusnet_post_hook: no parent found " . $b["thr-parent"]); return; @@ -683,7 +683,7 @@ function statusnet_prepare_body(App $a, &$b) $item["plink"] = $a->get_baseurl() . "/display/" . $a->user["nickname"] . "/" . $item["parent"]; $condition = ['uri' => $item["thr-parent"], 'uid' => local_user()]; - $orig_post = Item::selectFirst(local_user(), ['author-link', 'uri'], $condition); + $orig_post = Item::selectFirst(['author-link', 'uri'], $condition); if (count($orig_post)) { $nick = preg_replace("=https?://(.*)/(.*)=ism", "$2", $orig_post["author-link"]); diff --git a/twitter/twitter.php b/twitter/twitter.php index d9f6ece3..3e2d90d7 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -454,7 +454,7 @@ function twitter_post_hook(App $a, &$b) } $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; - $orig_post = Item::selectFirst($b["uid"], [], $condition); + $orig_post = Item::selectFirst([], $condition); if (!DBM::is_result($orig_post)) { logger("twitter_post_hook: no parent found " . $b["thr-parent"]); return; @@ -758,7 +758,7 @@ function twitter_prepare_body(App $a, &$b) $item["plink"] = $a->get_baseurl() . "/display/" . $a->user["nickname"] . "/" . $item["parent"]; $condition = ['uri' => $item["thr-parent"], 'uid' => local_user()]; - $orig_post = Item::selectFirst(local_user(), ['author-link'], $condition); + $orig_post = Item::selectFirst(['author-link'], $condition); if (DBM::is_result($orig_post)) { $nicknameplain = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $orig_post["author-link"]); $nickname = "@[url=" . $orig_post["author-link"] . "]" . $nicknameplain . "[/url]"; diff --git a/windowsphonepush/windowsphonepush.php b/windowsphonepush/windowsphonepush.php index a7453b1d..dd461ea4 100644 --- a/windowsphonepush/windowsphonepush.php +++ b/windowsphonepush/windowsphonepush.php @@ -197,7 +197,7 @@ function windowsphonepush_cron() $senditemtext = PConfig::get($rr['uid'], 'windowsphonepush', 'senditemtext'); if ($senditemtext == 1) { // load item with the max id - $item = Item::selectFirst(local_user(), ['author-name', 'body'], ['id' => $count[0]['max']]); + $item = Item::selectFirst(['author-name', 'body'], ['id' => $count[0]['max']]); // as user allows to send the item, we want to show the sender of the item in the toast // toasts are limited to one line, therefore place is limited - author shall be in From 478ff41870f60cc1bbd4b9730bea777000a907d3 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 Jun 2018 17:21:36 +0000 Subject: [PATCH 4/5] We don't need the uid --- mailstream/mailstream.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index bc6d490c..cf2fcc84 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -330,7 +330,7 @@ function mailstream_cron($a, $b) { // send the email itself before cron jumps in. Only if // mailstream_post_remote_hook fails for some reason will this get // used, and in that case it's worth holding off a bit anyway. - $ms_item_ids = q("SELECT `mailstream_item`.`message-id`, `mailstream_item`.`uri`, `mailstream_item`.`uid`, `item`.`id` FROM `mailstream_item` JOIN `item` ON (`mailstream_item`.`uid` = `item`.`uid` AND `mailstream_item`.`uri` = `item`.`uri` AND `mailstream_item`.`contact-id` = `item`.`contact-id`) WHERE `mailstream_item`.`completed` IS NULL AND `mailstream_item`.`created` < DATE_SUB(NOW(), INTERVAL 1 HOUR) AND `item`.`visible` = 1 ORDER BY `mailstream_item`.`created` LIMIT 100"); + $ms_item_ids = q("SELECT `mailstream_item`.`message-id`, `mailstream_item`.`uri`, `item`.`id` FROM `mailstream_item` JOIN `item` ON (`mailstream_item`.`uid` = `item`.`uid` AND `mailstream_item`.`uri` = `item`.`uri` AND `mailstream_item`.`contact-id` = `item`.`contact-id`) WHERE `mailstream_item`.`completed` IS NULL AND `mailstream_item`.`created` < DATE_SUB(NOW(), INTERVAL 1 HOUR) AND `item`.`visible` = 1 ORDER BY `mailstream_item`.`created` LIMIT 100"); logger('mailstream_cron processing ' . count($ms_item_ids) . ' items', LOGGER_DEBUG); foreach ($ms_item_ids as $ms_item_id) { if (!$ms_item_id['message-id'] || !strlen($ms_item_id['message-id'])) { From 5e4f9852434bbc9f8011a110762fef050f6ea8b6 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 Jun 2018 17:50:13 +0000 Subject: [PATCH 5/5] Don't use "count" --- statusnet/statusnet.php | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 6a3090da..43f5d400 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -55,6 +55,7 @@ use Friendica\Model\Photo; use Friendica\Model\User; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; +use Friendica\Database\DBM; function statusnet_install() { @@ -463,7 +464,7 @@ function statusnet_post_hook(App $a, &$b) $condition = ['uri' => $b["thr-parent"], 'uid' => $b["uid"]]; $orig_post = Item::selectFirst(['author-link', 'uri'], $condition); - if (!count($orig_post)) { + if (!DBM::is_result($orig_post)) { logger("statusnet_post_hook: no parent found " . $b["thr-parent"]); return; } else { @@ -684,7 +685,7 @@ function statusnet_prepare_body(App $a, &$b) $condition = ['uri' => $item["thr-parent"], 'uid' => local_user()]; $orig_post = Item::selectFirst(['author-link', 'uri'], $condition); - if (count($orig_post)) { + if (DBM::is_result($orig_post)) { $nick = preg_replace("=https?://(.*)/(.*)=ism", "$2", $orig_post["author-link"]); $nickname = "@[url=" . $orig_post["author-link"] . "]" . $nick . "[/url]"; @@ -729,7 +730,7 @@ function statusnet_cron(App $a, $b) logger('statusnet: cron_start'); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'mirror_posts' AND `v` = '1' ORDER BY RAND() "); - if (count($r)) { + if (DBM::is_result($r)) { foreach ($r as $rr) { logger('statusnet: fetching for user ' . $rr['uid']); statusnet_fetchtimeline($a, $rr['uid']); @@ -744,11 +745,11 @@ function statusnet_cron(App $a, $b) $abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'import' AND `v` ORDER BY RAND()"); - if (count($r)) { + if (DBM::is_result($r)) { foreach ($r as $rr) { if ($abandon_days != 0) { $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); - if (!count($user)) { + if (!DBM::is_result($user)) { logger('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported'); continue; } @@ -901,16 +902,16 @@ function statusnet_fetch_contact($uid, $contact, $create_user) $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' AND `network` = '%s'LIMIT 1", intval($uid), dbesc(normalise_link($contact->statusnet_profile_url)), dbesc(NETWORK_STATUSNET)); - if (!count($r) && !$create_user) { + if (!DBM::is_result($r) && !$create_user) { return 0; } - if (count($r) && ($r[0]["readonly"] || $r[0]["blocked"])) { + if (DBM::is_result($r) && ($r[0]["readonly"] || $r[0]["blocked"])) { logger("statusnet_fetch_contact: Contact '" . $r[0]["nick"] . "' is blocked or readonly.", LOGGER_DEBUG); return -1; } - if (!count($r)) { + if (!DBM::is_result($r)) { // create contact record q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`, @@ -940,7 +941,7 @@ function statusnet_fetch_contact($uid, $contact, $create_user) intval($uid), dbesc(NETWORK_STATUSNET)); - if (!count($r)) { + if (!DBM::is_result($r)) { return false; } @@ -1024,7 +1025,7 @@ function statusnet_fetchuser(App $a, $uid, $screen_name = "", $user_id = "") $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (count($r)) { + if (DBM::is_result($r)) { $self = $r[0]; } else { return; @@ -1079,7 +1080,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex intval($uid) ); - if (count($r)) { + if (DBM::is_result($r)) { return []; } @@ -1093,7 +1094,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex dbesc($parent), intval($uid) ); - if (count($r)) { + if (DBM::is_result($r)) { $postarray['thr-parent'] = $r[0]["uri"]; $postarray['parent-uri'] = $r[0]["parent-uri"]; $postarray['parent'] = $r[0]["parent"]; @@ -1103,7 +1104,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex dbesc($parent), intval($uid) ); - if (count($r)) { + if (DBM::is_result($r)) { $postarray['thr-parent'] = $r[0]['uri']; $postarray['parent-uri'] = $r[0]['parent-uri']; $postarray['parent'] = $r[0]['parent']; @@ -1122,7 +1123,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (count($r)) { + if (DBM::is_result($r)) { $contactid = $r[0]["id"]; $postarray['owner-name'] = $r[0]["name"]; @@ -1226,7 +1227,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) intval($own_contact), intval($uid)); - if (count($r)) { + if (DBM::is_result($r)) { $nick = $r[0]["nick"]; } else { logger("statusnet_fetchhometimeline: Own GNU Social contact not found for user " . $uid, LOGGER_DEBUG); @@ -1236,7 +1237,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); - if (count($r)) { + if (DBM::is_result($r)) { $self = $r[0]; } else { logger("statusnet_fetchhometimeline: Own contact not found for user " . $uid, LOGGER_DEBUG); @@ -1245,7 +1246,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", intval($uid)); - if (!count($u)) { + if (!DBM::is_result($u)) { logger("statusnet_fetchhometimeline: Own user not found for user " . $uid, LOGGER_DEBUG); return; } @@ -1535,7 +1536,7 @@ function statusnet_fetch_own_contact(App $a, $uid) } else { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), dbesc($own_url)); - if (count($r)) { + if (DBM::is_result($r)) { $contact_id = $r[0]["id"]; } else { PConfig::delete($uid, 'statusnet', 'own_url');