From dc3d2d598820d7a8682f55dd0d84a8f6ecabaaa1 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 23 Aug 2018 15:51:58 +0200 Subject: [PATCH] "dba" is now "DBA". This hadn't been respected at some places (#5655) * "dba" is now "DBA". This hadn't been respected at some places * Cleaning up unneeded stuff --- include/dba.php | 6 +++--- src/Core/System.php | 2 +- src/Database/DBA.php | 14 +++++++------- src/Model/Group.php | 19 ++++--------------- src/Protocol/Diaspora.php | 4 ++-- 5 files changed, 17 insertions(+), 28 deletions(-) diff --git a/include/dba.php b/include/dba.php index 6480b28ed2..9e168eac79 100644 --- a/include/dba.php +++ b/include/dba.php @@ -5,9 +5,9 @@ use Friendica\Database\DBA; /** * @brief execute SQL query with printf style args - deprecated * - * Please use the dba:: functions instead: - * dba::select, dba::exists, dba::insert - * dba::delete, dba::update, dba::p, dba::e + * Please use the DBA:: functions instead: + * DBA::select, DBA::exists, DBA::insert + * DBA::delete, DBA::update, DBA::p, DBA::e * * @param $args Query parameters (1 to N parameters of different types) * @return array|bool Query array diff --git a/src/Core/System.php b/src/Core/System.php index 4e2b63f044..88b89cda27 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -65,7 +65,7 @@ class System extends BaseObject while ($func = array_pop($trace)) { if (!empty($func['class'])) { // Don't show multiple calls from the "dba" class to show the essential parts of the callstack - if ((($previous['class'] != $func['class']) || ($func['class'] != 'dba')) && ($previous['function'] != 'q')) { + if ((($previous['class'] != $func['class']) || ($func['class'] != 'Friendica\Database\DBA')) && ($previous['function'] != 'q')) { $classparts = explode("\\", $func['class']); $callstack[] = array_pop($classparts).'::'.$func['function']; $previous = $func; diff --git a/src/Database/DBA.php b/src/Database/DBA.php index 9dc1984afb..bf480dad2c 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -372,7 +372,7 @@ class DBA * @usage Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid); * * Please only use it with complicated queries. - * For all regular queries please use dba::select or dba::exists + * For all regular queries please use DBA::select or DBA::exists * * @param string $sql SQL statement * @return bool|object statement object or result object @@ -590,7 +590,7 @@ class DBA /** * @brief Executes a prepared statement like UPDATE or INSERT that doesn't return data * - * Please use dba::delete, dba::insert, dba::update, ... instead + * Please use DBA::delete, DBA::insert, DBA::update, ... instead * * @param string $sql SQL statement * @return boolean Was the query successfull? False is returned only if an error occurred @@ -685,7 +685,7 @@ class DBA /** * Fetches the first row * - * Please use dba::selectFirst or dba::exists whenever this is possible. + * Please use DBA::selectFirst or DBA::exists whenever this is possible. * * @brief Fetches the first row * @param string $sql SQL statement @@ -1303,7 +1303,7 @@ class DBA * * $params = array("order" => array("id", "received" => true), "limit" => 10); * - * $data = dba::select($table, $fields, $condition, $params); + * $data = DBA::select($table, $fields, $condition, $params); */ public static function select($table, array $fields = [], array $condition = [], array $params = []) { @@ -1345,7 +1345,7 @@ class DBA * or: * $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr']; * - * $count = dba::count($table, $condition); + * $count = DBA::count($table, $condition); */ public static function count($table, array $condition = []) { @@ -1399,7 +1399,7 @@ class DBA /* Workaround for MySQL Bug #64791. * Never mix data types inside any IN() condition. * In case of mixed types, cast all as string. - * Logic needs to be consistent with dba::p() data types. + * Logic needs to be consistent with DBA::p() data types. */ $is_int = false; $is_alpha = false; @@ -1530,7 +1530,7 @@ class DBA case 'mysqli': // MySQLi offers both a mysqli_stmt and a mysqli_result class. // We should be careful not to assume the object type of $stmt - // because dba::p() has been able to return both types. + // because DBA::p() has been able to return both types. if ($stmt instanceof mysqli_stmt) { $stmt->free_result(); $ret = $stmt->close(); diff --git a/src/Model/Group.php b/src/Model/Group.php index b01fc19701..71f7941189 100644 --- a/src/Model/Group.php +++ b/src/Model/Group.php @@ -273,36 +273,25 @@ class Group extends BaseObject * * @param array $group_ids * @param boolean $check_dead - * @param boolean $use_gcontact * @return array */ - public static function expand($group_ids, $check_dead = false, $use_gcontact = false) + public static function expand($group_ids, $check_dead = false) { if (!is_array($group_ids) || !count($group_ids)) { return []; } - $condition = '`gid` IN (' . substr(str_repeat("?, ", count($group_ids)), 0, -2) . ')'; - if ($use_gcontact) { - $sql = 'SELECT `gcontact`.`id` AS `contact-id` FROM `group_member` - INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` - INNER JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl` - WHERE ' . $condition; - $param_arr = array_merge([$sql], $group_ids); - $stmt = call_user_func_array('dba::p', $param_arr); - } else { - $condition_array = array_merge([$condition], $group_ids); - $stmt = DBA::select('group_member', ['contact-id'], $condition_array); - } + $stmt = DBA::select('group_member', ['contact-id'], ['gid' => $group_ids]); $return = []; while($group_member = DBA::fetch($stmt)) { $return[] = $group_member['contact-id']; } - if ($check_dead && !$use_gcontact) { + if ($check_dead) { Contact::pruneUnavailable($return); } + return $return; } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index e62329e180..a7f34b7a6d 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -1050,7 +1050,7 @@ class Diaspora return false; } - $contact = dba::selectFirst('contact', [], ['id' => $cid]); + $contact = DBA::selectFirst('contact', [], ['id' => $cid]); if (!DBA::isResult($contact)) { // This here shouldn't happen at all logger("Haven't found a contact for user " . $uid . " and handle " . $handle, LOGGER_DEBUG); @@ -1079,7 +1079,7 @@ class Diaspora // It is deactivated by now, due to side effects. See issue https://github.com/friendica/friendica/pull/4033 // It is not removed by now. Possibly the code is needed? //if (!$is_comment && $contact["rel"] == Contact::FOLLOWER && in_array($importer["page-flags"], array(Contact::PAGE_FREELOVE))) { - // dba::update( + // DBA::update( // 'contact', // array('rel' => Contact::FRIEND, 'writable' => true), // array('id' => $contact["id"], 'uid' => $contact["uid"])