From df02238659ca702db64b89c5fcf47849f8ae722c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 17 Dec 2017 16:22:39 -0500 Subject: [PATCH] Centralize owner data fetch --- src/Model/User.php | 31 +++++++++++++++++++++++++++++++ src/Protocol/Diaspora.php | 22 ++-------------------- src/Worker/Delivery.php | 14 +++----------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/Model/User.php b/src/Model/User.php index 9762727ac..a43560b01 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -33,6 +33,37 @@ require_once 'include/text.php'; */ class User { + /** + * @brief Get owner data by user id + * + * @param int $uid + * @return boolean|array + */ + public static function getOwnerDataById($uid) { + $r = dba::p("SELECT + `contact`.*, + `user`.`prvkey` AS `uprvkey`, + `user`.`timezone`, + `user`.`nickname`, + `user`.`sprvkey`, + `user`.`spubkey`, + `user`.`page-flags`, + `user`.`account-type`, + `user`.`prvnets` + FROM `contact` + INNER JOIN `user` + ON `user`.`uid` = `contact`.`uid` + WHERE `contact`.`uid` = ? + AND `contact`.`self` = 1 + LIMIT 1", + $uid + ); + if (!DBM::is_result($r)) { + return false; + } + return $r[0]; + } + /** * @brief Returns the default group for a given user and network * diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index e15c1b793..8828324c5 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -4051,28 +4051,10 @@ class Diaspora return; } - $r = dba::p("SELECT - `contact`.*, - `user`.`prvkey` AS `uprvkey`, - `user`.`timezone`, - `user`.`nickname`, - `user`.`sprvkey`, - `user`.`spubkey`, - `user`.`page-flags`, - `user`.`account-type`, - `user`.`prvnets` - FROM `contact` - INNER JOIN `user` - ON `user`.`uid` = `contact`.`uid` - WHERE `contact`.`uid` = ? - AND `contact`.`self` = 1 - LIMIT 1", - $uid - ); - if (!DBM::is_result($r)) { + $owner = User::getOwnerDataById($uid); + if (!$owner) { return; } - $owner = $r[0]; if (!$recips) { $recips = q( diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 9ed9a06c1..b3d3ecc14 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -10,6 +10,7 @@ use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Database\DBM; use Friendica\Model\Contact; +use Friendica\Model\User; use Friendica\Protocol\Diaspora; use Friendica\Protocol\DFRN; use Friendica\Protocol\Email; @@ -140,20 +141,11 @@ class Delivery { } } - $r = q("SELECT `contact`.*, `user`.`prvkey` AS `uprvkey`, - `user`.`timezone`, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, - `user`.`page-flags`, `user`.`account-type`, `user`.`prvnets` - FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` - WHERE `contact`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", - intval($uid) - ); - - if (!DBM::is_result($r)) { + $owner = User::getOwnerDataById($uid); + if (!$owner) { return; } - $owner = $r[0]; - $walltowall = (($top_level && ($owner['id'] != $items[0]['contact-id'])) ? true : false); $public_message = true;