From a0567d40813a82d46d4b5cbe0baec75e9e0f0c0a Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 15 Aug 2017 06:08:26 +0000 Subject: [PATCH 1/2] dbm::is_result now checks whether a dba:... call returns at least one result --- include/dbm.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/dbm.php b/include/dbm.php index bda62f34c2..de4aef7d2b 100644 --- a/include/dbm.php +++ b/include/dbm.php @@ -41,7 +41,7 @@ class dbm { * Checks if $array is a filled array with at least one entry. * * @param $array mixed A filled array with at least one entry - * @return Whether $array is a filled array + * @return Whether $array is a filled array or an object with rows */ public static function is_result($array) { // It could be a return value from an update statement @@ -50,10 +50,10 @@ class dbm { } if (is_object($array)) { - return true; + return dba::num_rows($array) > 0; } - return (is_array($array) && count($array) > 0); + return (is_array($array) && (count($array) > 0)); } /** From 6c9953809ad6113d58126bbdfd5eceef7e42972e Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 15 Aug 2017 10:10:09 +0000 Subject: [PATCH 2/2] Improved position of "close" --- include/contact_widgets.php | 15 +++++++-------- src/Core/PConfig.php | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 744d2f2b03..2bc1e89f5c 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -3,6 +3,8 @@ use Friendica\App; use Friendica\Core\Config; +require_once 'include/contact_selectors.php'; + function follow_widget($value = "") { return replace_macros(get_markup_template('follow.tpl'), array( @@ -113,16 +115,13 @@ function networks_widget($baseurl, $selected = '') { ); $nets = array(); - if (dbm::is_result($r)) { - require_once 'include/contact_selectors.php'; - while ($rr = dba::fetch($r)) { - /// @TODO If 'network' is not there, this triggers an E_NOTICE - if ($rr['network']) { - $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' )); - } + while ($rr = dba::fetch($r)) { + /// @TODO If 'network' is not there, this triggers an E_NOTICE + if ($rr['network']) { + $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' )); } - dba::close($r); } + dba::close($r); if (count($nets) < 2) { return ''; diff --git a/src/Core/PConfig.php b/src/Core/PConfig.php index 5e17243241..1c64888247 100644 --- a/src/Core/PConfig.php +++ b/src/Core/PConfig.php @@ -43,11 +43,11 @@ class PConfig { $a->config[$uid][$family][$k] = $rr['v']; self::$in_db[$uid][$family][$k] = true; } - dba::close($r); } else if ($family != 'config') { // Negative caching $a->config[$uid][$family] = "!!"; } + dba::close($r); } /**