]> git.mxchange.org Git - friendica.git/commitdiff
Centralize owner data fetch
authorHypolite Petovan <mrpetovan@gmail.com>
Sun, 17 Dec 2017 21:22:39 +0000 (16:22 -0500)
committerHypolite Petovan <mrpetovan@gmail.com>
Sun, 17 Dec 2017 21:22:39 +0000 (16:22 -0500)
src/Model/User.php
src/Protocol/Diaspora.php
src/Worker/Delivery.php

index 9762727acae86d98e4a11ec14ad2ab2faa351125..a43560b0190e1b9abec585c8592bdd5f1745a7df 100644 (file)
@@ -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
         *
index e15c1b7933792b2edf6c40ff45a28c7ba99c3797..8828324c541feecf6310ba19ae6aa75d5f03d02f 100644 (file)
@@ -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(
index 9ed9a06c17b8a06987fff2bb2df5dfe9f61f200e..b3d3ecc1409e8c46439708ed40d81ae80170db4d 100644 (file)
@@ -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;