]> git.mxchange.org Git - friendica.git/commitdiff
Merge
authorMichael <heluecht@pirati.ca>
Tue, 28 Apr 2020 13:33:03 +0000 (13:33 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 28 Apr 2020 13:33:03 +0000 (13:33 +0000)
17 files changed:
mod/msearch.php
src/Core/Worker.php
src/Database/Database.php
src/Model/Contact.php
src/Model/GContact.php
src/Model/Process.php
src/Model/Search.php
src/Model/User.php
src/Model/UserItem.php
src/Module/Admin/DBSync.php
src/Module/Admin/Site.php
src/Module/Settings/Delegation.php
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/Diaspora.php
src/Worker/CronJobs.php
src/Worker/UpdateGContacts.php
src/Worker/UpdateGServers.php

index b02a036ae4e1996dc4a6853892b77b6b4df71724..14dfd1ef7c1646caf7bfde3bd5f2b269360f196b 100644 (file)
@@ -68,7 +68,7 @@ function msearch_post(App $a)
                $perpage
        );
 
-       while($search_result = DBA::fetch($search_stmt)) {
+       while ($search_result = DBA::fetch($search_stmt)) {
                $results[] = [
                        'name'  => $search_result['name'],
                        'url'   => DI::baseUrl() . '/profile/' . $search_result['nickname'],
@@ -77,6 +77,8 @@ function msearch_post(App $a)
                ];
        }
 
+       DBA::close($search_stmt);
+
        $output = ['total' => $total, 'items_page' => $perpage, 'page' => $page, 'results' => $results];
 
        echo json_encode($output);
index 6fb8bd40ff7d555031e7c03a5df66e14bcd8a373..24febf3bc4cc74ae47e603e21a4eeb53f2b01dbf 100644 (file)
@@ -614,6 +614,7 @@ class Worker
                                }
                        }
                }
+               DBA::close($entries);
        }
 
        /**
index f86f279965ab0e430734d13c0f35a3ceff4436d7..db906bd01e05e40675e049c6adc45802f333798b 100644 (file)
@@ -57,6 +57,7 @@ class Database
        /** @var PDO|mysqli */
        protected $connection;
        protected $driver;
+       private $emulate_prepares = false;
        private $error          = false;
        private $errorno        = 0;
        private $affected_rows  = 0;
@@ -130,6 +131,8 @@ class Database
                        return false;
                }
 
+               $this->emulate_prepares = (bool)$this->configCache->get('database', 'emulate_prepares');
+
                if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
                        $this->driver = 'pdo';
                        $connect      = "mysql:host=" . $server . ";dbname=" . $db;
@@ -428,8 +431,10 @@ class Database
        {
                $offset = 0;
                foreach ($args AS $param => $value) {
-                       if (is_int($args[$param]) || is_float($args[$param])) {
+                       if (is_int($args[$param]) || is_float($args[$param]) || is_bool($args[$param])) {
                                $replace = intval($args[$param]);
+                       } elseif (is_null($args[$param])) {
+                               $replace = 'NULL';
                        } else {
                                $replace = "'" . $this->escape($args[$param]) . "'";
                        }
@@ -515,8 +520,8 @@ class Database
                switch ($this->driver) {
                        case 'pdo':
                                // If there are no arguments we use "query"
-                               if (count($args) == 0) {
-                                       if (!$retval = $this->connection->query($sql)) {
+                               if ($this->emulate_prepares || count($args) == 0) {
+                                       if (!$retval = $this->connection->query($this->replaceParameters($sql, $args))) {
                                                $errorInfo     = $this->connection->errorInfo();
                                                $this->error   = $errorInfo[2];
                                                $this->errorno = $errorInfo[1];
@@ -562,7 +567,7 @@ class Database
                                $can_be_prepared = in_array($command, ['select', 'update', 'insert', 'delete']);
 
                                // The fallback routine is called as well when there are no arguments
-                               if (!$can_be_prepared || (count($args) == 0)) {
+                               if ($this->emulate_prepares || !$can_be_prepared || (count($args) == 0)) {
                                        $retval = $this->connection->query($this->replaceParameters($sql, $args));
                                        if ($this->connection->errno) {
                                                $this->error   = $this->connection->error;
index 2435b54f9c75a17afa36ae53b6856cbc1c3b310c..becc80c0c3c6e09e557e77778aaf37cc59882b80 100644 (file)
@@ -2057,6 +2057,7 @@ class Contact
 
                        Worker::add(PRIORITY_HIGH, 'MergeContact', $first, $duplicate['id'], $uid);
                }
+               DBA::close($duplicates);
                Logger::info('Duplicates handled', ['uid' => $uid, 'nurl' => $nurl]);
                return true;
        }
@@ -2732,6 +2733,7 @@ class Contact
                                );
                        }
                }
+               DBA::close($contacts);
        }
 
        /**
index 553976296f997297eb0b91d7f9a6f23e7c47a56a..becfd61b08e44105a9a4452d0b20154a327ad3ff 100644 (file)
@@ -113,6 +113,7 @@ class GContact
 
                        $gcontacts[] = Contact::getDetailsByURL($result['nurl'], local_user());
                }
+               DBA::close($results);
                return $gcontacts;
        }
 
@@ -563,6 +564,7 @@ class GContact
                                PortableContact::loadWorker(0, 0, 0, $base);
                        }
                }
+               DBA::close($contacts);
        }
 
        /**
index 2652929681d6e6209280a74098c9954f9f6f892d..18b5f785a1a619ede1c4609904ff3a83cfbd52dd 100644 (file)
@@ -85,7 +85,7 @@ class Process
                                self::deleteByPid($process['pid']);
                        }
                }
-
+               DBA::close($processes);
                DBA::commit();
        }
 }
index 9e00bbe30874751bd8ae707d136093aef8d18350..ca8960ef35bc6ec2437a0cc078ceffca441a89a6 100644 (file)
@@ -44,7 +44,7 @@ class Search
                while ($term = DBA::fetch($termsStmt)) {
                        $tags[] = trim($term['term'], '#');
                }
-
+               DBA::close($termsStmt);
                return $tags;
        }
 }
index be71bcf64589a61c4d10fee982ae5e78fd6082d9..89574e76094fc5857e6651badb36efaf3d7a969f 100644 (file)
@@ -1298,6 +1298,7 @@ class User
                                $statistics['active_users_monthly']++;
                        }
                }
+               DBA::close($userStmt);
 
                return $statistics;
        }
index f68b5aac824588bd1f9c8ab96d6b2fe8a35db8f7..74c5ac4486cc20cb43d3fb766deaad9d9fe10e98 100644 (file)
@@ -215,6 +215,7 @@ class UserItem
                                return true;
                        }
                }
+               DBA::close($tags);
 
                return false;
        }
index 8892c2969165bde30afad0a79102e97753e5f8bc..dd7febcc59123555a1b619a53cfd66164c9416c5 100644 (file)
@@ -102,6 +102,7 @@ class DBSync extends BaseAdmin
                                $failed[] = $upd;
                        }
                }
+               DBA::close($configStmt);
 
                if (!count($failed)) {
                        $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/dbsync/structure_check.tpl'), [
index cf3fee31b1b548a783c053c7f0f30c4df8c2e9c0..f3086856b3af48ae7a085dda0e4f4b57c7982e59 100644 (file)
@@ -121,6 +121,7 @@ class Site extends BaseAdmin
                        while ($user = DBA::fetch($usersStmt)) {
                                Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $user['uid']);
                        }
+                       DBA::close($usersStmt);
 
                        info("Relocation started. Could take a while to complete.");
 
index e70dee8908fab898b96137cb175163a1fc800a0e..e590d6ea773243bd5366634edc373cdeac86d07d 100644 (file)
@@ -125,6 +125,7 @@ class Delegation extends BaseSettings
                while ($contact = DBA::fetch($contacts)) {
                        $nicknames[] = $contact['nick'];
                }
+               DBA::close($contacts);
 
                // get user records for all potential page delegates who are not already delegates or managers
                $potentialDelegateUsers = DBA::selectToArray('user', ['uid', 'username', 'nickname'], ['nickname' => $nicknames]);
index 620894c75e5acfdedc7b62ccfbe6dcffd1fea3ba..fd91dca16a6376c608d878246d332ba5ec0c7ea0 100644 (file)
@@ -96,6 +96,7 @@ class Transmitter
                        while ($contact = DBA::fetch($contacts)) {
                                $list[] = $contact['url'];
                        }
+                       DBA::close($contacts);
 
                        if (!empty($list)) {
                                $data['next'] = DI::baseUrl() . '/followers/' . $owner['nickname'] . '?page=' . ($page + 1);
@@ -145,6 +146,7 @@ class Transmitter
                        while ($contact = DBA::fetch($contacts)) {
                                $list[] = $contact['url'];
                        }
+                       DBA::close($contacts);
 
                        if (!empty($list)) {
                                $data['next'] = DI::baseUrl() . '/following/' . $owner['nickname'] . '?page=' . ($page + 1);
index 2a7fcc4665b41cf23897d540f4145e6548a0babd..a91c5cdf80925bf19e77afc24c85f32422c2f551 100644 (file)
@@ -122,6 +122,7 @@ class Diaspora
                        while ($server = DBA::fetch($servers)) {
                                $serverlist[$server['url']] = $server['url'];
                        }
+                       DBA::close($servers);
 
                        // All tags of the current post
                        $tags = DBA::select('tag-view', ['name'], ['uri-id' => $parent['uri-id'], 'type' => Tag::HASHTAG]);
@@ -138,6 +139,7 @@ class Diaspora
                                while ($server = DBA::fetch($tagserver)) {
                                        $tagserverlist[] = $server['gserver-id'];
                                }
+                               DBA::close($tagserver);
                        }
 
                        // All adresses with the given id
@@ -146,6 +148,7 @@ class Diaspora
                                while ($server = DBA::fetch($servers)) {
                                        $serverlist[$server['url']] = $server['url'];
                                }
+                               DBA::close($servers);
                        }
                }
 
@@ -1718,6 +1721,7 @@ class Diaspora
                while ($contact = DBA::fetch($contacts)) {
                        Contact::remove($contact["id"]);
                }
+               DBA::close($contacts);
 
                DBA::delete('gcontact', ['addr' => $author]);
 
index 2a6c97e84299a53a34bf8c1632cb8744f53fa645..319a369d1fa69a6953059bedb954b81afe8199b2 100644 (file)
@@ -128,6 +128,7 @@ class CronJobs
                while ($user = DBA::fetch($users)) {
                        User::remove($user['uid']);
                }
+               DBA::close($users);
 
                // delete user records for recently removed accounts
                $users = DBA::select('user', ['uid'], ["`account_removed` AND `account_expires_on` < UTC_TIMESTAMP() "]);
@@ -140,6 +141,7 @@ class CronJobs
 
                        DBA::delete('user', ['uid' => $user['uid']]);
                }
+               DBA::close($users);
        }
 
        /**
index 80c0ef524ed5ca6d16968c50dd9a9425d7ae4409..9d9519241b4d738d0a553c87c4313ce122ef5ea8 100644 (file)
@@ -96,5 +96,6 @@ class UpdateGContacts
                                return;
                        }
                }
+               DBA::close($contacts);
        }
 }
index 2200d02e9261419de97d67ac3554c1fff4fdff15..5a45138462f797f9e7c258d6d8a4b81935159f40 100644 (file)
@@ -52,5 +52,6 @@ class UpdateGServers
                                return;
                        }
                }
+               DBA::close($gservers);
        }
 }