]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #5418 from MrPetovan/task/5410-move-dba-to-src
authorMichael Vogel <icarus@dabo.de>
Fri, 20 Jul 2018 04:50:36 +0000 (06:50 +0200)
committerGitHub <noreply@github.com>
Fri, 20 Jul 2018 04:50:36 +0000 (06:50 +0200)
Move \dba to \Friendica\Database\dba

130 files changed:
bin/daemon.php
include/api.php
include/conversation.php
include/dba.php
include/enotify.php
include/items.php
include/security.php
index.php
mod/acl.php
mod/admin.php
mod/allfriends.php
mod/attach.php
mod/cal.php
mod/common.php
mod/community.php
mod/contacts.php
mod/crepair.php
mod/delegate.php
mod/dfrn_confirm.php
mod/dfrn_notify.php
mod/dfrn_poll.php
mod/dfrn_request.php
mod/directory.php
mod/dirfind.php
mod/display.php
mod/feedtest.php
mod/hovercard.php
mod/install.php
mod/item.php
mod/lostpass.php
mod/message.php
mod/network.php
mod/nodeinfo.php
mod/noscrape.php
mod/notes.php
mod/notifications.php
mod/photos.php
mod/profile.php
mod/profiles.php
mod/proxy.php
mod/pubsub.php
mod/pubsubhubbub.php
mod/receive.php
mod/redir.php
mod/regmod.php
mod/removeme.php
mod/search.php
mod/settings.php
mod/suggest.php
mod/unfollow.php
mod/wall_attach.php
mod/worker.php
mod/xrd.php
src/App.php
src/Content/ContactSelector.php
src/Content/ForumManager.php
src/Content/Nav.php
src/Content/OEmbed.php
src/Content/Widget.php
src/Content/Widget/TagCloud.php
src/Core/ACL.php
src/Core/Addon.php
src/Core/Cache/DatabaseCacheDriver.php
src/Core/Config/JITConfigAdapter.php
src/Core/Config/JITPConfigAdapter.php
src/Core/Config/PreloadConfigAdapter.php
src/Core/Config/PreloadPConfigAdapter.php
src/Core/Console/ArchiveContact.php
src/Core/Console/AutomaticInstallation.php
src/Core/Console/Config.php
src/Core/Console/DatabaseStructure.php
src/Core/Console/GlobalCommunitySilence.php
src/Core/Console/NewPassword.php
src/Core/L10n.php
src/Core/Lock/DatabaseLockDriver.php
src/Core/NotificationsManager.php
src/Core/Session/DatabaseSessionHandler.php
src/Core/UserImport.php
src/Core/Worker.php
src/Database/DBA.php [new file with mode: 0644]
src/Database/DBM.php
src/Database/DBStructure.php
src/Database/PostUpdate.php
src/Model/Contact.php
src/Model/Conversation.php
src/Model/Event.php
src/Model/GContact.php
src/Model/Group.php
src/Model/Item.php
src/Model/Mail.php
src/Model/OpenWebAuthToken.php
src/Model/PermissionSet.php
src/Model/Photo.php
src/Model/Process.php
src/Model/Profile.php
src/Model/PushSubscriber.php
src/Model/Queue.php
src/Model/Term.php
src/Model/User.php
src/Module/Hashtag.php
src/Module/Login.php
src/Module/Magic.php
src/Module/Owa.php
src/Network/FKOAuth1.php
src/Network/FKOAuthDataStore.php
src/Network/Probe.php
src/Object/Post.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/Feed.php
src/Protocol/OStatus.php
src/Protocol/PortableContact.php
src/Util/ExAuth.php
src/Util/HTTPSignature.php
src/Util/ParseUrl.php
src/Worker/Cron.php
src/Worker/CronJobs.php
src/Worker/DBClean.php
src/Worker/Delivery.php
src/Worker/DiscoverPoCo.php
src/Worker/Expire.php
src/Worker/Notifier.php
src/Worker/OnePoll.php
src/Worker/PubSubPublish.php
src/Worker/Queue.php
src/Worker/RemoveContact.php
src/Worker/TagUpdate.php
tests/DatabaseTest.php
tests/src/Core/Lock/DatabaseLockDriverTest.php
update.php

index 65ae2a53b6596730e9f4b107e95c7dffdf001c04..6ab2f761026099278b07974f96060e86c39c0802 100755 (executable)
@@ -10,6 +10,7 @@
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 
 // Ensure that daemon.php is executed from the base path of the installation
 if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
index b67c5a5650a6251565020ebcadd62912cb065e1d..a6196852bf229f6f9ed890820aae6aa7b2e0b3cc 100644 (file)
@@ -19,6 +19,7 @@ use Friendica\Core\PConfig;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
index 54716cd6878613e0c94bb4a6e2505843a2639ccd..9b37e32687d7fe09fd3eb35ea200879c08f33192 100644 (file)
@@ -12,10 +12,12 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
-use Friendica\Model\Profile;
 use Friendica\Model\Item;
+use Friendica\Model\Profile;
+use Friendica\Model\Term;
 use Friendica\Object\Post;
 use Friendica\Object\Thread;
 use Friendica\Util\DateTimeFormat;
@@ -578,7 +580,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                                        $profile_name = $item['author-link'];
                                }
 
-                               $tags = \Friendica\Model\Term::populateTagsFromItem($item);
+                               $tags = Term::populateTagsFromItem($item);
 
                                $author = ['uid' => 0, 'id' => $item['author-id'],
                                        'network' => $item['author-network'], 'url' => $item['author-link']];
index 954c3a7cbb4468491d47906f3994f0894c2d7da1..a560c023121bc87f59f32829a81ce428e74381ec 100644 (file)
 <?php
 
-// Do not use Core\Config in this class at risk of infinite loop.
-// Please use App->getConfigVariable() instead.
-//use Friendica\Core\Config;
-
-use Friendica\Core\System;
-use Friendica\Database\DBM;
-use Friendica\Database\DBStructure;
-use Friendica\Util\DateTimeFormat;
-
-/**
- * @class MySQL database class
- *
- * This class is for the low level database stuff that does driver specific things.
- */
-
-class dba {
-       public static $connected = false;
-
-       private static $_server_info = '';
-       private static $db;
-       private static $driver;
-       private static $error = false;
-       private static $errorno = 0;
-       private static $affected_rows = 0;
-       private static $in_transaction = false;
-       private static $in_retrial = false;
-       private static $relation = [];
-       private static $db_serveraddr = '';
-       private static $db_user = '';
-       private static $db_pass = '';
-       private static $db_name = '';
-       private static $db_charset = '';
-
-       public static function connect($serveraddr, $user, $pass, $db, $charset = null)
-       {
-               if (!is_null(self::$db) && self::connected()) {
-                       return true;
-               }
-
-               // We are storing these values for being able to perform a reconnect
-               self::$db_serveraddr = $serveraddr;
-               self::$db_user = $user;
-               self::$db_pass = $pass;
-               self::$db_name = $db;
-               self::$db_charset = $charset;
-
-               $serveraddr = trim($serveraddr);
-
-               $serverdata = explode(':', $serveraddr);
-               $server = $serverdata[0];
-
-               if (count($serverdata) > 1) {
-                       $port = trim($serverdata[1]);
-               }
-
-               $server = trim($server);
-               $user = trim($user);
-               $pass = trim($pass);
-               $db = trim($db);
-               $charset = trim($charset);
-
-               if (!(strlen($server) && strlen($user))) {
-                       return false;
-               }
-
-               if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
-                       self::$driver = 'pdo';
-                       $connect = "mysql:host=".$server.";dbname=".$db;
-
-                       if (isset($port)) {
-                               $connect .= ";port=".$port;
-                       }
-
-                       if ($charset) {
-                               $connect .= ";charset=".$charset;
-                       }
-
-                       try {
-                               self::$db = @new PDO($connect, $user, $pass);
-                               self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
-                               self::$connected = true;
-                       } catch (PDOException $e) {
-                       }
-               }
-
-               if (!self::$connected && class_exists('mysqli')) {
-                       self::$driver = 'mysqli';
-                       self::$db = @new mysqli($server, $user, $pass, $db, $port);
-                       if (!mysqli_connect_errno()) {
-                               self::$connected = true;
-
-                               if ($charset) {
-                                       self::$db->set_charset($charset);
-                               }
-                       }
-               }
-
-               // No suitable SQL driver was found.
-               if (!self::$connected) {
-                       self::$driver = null;
-                       self::$db = null;
-               }
-
-               return self::$connected;
-       }
-
-       /**
-        * Disconnects the current database connection
-        */
-       public static function disconnect()
-       {
-               if (is_null(self::$db)) {
-                       return;
-               }
-
-               switch (self::$driver) {
-                       case 'pdo':
-                               self::$db = null;
-                               break;
-                       case 'mysqli':
-                               self::$db->close();
-                               self::$db = null;
-                               break;
-               }
-       }
-
-       /**
-        * Perform a reconnect of an existing database connection
-        */
-       public static function reconnect() {
-               self::disconnect();
-
-               $ret = self::connect(self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset);
-               return $ret;
-       }
-
-       /**
-        * Return the database object.
-        * @return PDO|mysqli
-        */
-       public static function get_db()
-       {
-               return self::$db;
-       }
-
-       /**
-        * @brief Returns the MySQL server version string
-        *
-        * This function discriminate between the deprecated mysql API and the current
-        * object-oriented mysqli API. Example of returned string: 5.5.46-0+deb8u1
-        *
-        * @return string
-        */
-       public static function server_info() {
-               if (self::$_server_info == '') {
-                       switch (self::$driver) {
-                               case 'pdo':
-                                       self::$_server_info = self::$db->getAttribute(PDO::ATTR_SERVER_VERSION);
-                                       break;
-                               case 'mysqli':
-                                       self::$_server_info = self::$db->server_info;
-                                       break;
-                       }
-               }
-               return self::$_server_info;
-       }
-
-       /**
-        * @brief Returns the selected database name
-        *
-        * @return string
-        */
-       public static function database_name() {
-               $ret = self::p("SELECT DATABASE() AS `db`");
-               $data = self::inArray($ret);
-               return $data[0]['db'];
-       }
-
-       /**
-        * @brief Analyze a database query and log this if some conditions are met.
-        *
-        * @param string $query The database query that will be analyzed
-        */
-       private static function logIndex($query) {
-               $a = get_app();
-
-               if (!$a->getConfigVariable('system', 'db_log_index')) {
-                       return;
-               }
-
-               // Don't explain an explain statement
-               if (strtolower(substr($query, 0, 7)) == "explain") {
-                       return;
-               }
-
-               // Only do the explain on "select", "update" and "delete"
-               if (!in_array(strtolower(substr($query, 0, 6)), ["select", "update", "delete"])) {
-                       return;
-               }
-
-               $r = self::p("EXPLAIN ".$query);
-               if (!DBM::is_result($r)) {
-                       return;
-               }
-
-               $watchlist = explode(',', $a->getConfigVariable('system', 'db_log_index_watch'));
-               $blacklist = explode(',', $a->getConfigVariable('system', 'db_log_index_blacklist'));
-
-               while ($row = dba::fetch($r)) {
-                       if ((intval($a->getConfigVariable('system', 'db_loglimit_index')) > 0)) {
-                               $log = (in_array($row['key'], $watchlist) &&
-                                       ($row['rows'] >= intval($a->getConfigVariable('system', 'db_loglimit_index'))));
-                       } else {
-                               $log = false;
-                       }
-
-                       if ((intval($a->getConfigVariable('system', 'db_loglimit_index_high')) > 0) && ($row['rows'] >= intval($a->getConfigVariable('system', 'db_loglimit_index_high')))) {
-                               $log = true;
-                       }
-
-                       if (in_array($row['key'], $blacklist) || ($row['key'] == "")) {
-                               $log = false;
-                       }
-
-                       if ($log) {
-                               $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
-                               @file_put_contents($a->getConfigVariable('system', 'db_log_index'), DateTimeFormat::utcNow()."\t".
-                                               $row['key']."\t".$row['rows']."\t".$row['Extra']."\t".
-                                               basename($backtrace[1]["file"])."\t".
-                                               $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
-                                               substr($query, 0, 2000)."\n", FILE_APPEND);
-                       }
-               }
-       }
-
-       public static function escape($str) {
-               switch (self::$driver) {
-                       case 'pdo':
-                               return substr(@self::$db->quote($str, PDO::PARAM_STR), 1, -1);
-                       case 'mysqli':
-                               return @self::$db->real_escape_string($str);
-               }
-       }
-
-       public static function connected() {
-               $connected = false;
-
-               if (is_null(self::$db)) {
-                       return false;
-               }
-
-               switch (self::$driver) {
-                       case 'pdo':
-                               $r = dba::p("SELECT 1");
-                               if (DBM::is_result($r)) {
-                                       $row = dba::inArray($r);
-                                       $connected = ($row[0]['1'] == '1');
-                               }
-                               break;
-                       case 'mysqli':
-                               $connected = self::$db->ping();
-                               break;
-               }
-               return $connected;
-       }
-
-       /**
-        * @brief Replaces ANY_VALUE() function by MIN() function,
-        *  if the database server does not support ANY_VALUE().
-        *
-        * Considerations for Standard SQL, or MySQL with ONLY_FULL_GROUP_BY (default since 5.7.5).
-        * ANY_VALUE() is available from MySQL 5.7.5 https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html
-        * A standard fall-back is to use MIN().
-        *
-        * @param string $sql An SQL string without the values
-        * @return string The input SQL string modified if necessary.
-        */
-       public static function any_value_fallback($sql) {
-               $server_info = self::server_info();
-               if (version_compare($server_info, '5.7.5', '<') ||
-                       (stripos($server_info, 'MariaDB') !== false)) {
-                       $sql = str_ireplace('ANY_VALUE(', 'MIN(', $sql);
-               }
-               return $sql;
-       }
-
-       /**
-        * @brief beautifies the query - useful for "SHOW PROCESSLIST"
-        *
-        * This is safe when we bind the parameters later.
-        * The parameter values aren't part of the SQL.
-        *
-        * @param string $sql An SQL string without the values
-        * @return string The input SQL string modified if necessary.
-        */
-       public static function clean_query($sql) {
-               $search = ["\t", "\n", "\r", "  "];
-               $replace = [' ', ' ', ' ', ' '];
-               do {
-                       $oldsql = $sql;
-                       $sql = str_replace($search, $replace, $sql);
-               } while ($oldsql != $sql);
-
-               return $sql;
-       }
-
-
-       /**
-        * @brief Replaces the ? placeholders with the parameters in the $args array
-        *
-        * @param string $sql SQL query
-        * @param array $args The parameters that are to replace the ? placeholders
-        * @return string The replaced SQL query
-        */
-       private static function replaceParameters($sql, $args) {
-               $offset = 0;
-               foreach ($args AS $param => $value) {
-                       if (is_int($args[$param]) || is_float($args[$param])) {
-                               $replace = intval($args[$param]);
-                       } else {
-                               $replace = "'".self::escape($args[$param])."'";
-                       }
-
-                       $pos = strpos($sql, '?', $offset);
-                       if ($pos !== false) {
-                               $sql = substr_replace($sql, $replace, $pos, 1);
-                       }
-                       $offset = $pos + strlen($replace);
-               }
-               return $sql;
-       }
-
-       /**
-        * @brief Convert parameter array to an universal form
-        * @param array $args Parameter array
-        * @return array universalized parameter array
-        */
-       private static function getParam($args) {
-               unset($args[0]);
-
-               // When the second function parameter is an array then use this as the parameter array
-               if ((count($args) > 0) && (is_array($args[1]))) {
-                       return $args[1];
-               } else {
-                       return $args;
-               }
-       }
-
-       /**
-        * @brief Executes a prepared statement that returns data
-        * @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
-        *
-        * @param string $sql SQL statement
-        * @return bool|object statement object or result object
-        */
-       public static function p($sql) {
-               $a = get_app();
-
-               $stamp1 = microtime(true);
-
-               $params = self::getParam(func_get_args());
-
-               // Renumber the array keys to be sure that they fit
-               $i = 0;
-               $args = [];
-               foreach ($params AS $param) {
-                       // Avoid problems with some MySQL servers and boolean values. See issue #3645
-                       if (is_bool($param)) {
-                               $param = (int)$param;
-                       }
-                       $args[++$i] = $param;
-               }
-
-               if (!self::$connected) {
-                       return false;
-               }
-
-               if ((substr_count($sql, '?') != count($args)) && (count($args) > 0)) {
-                       // Question: Should we continue or stop the query here?
-                       logger('Parameter mismatch. Query "'.$sql.'" - Parameters '.print_r($args, true), LOGGER_DEBUG);
-               }
-
-               $sql = self::clean_query($sql);
-               $sql = self::any_value_fallback($sql);
-
-               $orig_sql = $sql;
-
-               if ($a->getConfigValue('system', 'db_callstack')) {
-                       $sql = "/*".System::callstack()." */ ".$sql;
-               }
-
-               self::$error = '';
-               self::$errorno = 0;
-               self::$affected_rows = 0;
-
-               // We have to make some things different if this function is called from "e"
-               $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
-
-               if (isset($trace[1])) {
-                       $called_from = $trace[1];
-               } else {
-                       // We use just something that is defined to avoid warnings
-                       $called_from = $trace[0];
-               }
-               // We are having an own error logging in the function "e"
-               $called_from_e = ($called_from['function'] == 'e');
-
-               switch (self::$driver) {
-                       case 'pdo':
-                               // If there are no arguments we use "query"
-                               if (count($args) == 0) {
-                                       if (!$retval = self::$db->query($sql)) {
-                                               $errorInfo = self::$db->errorInfo();
-                                               self::$error = $errorInfo[2];
-                                               self::$errorno = $errorInfo[1];
-                                               $retval = false;
-                                               break;
-                                       }
-                                       self::$affected_rows = $retval->rowCount();
-                                       break;
-                               }
-
-                               if (!$stmt = self::$db->prepare($sql)) {
-                                       $errorInfo = self::$db->errorInfo();
-                                       self::$error = $errorInfo[2];
-                                       self::$errorno = $errorInfo[1];
-                                       $retval = false;
-                                       break;
-                               }
-
-                               foreach ($args AS $param => $value) {
-                                       if (is_int($args[$param])) {
-                                               $data_type = PDO::PARAM_INT;
-                                       } else {
-                                               $data_type = PDO::PARAM_STR;
-                                       }
-                                       $stmt->bindParam($param, $args[$param], $data_type);
-                               }
-
-                               if (!$stmt->execute()) {
-                                       $errorInfo = $stmt->errorInfo();
-                                       self::$error = $errorInfo[2];
-                                       self::$errorno = $errorInfo[1];
-                                       $retval = false;
-                               } else {
-                                       $retval = $stmt;
-                                       self::$affected_rows = $retval->rowCount();
-                               }
-                               break;
-                       case 'mysqli':
-                               // There are SQL statements that cannot be executed with a prepared statement
-                               $parts = explode(' ', $orig_sql);
-                               $command = strtolower($parts[0]);
-                               $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)) {
-                                       $retval = self::$db->query(self::replaceParameters($sql, $args));
-                                       if (self::$db->errno) {
-                                               self::$error = self::$db->error;
-                                               self::$errorno = self::$db->errno;
-                                               $retval = false;
-                                       } else {
-                                               if (isset($retval->num_rows)) {
-                                                       self::$affected_rows = $retval->num_rows;
-                                               } else {
-                                                       self::$affected_rows = self::$db->affected_rows;
-                                               }
-                                       }
-                                       break;
-                               }
-
-                               $stmt = self::$db->stmt_init();
-
-                               if (!$stmt->prepare($sql)) {
-                                       self::$error = $stmt->error;
-                                       self::$errorno = $stmt->errno;
-                                       $retval = false;
-                                       break;
-                               }
-
-                               $param_types = '';
-                               $values = [];
-                               foreach ($args AS $param => $value) {
-                                       if (is_int($args[$param])) {
-                                               $param_types .= 'i';
-                                       } elseif (is_float($args[$param])) {
-                                               $param_types .= 'd';
-                                       } elseif (is_string($args[$param])) {
-                                               $param_types .= 's';
-                                       } else {
-                                               $param_types .= 'b';
-                                       }
-                                       $values[] = &$args[$param];
-                               }
-
-                               if (count($values) > 0) {
-                                       array_unshift($values, $param_types);
-                                       call_user_func_array([$stmt, 'bind_param'], $values);
-                               }
-
-                               if (!$stmt->execute()) {
-                                       self::$error = self::$db->error;
-                                       self::$errorno = self::$db->errno;
-                                       $retval = false;
-                               } else {
-                                       $stmt->store_result();
-                                       $retval = $stmt;
-                                       self::$affected_rows = $retval->affected_rows;
-                               }
-                               break;
-               }
-
-               // We are having an own error logging in the function "e"
-               if ((self::$errorno != 0) && !$called_from_e) {
-                       // We have to preserve the error code, somewhere in the logging it get lost
-                       $error = self::$error;
-                       $errorno = self::$errorno;
-
-                       logger('DB Error '.self::$errorno.': '.self::$error."\n".
-                               System::callstack(8)."\n".self::replaceParameters($sql, $args));
-
-                       // On a lost connection we try to reconnect - but only once.
-                       if ($errorno == 2006) {
-                               if (self::$in_retrial || !self::reconnect()) {
-                                       // It doesn't make sense to continue when the database connection was lost
-                                       if (self::$in_retrial) {
-                                               logger('Giving up retrial because of database error '.$errorno.': '.$error);
-                                       } else {
-                                               logger("Couldn't reconnect after database error ".$errorno.': '.$error);
-                                       }
-                                       exit(1);
-                               } else {
-                                       // We try it again
-                                       logger('Reconnected after database error '.$errorno.': '.$error);
-                                       self::$in_retrial = true;
-                                       $ret = self::p($sql, $args);
-                                       self::$in_retrial = false;
-                                       return $ret;
-                               }
-                       }
-
-                       self::$error = $error;
-                       self::$errorno = $errorno;
-               }
-
-               $a->save_timestamp($stamp1, 'database');
-
-               if ($a->getConfigValue('system', 'db_log')) {
-                       $stamp2 = microtime(true);
-                       $duration = (float)($stamp2 - $stamp1);
-
-                       if (($duration > $a->getConfigValue('system', 'db_loglimit'))) {
-                               $duration = round($duration, 3);
-                               $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
-
-                               @file_put_contents($a->getConfigValue('system', 'db_log'), DateTimeFormat::utcNow()."\t".$duration."\t".
-                                               basename($backtrace[1]["file"])."\t".
-                                               $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
-                                               substr(self::replaceParameters($sql, $args), 0, 2000)."\n", FILE_APPEND);
-                       }
-               }
-               return $retval;
-       }
-
-       /**
-        * @brief Executes a prepared statement like UPDATE or INSERT that doesn't return data
-        *
-        * 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
-        */
-       public static function e($sql) {
-               $a = get_app();
-
-               $stamp = microtime(true);
-
-               $params = self::getParam(func_get_args());
-
-               // In a case of a deadlock we are repeating the query 20 times
-               $timeout = 20;
-
-               do {
-                       $stmt = self::p($sql, $params);
-
-                       if (is_bool($stmt)) {
-                               $retval = $stmt;
-                       } elseif (is_object($stmt)) {
-                               $retval = true;
-                       } else {
-                               $retval = false;
-                       }
-
-                       self::close($stmt);
-
-               } while ((self::$errorno == 1213) && (--$timeout > 0));
-
-               if (self::$errorno != 0) {
-                       // We have to preserve the error code, somewhere in the logging it get lost
-                       $error = self::$error;
-                       $errorno = self::$errorno;
-
-                       logger('DB Error '.self::$errorno.': '.self::$error."\n".
-                               System::callstack(8)."\n".self::replaceParameters($sql, $params));
-
-                       // On a lost connection we simply quit.
-                       // A reconnect like in self::p could be dangerous with modifications
-                       if ($errorno == 2006) {
-                               logger('Giving up because of database error '.$errorno.': '.$error);
-                               exit(1);
-                       }
-
-                       self::$error = $error;
-                       self::$errorno = $errorno;
-               }
-
-               $a->save_timestamp($stamp, "database_write");
-
-               return $retval;
-       }
-
-       /**
-        * @brief Check if data exists
-        *
-        * @param string $table Table name
-        * @param array $condition array of fields for condition
-        *
-        * @return boolean Are there rows for that condition?
-        */
-       public static function exists($table, $condition) {
-               if (empty($table)) {
-                       return false;
-               }
-
-               $fields = [];
-
-               reset($condition);
-               $first_key = key($condition);
-               if (!is_int($first_key)) {
-                       $fields = [$first_key];
-               }
-
-               $stmt = self::select($table, $fields, $condition, ['limit' => 1]);
-
-               if (is_bool($stmt)) {
-                       $retval = $stmt;
-               } else {
-                       $retval = (self::num_rows($stmt) > 0);
-               }
-
-               self::close($stmt);
-
-               return $retval;
-       }
-
-       /**
-        * Fetches the first row
-        *
-        * Please use dba::selectFirst or dba::exists whenever this is possible.
-        *
-        * @brief Fetches the first row
-        * @param string $sql SQL statement
-        * @return array first row of query
-        */
-       public static function fetch_first($sql) {
-               $params = self::getParam(func_get_args());
-
-               $stmt = self::p($sql, $params);
-
-               if (is_bool($stmt)) {
-                       $retval = $stmt;
-               } else {
-                       $retval = self::fetch($stmt);
-               }
-
-               self::close($stmt);
-
-               return $retval;
-       }
-
-       /**
-        * @brief Returns the number of affected rows of the last statement
-        *
-        * @return int Number of rows
-        */
-       public static function affected_rows() {
-               return self::$affected_rows;
-       }
-
-       /**
-        * @brief Returns the number of columns of a statement
-        *
-        * @param object Statement object
-        * @return int Number of columns
-        */
-       public static function columnCount($stmt) {
-               if (!is_object($stmt)) {
-                       return 0;
-               }
-               switch (self::$driver) {
-                       case 'pdo':
-                               return $stmt->columnCount();
-                       case 'mysqli':
-                               return $stmt->field_count;
-               }
-               return 0;
-       }
-       /**
-        * @brief Returns the number of rows of a statement
-        *
-        * @param PDOStatement|mysqli_result|mysqli_stmt Statement object
-        * @return int Number of rows
-        */
-       public static function num_rows($stmt) {
-               if (!is_object($stmt)) {
-                       return 0;
-               }
-               switch (self::$driver) {
-                       case 'pdo':
-                               return $stmt->rowCount();
-                       case 'mysqli':
-                               return $stmt->num_rows;
-               }
-               return 0;
-       }
-
-       /**
-        * @brief Fetch a single row
-        *
-        * @param mixed $stmt statement object
-        * @return array current row
-        */
-       public static function fetch($stmt) {
-               $a = get_app();
-
-               $stamp1 = microtime(true);
-
-               $columns = [];
-
-               if (!is_object($stmt)) {
-                       return false;
-               }
-
-               switch (self::$driver) {
-                       case 'pdo':
-                               $columns = $stmt->fetch(PDO::FETCH_ASSOC);
-                               break;
-                       case 'mysqli':
-                               if (get_class($stmt) == 'mysqli_result') {
-                                       $columns = $stmt->fetch_assoc();
-                                       break;
-                               }
-
-                               // This code works, but is slow
-
-                               // Bind the result to a result array
-                               $cols = [];
-
-                               $cols_num = [];
-                               for ($x = 0; $x < $stmt->field_count; $x++) {
-                                       $cols[] = &$cols_num[$x];
-                               }
-
-                               call_user_func_array([$stmt, 'bind_result'], $cols);
-
-                               if (!$stmt->fetch()) {
-                                       return false;
-                               }
-
-                               // The slow part:
-                               // We need to get the field names for the array keys
-                               // It seems that there is no better way to do this.
-                               $result = $stmt->result_metadata();
-                               $fields = $result->fetch_fields();
-
-                               foreach ($cols_num AS $param => $col) {
-                                       $columns[$fields[$param]->name] = $col;
-                               }
-               }
-
-               $a->save_timestamp($stamp1, 'database');
-
-               return $columns;
-       }
-
-       /**
-        * @brief Insert a row into a table
-        *
-        * @param string $table Table name
-        * @param array $param parameter array
-        * @param bool $on_duplicate_update Do an update on a duplicate entry
-        *
-        * @return boolean was the insert successfull?
-        */
-       public static function insert($table, $param, $on_duplicate_update = false) {
-
-               if (empty($table) || empty($param)) {
-                       logger('Table and fields have to be set');
-                       return false;
-               }
-
-               $sql = "INSERT INTO `".self::escape($table)."` (`".implode("`, `", array_keys($param))."`) VALUES (".
-                       substr(str_repeat("?, ", count($param)), 0, -2).")";
-
-               if ($on_duplicate_update) {
-                       $sql .= " ON DUPLICATE KEY UPDATE `".implode("` = ?, `", array_keys($param))."` = ?";
-
-                       $values = array_values($param);
-                       $param = array_merge_recursive($values, $values);
-               }
-
-               return self::e($sql, $param);
-       }
-
-       /**
-        * @brief Fetch the id of the last insert command
-        *
-        * @return integer Last inserted id
-        */
-       public static function lastInsertId() {
-               switch (self::$driver) {
-                       case 'pdo':
-                               $id = self::$db->lastInsertId();
-                               break;
-                       case 'mysqli':
-                               $id = self::$db->insert_id;
-                               break;
-               }
-               return $id;
-       }
-
-       /**
-        * @brief Locks a table for exclusive write access
-        *
-        * This function can be extended in the future to accept a table array as well.
-        *
-        * @param string $table Table name
-        *
-        * @return boolean was the lock successful?
-        */
-       public static function lock($table) {
-               // See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
-               if (self::$driver == 'pdo') {
-                       self::e("SET autocommit=0");
-                       self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
-               } else {
-                       self::$db->autocommit(false);
-               }
-
-               $success = self::e("LOCK TABLES `".self::escape($table)."` WRITE");
-
-               if (self::$driver == 'pdo') {
-                       self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
-               }
-
-               if (!$success) {
-                       if (self::$driver == 'pdo') {
-                               self::e("SET autocommit=1");
-                       } else {
-                               self::$db->autocommit(true);
-                       }
-               } else {
-                       self::$in_transaction = true;
-               }
-               return $success;
-       }
-
-       /**
-        * @brief Unlocks all locked tables
-        *
-        * @return boolean was the unlock successful?
-        */
-       public static function unlock() {
-               // See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
-               self::performCommit();
-
-               if (self::$driver == 'pdo') {
-                       self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
-               }
-
-               $success = self::e("UNLOCK TABLES");
-
-               if (self::$driver == 'pdo') {
-                       self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
-                       self::e("SET autocommit=1");
-               } else {
-                       self::$db->autocommit(true);
-               }
-
-               self::$in_transaction = false;
-               return $success;
-       }
-
-       /**
-        * @brief Starts a transaction
-        *
-        * @return boolean Was the command executed successfully?
-        */
-       public static function transaction() {
-               if (!self::performCommit()) {
-                       return false;
-               }
-
-               switch (self::$driver) {
-                       case 'pdo':
-                               if (self::$db->inTransaction()) {
-                                       break;
-                               }
-                               if (!self::$db->beginTransaction()) {
-                                       return false;
-                               }
-                               break;
-                       case 'mysqli':
-                               if (!self::$db->begin_transaction()) {
-                                       return false;
-                               }
-                               break;
-               }
-
-               self::$in_transaction = true;
-               return true;
-       }
-
-       private static function performCommit()
-       {
-               switch (self::$driver) {
-                       case 'pdo':
-                               if (!self::$db->inTransaction()) {
-                                       return true;
-                               }
-                               return self::$db->commit();
-                       case 'mysqli':
-                               return self::$db->commit();
-               }
-               return true;
-       }
-
-       /**
-        * @brief Does a commit
-        *
-        * @return boolean Was the command executed successfully?
-        */
-       public static function commit() {
-               if (!self::performCommit()) {
-                       return false;
-               }
-               self::$in_transaction = false;
-               return true;
-       }
-
-       /**
-        * @brief Does a rollback
-        *
-        * @return boolean Was the command executed successfully?
-        */
-       public static function rollback() {
-               $ret = false;
-
-               switch (self::$driver) {
-                       case 'pdo':
-                               if (!self::$db->inTransaction()) {
-                                       $ret = true;
-                                       break;
-                               }
-                               $ret = self::$db->rollBack();
-                               break;
-                       case 'mysqli':
-                               $ret = self::$db->rollback();
-                               break;
-               }
-               self::$in_transaction = false;
-               return $ret;
-       }
-
-       /**
-        * @brief Build the array with the table relations
-        *
-        * The array is build from the database definitions in DBStructure.php
-        *
-        * This process must only be started once, since the value is cached.
-        */
-       private static function buildRelationData() {
-               $definition = DBStructure::definition();
-
-               foreach ($definition AS $table => $structure) {
-                       foreach ($structure['fields'] AS $field => $field_struct) {
-                               if (isset($field_struct['relation'])) {
-                                       foreach ($field_struct['relation'] AS $rel_table => $rel_field) {
-                                               self::$relation[$rel_table][$rel_field][$table][] = $field;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       /**
-        * @brief Delete a row from a table
-        *
-        * @param string  $table       Table name
-        * @param array   $conditions  Field condition(s)
-        * @param array   $options
-        *                - cascade: If true we delete records in other tables that depend on the one we're deleting through
-        *                           relations (default: true)
-        * @param boolean $in_process  Internal use: Only do a commit after the last delete
-        * @param array   $callstack   Internal use: prevent endless loops
-        *
-        * @return boolean|array was the delete successful? When $in_process is set: deletion data
-        */
-       public static function delete($table, array $conditions, array $options = [], $in_process = false, array &$callstack = [])
-       {
-               if (empty($table) || empty($conditions)) {
-                       logger('Table and conditions have to be set');
-                       return false;
-               }
-
-               $commands = [];
-
-               // Create a key for the loop prevention
-               $key = $table . ':' . json_encode($conditions);
-
-               // We quit when this key already exists in the callstack.
-               if (isset($callstack[$key])) {
-                       return $commands;
-               }
-
-               $callstack[$key] = true;
-
-               $table = self::escape($table);
-
-               $commands[$key] = ['table' => $table, 'conditions' => $conditions];
-
-               $cascade = defaults($options, 'cascade', true);
-
-               // To speed up the whole process we cache the table relations
-               if ($cascade && count(self::$relation) == 0) {
-                       self::buildRelationData();
-               }
-
-               // Is there a relation entry for the table?
-               if ($cascade && isset(self::$relation[$table])) {
-                       // We only allow a simple "one field" relation.
-                       $field = array_keys(self::$relation[$table])[0];
-                       $rel_def = array_values(self::$relation[$table])[0];
-
-                       // Create a key for preventing double queries
-                       $qkey = $field . '-' . $table . ':' . json_encode($conditions);
-
-                       // When the search field is the relation field, we don't need to fetch the rows
-                       // This is useful when the leading record is already deleted in the frontend but the rest is done in the backend
-                       if ((count($conditions) == 1) && ($field == array_keys($conditions)[0])) {
-                               foreach ($rel_def AS $rel_table => $rel_fields) {
-                                       foreach ($rel_fields AS $rel_field) {
-                                               $retval = self::delete($rel_table, [$rel_field => array_values($conditions)[0]], $options, true, $callstack);
-                                               $commands = array_merge($commands, $retval);
-                                       }
-                               }
-                               // We quit when this key already exists in the callstack.
-                       } elseif (!isset($callstack[$qkey])) {
-
-                               $callstack[$qkey] = true;
-
-                               // Fetch all rows that are to be deleted
-                               $data = self::select($table, [$field], $conditions);
-
-                               while ($row = self::fetch($data)) {
-                                       // Now we accumulate the delete commands
-                                       $retval = self::delete($table, [$field => $row[$field]], $options, true, $callstack);
-                                       $commands = array_merge($commands, $retval);
-                               }
-
-                               self::close($data);
-
-                               // Since we had split the delete command we don't need the original command anymore
-                               unset($commands[$key]);
-                       }
-               }
-
-               if (!$in_process) {
-                       // Now we finalize the process
-                       $do_transaction = !self::$in_transaction;
-
-                       if ($do_transaction) {
-                               self::transaction();
-                       }
-
-                       $compacted = [];
-                       $counter = [];
-
-                       foreach ($commands AS $command) {
-                               $conditions = $command['conditions'];
-                               reset($conditions);
-                               $first_key = key($conditions);
-
-                               $condition_string = self::buildCondition($conditions);
-
-                               if ((count($command['conditions']) > 1) || is_int($first_key)) {
-                                       $sql = "DELETE FROM `" . $command['table'] . "`" . $condition_string;
-                                       logger(self::replaceParameters($sql, $conditions), LOGGER_DATA);
-
-                                       if (!self::e($sql, $conditions)) {
-                                               if ($do_transaction) {
-                                                       self::rollback();
-                                               }
-                                               return false;
-                                       }
-                               } else {
-                                       $key_table = $command['table'];
-                                       $key_condition = array_keys($command['conditions'])[0];
-                                       $value = array_values($command['conditions'])[0];
-
-                                       // Split the SQL queries in chunks of 100 values
-                                       // We do the $i stuff here to make the code better readable
-                                       $i = isset($counter[$key_table][$key_condition]) ? $counter[$key_table][$key_condition] : 0;
-                                       if (isset($compacted[$key_table][$key_condition][$i]) && count($compacted[$key_table][$key_condition][$i]) > 100) {
-                                               ++$i;
-                                       }
-
-                                       $compacted[$key_table][$key_condition][$i][$value] = $value;
-                                       $counter[$key_table][$key_condition] = $i;
-                               }
-                       }
-                       foreach ($compacted AS $table => $values) {
-                               foreach ($values AS $field => $field_value_list) {
-                                       foreach ($field_value_list AS $field_values) {
-                                               $sql = "DELETE FROM `" . $table . "` WHERE `" . $field . "` IN (" .
-                                                       substr(str_repeat("?, ", count($field_values)), 0, -2) . ");";
-
-                                               logger(self::replaceParameters($sql, $field_values), LOGGER_DATA);
-
-                                               if (!self::e($sql, $field_values)) {
-                                                       if ($do_transaction) {
-                                                               self::rollback();
-                                                       }
-                                                       return false;
-                                               }
-                                       }
-                               }
-                       }
-                       if ($do_transaction) {
-                               self::commit();
-                       }
-                       return true;
-               }
-
-               return $commands;
-       }
-
-       /**
-        * @brief Updates rows
-        *
-        * Updates rows in the database. When $old_fields is set to an array,
-        * the system will only do an update if the fields in that array changed.
-        *
-        * Attention:
-        * Only the values in $old_fields are compared.
-        * This is an intentional behaviour.
-        *
-        * Example:
-        * We include the timestamp field in $fields but not in $old_fields.
-        * Then the row will only get the new timestamp when the other fields had changed.
-        *
-        * When $old_fields is set to a boolean value the system will do this compare itself.
-        * When $old_fields is set to "true" the system will do an insert if the row doesn't exists.
-        *
-        * Attention:
-        * Only set $old_fields to a boolean value when you are sure that you will update a single row.
-        * When you set $old_fields to "true" then $fields must contain all relevant fields!
-        *
-        * @param string $table Table name
-        * @param array $fields contains the fields that are updated
-        * @param array $condition condition array with the key values
-        * @param array|boolean $old_fields array with the old field values that are about to be replaced (true = update on duplicate)
-        *
-        * @return boolean was the update successfull?
-        */
-       public static function update($table, $fields, $condition, $old_fields = []) {
-
-               if (empty($table) || empty($fields) || empty($condition)) {
-                       logger('Table, fields and condition have to be set');
-                       return false;
-               }
-
-               $table = self::escape($table);
-
-               $condition_string = self::buildCondition($condition);
-
-               if (is_bool($old_fields)) {
-                       $do_insert = $old_fields;
-
-                       $old_fields = self::selectFirst($table, [], $condition);
-
-                       if (is_bool($old_fields)) {
-                               if ($do_insert) {
-                                       $values = array_merge($condition, $fields);
-                                       return self::insert($table, $values, $do_insert);
-                               }
-                               $old_fields = [];
-                       }
-               }
-
-               $do_update = (count($old_fields) == 0);
-
-               foreach ($old_fields AS $fieldname => $content) {
-                       if (isset($fields[$fieldname])) {
-                               if ($fields[$fieldname] == $content) {
-                                       unset($fields[$fieldname]);
-                               } else {
-                                       $do_update = true;
-                               }
-                       }
-               }
-
-               if (!$do_update || (count($fields) == 0)) {
-                       return true;
-               }
-
-               $sql = "UPDATE `".$table."` SET `".
-                       implode("` = ?, `", array_keys($fields))."` = ?".$condition_string;
-
-               $params1 = array_values($fields);
-               $params2 = array_values($condition);
-               $params = array_merge_recursive($params1, $params2);
-
-               return self::e($sql, $params);
-       }
-
-       /**
-        * Retrieve a single record from a table and returns it in an associative array
-        *
-        * @brief Retrieve a single record from a table
-        * @param string $table
-        * @param array  $fields
-        * @param array  $condition
-        * @param array  $params
-        * @return bool|array
-        * @see dba::select
-        */
-       public static function selectFirst($table, array $fields = [], array $condition = [], $params = [])
-       {
-               $params['limit'] = 1;
-               $result = self::select($table, $fields, $condition, $params);
-
-               if (is_bool($result)) {
-                       return $result;
-               } else {
-                       $row = self::fetch($result);
-                       self::close($result);
-                       return $row;
-               }
-       }
-
-       /**
-        * @brief Select rows from a table
-        *
-        * @param string $table     Table name
-        * @param array  $fields    Array of selected fields, empty for all
-        * @param array  $condition Array of fields for condition
-        * @param array  $params    Array of several parameters
-        *
-        * @return boolean|object
-        *
-        * Example:
-        * $table = "item";
-        * $fields = array("id", "uri", "uid", "network");
-        *
-        * $condition = array("uid" => 1, "network" => 'dspr');
-        * or:
-        * $condition = array("`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr');
-        *
-        * $params = array("order" => array("id", "received" => true), "limit" => 10);
-        *
-        * $data = dba::select($table, $fields, $condition, $params);
-        */
-       public static function select($table, array $fields = [], array $condition = [], array $params = [])
-       {
-               if ($table == '') {
-                       return false;
-               }
-
-               $table = self::escape($table);
-
-               if (count($fields) > 0) {
-                       $select_fields = "`" . implode("`, `", array_values($fields)) . "`";
-               } else {
-                       $select_fields = "*";
-               }
-
-               $condition_string = self::buildCondition($condition);
-
-               $param_string = self::buildParameter($params);
-
-               $sql = "SELECT " . $select_fields . " FROM `" . $table . "`" . $condition_string . $param_string;
-
-               $result = self::p($sql, $condition);
-
-               return $result;
-       }
-
-       /**
-        * @brief Counts the rows from a table satisfying the provided condition
-        *
-        * @param string $table Table name
-        * @param array $condition array of fields for condition
-        *
-        * @return int
-        *
-        * Example:
-        * $table = "item";
-        *
-        * $condition = ["uid" => 1, "network" => 'dspr'];
-        * or:
-        * $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr'];
-        *
-        * $count = dba::count($table, $condition);
-        */
-       public static function count($table, array $condition = [])
-       {
-               if ($table == '') {
-                       return false;
-               }
-
-               $condition_string = self::buildCondition($condition);
-
-               $sql = "SELECT COUNT(*) AS `count` FROM `".$table."`".$condition_string;
-
-               $row = self::fetch_first($sql, $condition);
-
-               return $row['count'];
-       }
-
-       /**
-        * @brief Returns the SQL condition string built from the provided condition array
-        *
-        * This function operates with two modes.
-        * - Supplied with a filed/value associative array, it builds simple strict
-        *   equality conditions linked by AND.
-        * - Supplied with a flat list, the first element is the condition string and
-        *   the following arguments are the values to be interpolated
-        *
-        * $condition = ["uid" => 1, "network" => 'dspr'];
-        * or:
-        * $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr'];
-        *
-        * In either case, the provided array is left with the parameters only
-        *
-        * @param array $condition
-        * @return string
-        */
-       public static function buildCondition(array &$condition = [])
-       {
-               $condition_string = '';
-               if (count($condition) > 0) {
-                       reset($condition);
-                       $first_key = key($condition);
-                       if (is_int($first_key)) {
-                               $condition_string = " WHERE (" . array_shift($condition) . ")";
-                       } else {
-                               $new_values = [];
-                               $condition_string = "";
-                               foreach ($condition as $field => $value) {
-                                       if ($condition_string != "") {
-                                               $condition_string .= " AND ";
-                                       }
-                                       if (is_array($value)) {
-                                               /* 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.
-                                                */
-                                               $is_int = false;
-                                               $is_alpha = false;
-                                               foreach ($value as $single_value) {
-                                                       if (is_int($single_value)) {
-                                                               $is_int = true;
-                                                       } else {
-                                                               $is_alpha = true;
-                                                       }
-                                               }
-
-                                               if ($is_int && $is_alpha) {
-                                                       foreach ($value as &$ref) {
-                                                               if (is_int($ref)) {
-                                                                       $ref = (string)$ref;
-                                                               }
-                                                       }
-                                                       unset($ref); //Prevent accidental re-use.
-                                               }
-
-                                               $new_values = array_merge($new_values, array_values($value));
-                                               $placeholders = substr(str_repeat("?, ", count($value)), 0, -2);
-                                               $condition_string .= "`" . $field . "` IN (" . $placeholders . ")";
-                                       } else {
-                                               $new_values[$field] = $value;
-                                               $condition_string .= "`" . $field . "` = ?";
-                                       }
-                               }
-                               $condition_string = " WHERE (" . $condition_string . ")";
-                               $condition = $new_values;
-                       }
-               }
-
-               return $condition_string;
-       }
-
-       /**
-        * @brief Returns the SQL parameter string built from the provided parameter array
-        *
-        * @param array $params
-        * @return string
-        */
-       public static function buildParameter(array $params = [])
-       {
-               $order_string = '';
-               if (isset($params['order'])) {
-                       $order_string = " ORDER BY ";
-                       foreach ($params['order'] AS $fields => $order) {
-                               if (!is_int($fields)) {
-                                       $order_string .= "`" . $fields . "` " . ($order ? "DESC" : "ASC") . ", ";
-                               } else {
-                                       $order_string .= "`" . $order . "`, ";
-                               }
-                       }
-                       $order_string = substr($order_string, 0, -2);
-               }
-
-               $limit_string = '';
-               if (isset($params['limit']) && is_int($params['limit'])) {
-                       $limit_string = " LIMIT " . $params['limit'];
-               }
-
-               if (isset($params['limit']) && is_array($params['limit'])) {
-                       $limit_string = " LIMIT " . intval($params['limit'][0]) . ", " . intval($params['limit'][1]);
-               }
-
-               return $order_string.$limit_string;
-       }
-
-       /**
-        * @brief Fills an array with data from a query
-        *
-        * @param object $stmt statement object
-        * @return array Data array
-        */
-       public static function inArray($stmt, $do_close = true) {
-               if (is_bool($stmt)) {
-                       return $stmt;
-               }
-
-               $data = [];
-               while ($row = self::fetch($stmt)) {
-                       $data[] = $row;
-               }
-               if ($do_close) {
-                       self::close($stmt);
-               }
-               return $data;
-       }
-
-       /**
-        * @brief Returns the error number of the last query
-        *
-        * @return string Error number (0 if no error)
-        */
-       public static function errorNo() {
-               return self::$errorno;
-       }
-
-       /**
-        * @brief Returns the error message of the last query
-        *
-        * @return string Error message ('' if no error)
-        */
-       public static function errorMessage() {
-               return self::$error;
-       }
-
-       /**
-        * @brief Closes the current statement
-        *
-        * @param object $stmt statement object
-        * @return boolean was the close successful?
-        */
-       public static function close($stmt) {
-               $a = get_app();
-
-               $stamp1 = microtime(true);
-
-               if (!is_object($stmt)) {
-                       return false;
-               }
-
-               switch (self::$driver) {
-                       case 'pdo':
-                               $ret = $stmt->closeCursor();
-                               break;
-                       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.
-                               if ($stmt instanceof mysqli_stmt) {
-                                       $stmt->free_result();
-                                       $ret = $stmt->close();
-                               } elseif ($stmt instanceof mysqli_result) {
-                                       $stmt->free();
-                                       $ret = true;
-                               } else {
-                                       $ret = false;
-                               }
-                               break;
-               }
-
-               $a->save_timestamp($stamp1, 'database');
-
-               return $ret;
-       }
-}
+use Friendica\Database\dba;
 
 function dbesc($str) {
        if (dba::$connected) {
index 2d4cbdadb5a09a5f1ac461576b6dd77f969bfe39..30ebe5d1ac7320ede7a1e243119167c852e888e4 100644 (file)
@@ -8,10 +8,11 @@ use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
+use Friendica\Model\Item;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Emailer;
-use Friendica\Model\Item;
 
 /**
  * @brief Creates a notification entry and possibly sends a mail
@@ -679,7 +680,7 @@ function check_user_notification($itemid) {
  *
  * @param int $itemid ID of the item for which the check should be done
  * @param int $uid User ID
- * @param str $defaulttype (Optional) Forces a notification with this type.
+ * @param string $defaulttype (Optional) Forces a notification with this type.
  */
 function check_item_notification($itemid, $uid, $defaulttype = "") {
        $notification_data = ["uid" => $uid, "profiles" => []];
index e06df925e34ee9530c0c2f51d8c614175b00433b..14a74c8e51ea5afa0ff7e91cda3cd9aead2419b3 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Item;
 use Friendica\Protocol\DFRN;
index 768d7c82d45934310a7122b1ca94e56c2e437f0c..64f32bd55e237ae4d1b362376bfb1929996b25ec 100644 (file)
@@ -8,6 +8,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Group;
 use Friendica\Util\DateTimeFormat;
index a8098942c2353e1a8963929fde47b8c259070634..8cdef23ccbf70307be1ed79c0e05842227465c03 100644 (file)
--- a/index.php
+++ b/index.php
@@ -17,6 +17,7 @@ use Friendica\Core\Session;
 use Friendica\Core\System;
 use Friendica\Core\Theme;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Profile;
 use Friendica\Module\Login;
index dd5dd90281d0140782d45195dead24039635b8ae..32b86d90bbc338a703537d95068c5ab589155246 100644 (file)
@@ -6,6 +6,7 @@ use Friendica\App;
 use Friendica\Content\Widget;
 use Friendica\Core\ACL;
 use Friendica\Core\Addon;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
index 9fa54bc13717808e83a13924cb0f30c811aae6aa..9a289dda5a2365ce6950b820205fd069605121e0 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Theme;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Database\DBStructure;
 use Friendica\Model\Contact;
@@ -782,7 +783,7 @@ function admin_page_workerqueue(App $a)
        // get jobs from the workerqueue table
        $statement = dba::select('workerqueue', ['id', 'parameter', 'created', 'priority'], ['done' => 0], ['order'=> ['priority']]);
        $r = dba::inArray($statement);
-        
+
        for($i = 0; $i < count($r); $i++) {
                $r[$i]['parameter'] = stripslashes(implode(': ', explode('","', $r[$i]['parameter'])));
                $r[$i]['parameter'] = substr($r[$i]['parameter'], 2, -2);
index d85d3ec9b36938f015e3f197c154ed086d98c6f7..e9d964847c8daa842bf59cf13c427bcf2371e754 100644 (file)
@@ -2,10 +2,12 @@
 /**
  * @file mod/allfriends.php
  */
+
 use Friendica\App;
 use Friendica\Content\ContactSelector;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
index fd428286a6ec9d4ed655e442fe68950e86d2e389..0b88fe28fc4a769533a9a80a0b3937c8156dc32a 100644 (file)
@@ -2,8 +2,10 @@
 /**
  * @file mod/attach.php
  */
+
 use Friendica\App;
 use Friendica\Core\L10n;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 
 require_once 'include/dba.php';
index bf73408f4249f821fb54b8654e17f86f1c16dd0e..246d8a6447b6c7376fc3e00711a5ab6229422ce5 100644 (file)
@@ -13,6 +13,7 @@ use Friendica\Content\Widget;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Event;
index f45bbb0175c1498d344fb542ac7f526e4ad80602..f6f826789bc23461b9c1eba6a50523a3cb3ba8e1 100644 (file)
@@ -2,9 +2,11 @@
 /**
  * @file include/common.php
  */
+
 use Friendica\App;
 use Friendica\Content\ContactSelector;
 use Friendica\Core\L10n;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
index 1e6162fb8e57b2b5b890c4226f9f89efa8c28780..97ecf00831567a48afc8858f6f161a462d5ff465 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Core\ACL;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 
 function community_init(App $a)
index a4caafe8f9cd8b2e4f2e5b7d1f1af11cc7efafed..736d16dfb94cdf279634b0425bed461c26097cec 100644 (file)
@@ -12,6 +12,7 @@ use Friendica\Core\Addon;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
index 29b00b4e3aab3a6848837636e5c45406a5edbb34..e23e082240c8ee4d14d7f006971f1dbd4dcc6316 100644 (file)
@@ -2,9 +2,11 @@
 /**
  * @file mod/crepair.php
  */
+
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
index 510fc0ec8ff11b7730b53de657f5bda941f81832..60cf13046455832bc9038d0064723b5a7f97cf94 100644 (file)
@@ -2,9 +2,11 @@
 /**
  * @file mod/delegate.php
  */
+
 use Friendica\App;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\User;
 
index 0bcf137857ab5a2ca6f3e8614e4327dfd4e7451a..32a9d59f9e874111fa3b98526e666734bf8cfbdc 100644 (file)
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
 use Friendica\Core\System;
-use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
-use Friendica\Model\Item;
 use Friendica\Model\User;
 use Friendica\Network\Probe;
 use Friendica\Protocol\Diaspora;
index bfbf4c657a449aec03ab3087ebe0e9a33bea767f..e3569965720af8b5b400df5e236ab745841f041e 100644 (file)
@@ -9,6 +9,7 @@
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Protocol\DFRN;
index d6bc1727e70f6d04b020e1e6c38f6e9907ce7650..32a8013c3169d4cf61e8e41c430f2cd964e73251 100644 (file)
@@ -3,10 +3,12 @@
 /**
  * @file mod/dfrn_poll.php
  */
+
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Module\Login;
 use Friendica\Protocol\DFRN;
index b7a0dd7487e6fbbf566c7beb1eb435bcdad7ffb0..8713785ad4e983410bc836b24a52aa486d94595d 100644 (file)
@@ -15,8 +15,8 @@
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
index a83b1b76ceb6f9aebb60598d2acdf4528227cd95..85bcbf81303085e63c8fcd775bd41d7f2d42158c 100644 (file)
@@ -2,12 +2,14 @@
 /**
  * @file mod/directory.php
  */
+
 use Friendica\App;
 use Friendica\Content\Nav;
 use Friendica\Content\Widget;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
index d72c2d43d4115ecbec70acffb3c29d776cf22ab9..257c8b11aa44be12f7637feb9557a0449be28e97 100644 (file)
@@ -2,6 +2,7 @@
 /**
  * @file mod/dirfind.php
  */
+
 use Friendica\App;
 use Friendica\Content\ContactSelector;
 use Friendica\Content\Widget;
@@ -9,12 +10,13 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
+use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Network\Probe;
 use Friendica\Protocol\PortableContact;
 use Friendica\Util\Network;
-use Friendica\Database\DBM;
 
 require_once 'mod/contacts.php';
 
index 2600dfd26d020e06d409b8d31a52faf7c2ea147e..3775d263c851b42893c1d633e71e2d1990e9730e 100644 (file)
@@ -11,6 +11,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
index 9217b85d541ffe3190eae9f701d0e406d847e776..a96b1f5d031c78537b8e85c49cafbbac1d58763b 100644 (file)
@@ -6,6 +6,7 @@
 
 use Friendica\App;
 use Friendica\Core\L10n;
+use Friendica\Database\dba;
 use Friendica\Model\Contact;
 use Friendica\Protocol\Feed;
 use Friendica\Util\Network;
index 0e8cc80f27ae962453b57988f4d005d037c3e890..dfec16854113bea9ada0a4fdbd1ee704fb129645 100644 (file)
@@ -7,12 +7,13 @@
  * Author: Rabuzarus <https://github.com/rabuzarus>
  * License: GNU AFFERO GENERAL PUBLIC LICENSE (Version 3)
  */
+
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
-use Friendica\Model\Profile;
 
 function hovercard_init(App $a)
 {
index 55a7cdd7fdc5c92d15ea696fe2b9def67bd9ab30..59dcf92c56cba012850c7ef2e365b55038a99310 100644 (file)
@@ -4,9 +4,10 @@
  */
 
 use Friendica\App;
-use Friendica\Core\L10n;
 use Friendica\Core\Install;
+use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Util\Temporal;
 
index 2359b79c582ec9981fed38aee2ebdee82f28fd95..7bcfdfbe35934ecebb2d8260739c711f9b9cf9eb 100644 (file)
 
 use Friendica\App;
 use Friendica\Content\Text\BBCode;
+use Friendica\Content\Text\HTML;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
@@ -812,7 +814,7 @@ function item_post(App $a) {
                                        'replyTo' => $a->user['email'],
                                        'messageSubject' => $subject,
                                        'htmlVersion' => $message,
-                                       'textVersion' => Friendica\Content\Text\HTML::toPlaintext($html.$disclaimer)
+                                       'textVersion' => HTML::toPlaintext($html.$disclaimer)
                                ];
                                Emailer::send($params);
                        }
index 0d22252bdc723cf948564dcfd1fd5872fb995415..07c24f158016df4519234e0b5a10c29fe18efd05 100644 (file)
@@ -4,8 +4,10 @@
  */
 
 use Friendica\App;
+use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
index b414fe0e49f6110371dbeb6a6c7bec1a0a533f8f..ccdb377b2f2a6f8c67098d8ff016c0044fd5da7a 100644 (file)
@@ -10,6 +10,7 @@ use Friendica\Content\Text\BBCode;
 use Friendica\Core\ACL;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Mail;
index 67dd651e225e521b1a5849f19d41a384d956b50e..af9e111c9fd89de98f11d3cc278323ca98d48eee 100644 (file)
@@ -15,6 +15,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
index fad7246075938e6f12f70a9098d24a909396b783..57b083a7612c9edb3e439d073c0838849afb163c 100644 (file)
@@ -7,8 +7,9 @@
 
 use Friendica\App;
 use Friendica\Core\Addon;
-use Friendica\Core\System;
 use Friendica\Core\Config;
+use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Util\Network;
 require_once 'include/dba.php';
 
index 20936929ddd6672787d7dce4e3860f86dde557c6..d17937ff5d39fb7b9cee7b37333902ef7a4e6bcf 100644 (file)
@@ -2,8 +2,10 @@
 /**
  * @file mod/noscrape.php
  */
+
 use Friendica\App;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Profile;
 
index 69a5280f7e6dd265b71e8d18f86b12ff61fe094e..af7bd71793bc854b656c17f020df7e39198c6b7b 100644 (file)
@@ -2,12 +2,14 @@
 /**
  * @file mod/notes.php
  */
+
 use Friendica\App;
 use Friendica\Content\Nav;
 use Friendica\Core\L10n;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Model\Profile;
 use Friendica\Model\Item;
+use Friendica\Model\Profile;
 
 function notes_init(App $a)
 {
index b113be030d8337cc95f19d744e4f9a57f2671443..0b7ac14d45e68378189ab6ae5d9893508c3dae4e 100644 (file)
@@ -3,12 +3,14 @@
  * @file mod/notifications.php
  * @brief The notifications module
  */
+
 use Friendica\App;
 use Friendica\Content\ContactSelector;
 use Friendica\Content\Nav;
 use Friendica\Core\L10n;
 use Friendica\Core\NotificationsManager;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 
 function notifications_post(App $a)
index bd1de938c89b6c38eaedd0b8db0668ea16c02925..4058ac5c18fdfcb3cbaf684983b74260775167d4 100644 (file)
@@ -13,6 +13,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
index 08c0dfdb86a9e4e16928d81ba2584e67568075df..6ac7d41fe08047701ba3385b086516a802cd45f0 100644 (file)
@@ -12,6 +12,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
index 3ceb8c664599f5cb92fb9c888c57013a0fa9ad26..db4a7deae5ba82633cbbed9982a384595c2a4575 100644 (file)
@@ -13,10 +13,10 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
-use Friendica\Model\Item;
 use Friendica\Model\Profile;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
index ca8ced3cd6751292dd06c2b3b0198d0ce0d0b06c..6dc396787664ff64211f5d3c9a4bc2987a6be7fe 100644 (file)
@@ -7,6 +7,7 @@
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Photo;
 use Friendica\Object\Image;
index a68b222ec4bbbcfd2d876b663c275ea571242fcf..fb6de40523945d1aa254998b636777fcb5ee0588 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 use Friendica\App;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Protocol\OStatus;
 
index 6ee7955e0757bdb8646d42948881bee714f3e622..53b9c01c157e7ecebda7240d0a118993b95bd630 100644 (file)
@@ -3,9 +3,10 @@
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Util\Network;
 use Friendica\Model\PushSubscriber;
+use Friendica\Util\Network;
 
 function post_var($name) {
        return (x($_POST, $name)) ? notags(trim($_POST[$name])) : '';
index adb758e384451386158d16727b1717b23fb26233..e9f26e027b5588a512e3c483e67f091f70b13bd3 100644 (file)
@@ -7,6 +7,7 @@
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Protocol\Diaspora;
 
index e448aa36d3f200eb52a61ebc81d103774d3460c0..8f112a3c5d24938d83d8dd4b16df8ff14f6ff332 100644 (file)
@@ -3,6 +3,7 @@
 use Friendica\App;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
index 2b7df0bd13dcdba7d320f82528bb6500a16d8c9e..b96cd02448b85fa34178daa224784873d97142eb 100644 (file)
@@ -8,6 +8,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\User;
 use Friendica\Module\Login;
index dd0ca0f81ffd790d0d35ba8856d610a8642e12ed..adc788983efd9a5ef3381e41f1e5e7be5334cf22 100644 (file)
@@ -7,6 +7,7 @@ use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\User;
 
index 8f89e72001078905eab52d6cf59a73eb10af8614..b425464dcc40bb2f31e2c1e9d14fb35fd2683606 100644 (file)
@@ -2,6 +2,7 @@
 /**
  * @file mod/search.php
  */
+
 use Friendica\App;
 use Friendica\Content\Feature;
 use Friendica\Content\Nav;
@@ -9,6 +10,7 @@ use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Item;
 
index ff969d65eb24d8654f98df9197498ec02a4c3890..c4a114ab810c6ea04f3d19974f97d48259df22cf 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Core\Theme;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
index b1b6e83dac9476d6aa38cd3954307d5eb567ea40..86c11803bebad4d24bbb13d01ff3e0443032839f 100644 (file)
@@ -2,15 +2,16 @@
 /**
  * @file mod/suggest.php
  */
+
 use Friendica\App;
 use Friendica\Content\ContactSelector;
 use Friendica\Content\Widget;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
-use Friendica\Model\Profile;
 
 function suggest_init(App $a) {
        if (! local_user()) {
index 6059c27ab7e2403c0a05a657dd7b480ddc48b532..9ee92b3ba9ed7fff5ace231e4a43907697ace40f 100644 (file)
@@ -2,9 +2,11 @@
 /**
  * @file mod/unfollow.php
  */
+
 use Friendica\App;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
index 29c790843a7dd8ef4513b08c7fe835735a1ea6eb..69763c2fe5f17a3b3155007c1838e863aee71a4a 100644 (file)
@@ -7,6 +7,7 @@ use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Mimetype;
index 5659d825e71326a52aa78e1782af54effc9e2fb8..da354445f4588b24c7396fc18dbe1ee56647af71 100644 (file)
@@ -6,6 +6,7 @@
 
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Util\DateTimeFormat;
 
 function worker_init()
index 29ee1057a2696c34442e595c375e13d4bab7d353..230cdbf63776944f94a3488d08b4cd8eedf8ac16 100644 (file)
@@ -2,9 +2,11 @@
 /**
  * @file mod/xrd.php
  */
+
 use Friendica\App;
 use Friendica\Core\Addon;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Protocol\Salmon;
 
index e1843e5737dc99f318bf3f590d8e658a13c9c917..0359d8309c12fca1859e835a620872ab717bfc8d 100644 (file)
@@ -4,16 +4,14 @@
  */
 namespace Friendica;
 
+use Detection\MobileDetect;
+use Exception;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use dba;
-
-use Detection\MobileDetect;
-
-use Exception;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
@@ -492,13 +490,13 @@ class App
 
                $this->mode |= App::MODE_LOCALCONFIGPRESENT;
 
-               if (!\dba::connected()) {
+               if (!dba::connected()) {
                        return;
                }
 
                $this->mode |= App::MODE_DBAVAILABLE;
 
-               if (\dba::fetch_first("SHOW TABLES LIKE 'config'") === false) {
+               if (dba::fetch_first("SHOW TABLES LIKE 'config'") === false) {
                        return;
                }
 
@@ -513,7 +511,7 @@ class App
 
        public function loadDatabase()
        {
-               if (\dba::connected()) {
+               if (dba::connected()) {
                        return;
                }
 
@@ -544,7 +542,7 @@ class App
 
                $stamp1 = microtime(true);
 
-               \dba::connect($db_host, $db_user, $db_pass, $db_data, $charset);
+               dba::connect($db_host, $db_user, $db_pass, $db_data, $charset);
                unset($db_host, $db_user, $db_pass, $db_data, $charset);
 
                $this->save_timestamp($stamp1, 'network');
index 06972c36d9f3be9ab16e240482c1f4763f29b15d..47df84f7a6f6d266acbe7a0c5dd1b5a40d05a665 100644 (file)
@@ -6,9 +6,8 @@ namespace Friendica\Content;
 
 use Friendica\Core\Addon;
 use Friendica\Core\L10n;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Protocol\Diaspora;
-use dba;
 
 /**
  * @brief ContactSelector class
index e45dd0c4215a5722638833190347894cfe4e6352..edbe0b64e98deb382d0edd01d0534636ca68d282 100644 (file)
@@ -5,13 +5,12 @@
  */
 namespace Friendica\Content;
 
-use Friendica\App;
 use Friendica\Content\Feature;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
-use Friendica\Model\Contact;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use dba;
+use Friendica\Model\Contact;
 
 require_once 'include/dba.php';
 
index 92ca714df876bec43ca25f13d646568b4c3a97c7..5f47875098c461cdd2537786fc20cbf0231fcf53 100644 (file)
@@ -10,9 +10,9 @@ use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Profile;
-use dba;
 
 require_once 'boot.php';
 require_once 'dba.php';
index 390f3ea868435a3c035d9f9f7e9deceab24f5fec..70556839e933bb4b17b8a4a70680f8ad3627be79 100644 (file)
@@ -5,21 +5,21 @@
  */
 namespace Friendica\Content;
 
+use DOMDocument;
+use DOMNode;
+use DOMText;
+use DOMXPath;
+use Exception;
 use Friendica\Core\Addon;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
-use dba;
-use DOMDocument;
-use DOMNode;
-use DOMText;
-use DOMXPath;
-use Exception;
 use stdClass;
 
 require_once 'include/dba.php';
index ba575201244205548276e11d591bb197c64b22d3..76d51961c6d057f528d32dbfddac15cc23382cc4 100644 (file)
@@ -11,11 +11,11 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Model\Profile;
-use dba;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
index 53c4daae4512ea522d49a484031415ba94365e3f..9160dd579f00f36a354a609aa394a8443b898f2b 100644 (file)
@@ -6,9 +6,9 @@
 
 namespace Friendica\Content\Widget;
 
-use dba;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 
 require_once 'include/dba.php';
index 4e8bf6abde2e5eb85a786b08a632cbafd92fc304..95948af293c18870c69395313e22291df9727820 100644 (file)
@@ -6,27 +6,13 @@
 
 namespace Friendica\Core;
 
-use dba;
 use Friendica\BaseObject;
 use Friendica\Content\Feature;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Util\Network;
-use const CONTACT_IS_FRIEND;
-use const NETWORK_DFRN;
-use const NETWORK_DIASPORA;
-use const NETWORK_FACEBOOK;
-use const NETWORK_MAIL;
-use const NETWORK_OSTATUS;
-use const PHP_EOL;
-use function dbesc;
-use function defaults;
-use function get_markup_template;
-use function get_server;
-use function local_user;
-use function remote_user;
-use function replace_macros;
 
 /**
  * Handle ACL management and display
index 50247d240f42fbffb1480493273b3416412c59a4..eb2b7d1aac6b6e22630d20ed45d8d77c913d4cd1 100644 (file)
@@ -4,11 +4,9 @@
  */
 namespace Friendica\Core;
 
-use Friendica\Core\Config;
+use Friendica\App;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Core\Worker;
-
-use dba;
 
 require_once 'include/dba.php';
 
@@ -228,12 +226,12 @@ class Addon
        /**
         * @brief Calls a single hook.
         *
-        * @param \Friendica\App $a
+        * @param App $a
         * @param string         $name of the hook to call
         * @param array          $hook Hook data
         * @param string|array   &$data to transmit to the callback handler
         */
-       public static function callSingleHook(\Friendica\App $a, $name, $hook, &$data = null)
+       public static function callSingleHook(App $a, $name, $hook, &$data = null)
        {
                // Don't run a theme's hook if the user isn't using the theme
                if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . $a->getCurrentTheme()) === false) {
index 059fef3290626779252fded72a321e1e7df81fbb..2e14567704336cd29149d166d6a32cd2a61c5927 100644 (file)
@@ -2,8 +2,8 @@
 
 namespace Friendica\Core\Cache;
 
-use dba;
 use Friendica\Core\Cache;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Util\DateTimeFormat;
 
index 527c718ae0a2a6648d63f08303994b172d5a1fdc..77902ffc82dfab07d8d2b3e96c8ba838eabb04b6 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 namespace Friendica\Core\Config;
 
-use dba;
 use Friendica\BaseObject;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 
 require_once 'include/dba.php';
index ffd807a3628a0f67e1e42f2f90e0d3f47ae2afee..6840fe7127570f8ca5c8a7a7bf8f89b48c09be78 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 namespace Friendica\Core\Config;
 
-use dba;
 use Friendica\BaseObject;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 
 require_once 'include/dba.php';
index 204e462948e4d5cde40ac5edd83948868e78863e..7a97854a43fc0dd1a75afc711e919e41d99acded 100644 (file)
@@ -2,10 +2,9 @@
 
 namespace Friendica\Core\Config;
 
-use dba;
 use Exception;
-use Friendica\App;
 use Friendica\BaseObject;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 
 require_once 'include/dba.php';
index 8ed3ee10e82b9b4c75291af78a3d7e0157af5c81..36b0f36362ccbf5c9aa2029355a4db3d08573d60 100644 (file)
@@ -2,10 +2,9 @@
 
 namespace Friendica\Core\Config;
 
-use dba;
 use Exception;
-use Friendica\App;
 use Friendica\BaseObject;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 
 require_once 'include/dba.php';
index 63ace91c0f3867ed4b3470de79d722cf785aa48b..fda398c8a2fd7a6ef1247ecfc4368f7c1e1bba8d 100644 (file)
@@ -2,8 +2,10 @@
 
 namespace Friendica\Core\Console;
 
+use Friendica\App;
 use Friendica\Core\L10n;
-use dba;
+use Friendica\Database\dba;
+use RuntimeException;
 
 /**
  * @brief tool to archive a contact on the server
@@ -55,19 +57,19 @@ HELP;
                }
 
                if ($a->mode === App::MODE_INSTALL) {
-                       throw new \RuntimeException('Friendica isn\'t properly installed yet.');
+                       throw new RuntimeException('Friendica isn\'t properly installed yet.');
                }
 
                $nurl = normalise_link($this->getArgument(0));
                if (!dba::exists('contact', ['nurl' => $nurl, 'archive' => false])) {
-                       throw new \RuntimeException(L10n::t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
+                       throw new RuntimeException(L10n::t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
                }
                if (dba::update('contact', ['archive' => true], ['nurl' => $nurl])) {
                        $condition = ["`cid` IN (SELECT `id` FROM `contact` WHERE `archive`)"];
                        dba::delete('queue', $condition);
                        $this->out(L10n::t('The contact entries have been archived'));
                } else {
-                       throw new \RuntimeException('The contact archival failed.');
+                       throw new RuntimeException('The contact archival failed.');
                }
 
                return 0;
index 4822368ab5cf9657772cba80331d70272e746a75..76735ec9aeaefad160f8d865c93832461c64ad28 100644 (file)
@@ -3,11 +3,11 @@
 namespace Friendica\Core\Console;
 
 use Asika\SimpleConsole\Console;
-use dba;
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\Install;
 use Friendica\Core\Theme;
+use Friendica\Database\dba;
 use RuntimeException;
 
 require_once 'mod/install.php';
index c37dd26b15ddb3cbbf81c5d80e07c1fae16b5f54..daa0ba60a8caaa90674d560d702dcd3720b322a2 100644 (file)
@@ -9,8 +9,9 @@
 namespace Friendica\Core\Console;
 
 use Asika\SimpleConsole\CommandArgsException;
-use dba;
+use Friendica\App;
 use Friendica\Core;
+use RuntimeException;
 
 require_once 'include/dba.php';
 require_once 'include/text.php';
@@ -92,7 +93,7 @@ HELP;
                        throw new CommandArgsException('Too many arguments');
                }
 
-               if (!($a->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE)) {
+               if (!($a->mode & App::MODE_DBCONFIGAVAILABLE)) {
                        $this->out('Database isn\'t ready or populated yet, showing file config only');
                }
 
@@ -102,7 +103,7 @@ HELP;
                        $value = $this->getArgument(2);
 
                        if (is_array(Core\Config::get($cat, $key))) {
-                               throw new \RuntimeException("$cat.$key is an array and can't be set using this command.");
+                               throw new RuntimeException("$cat.$key is an array and can't be set using this command.");
                        }
 
                        $result = Core\Config::set($cat, $key, $value);
@@ -151,7 +152,7 @@ HELP;
                if (count($this->args) == 0) {
                        Core\Config::load();
 
-                       if (Core\Config::get('system', 'config_adapter') == 'jit' && $a->mode & \Friendica\App::MODE_DBCONFIGAVAILABLE) {
+                       if (Core\Config::get('system', 'config_adapter') == 'jit' && $a->mode & App::MODE_DBCONFIGAVAILABLE) {
                                $this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only');
                        }
 
index 11904843102a64aa4e34fd9d6031c1c922c37beb..8c26987d2cbfc3b458d732ccad29b27808a056d1 100644 (file)
@@ -3,7 +3,9 @@
 namespace Friendica\Core\Console;
 
 use Friendica\Core;
+use Friendica\Database\dba;
 use Friendica\Database\DBStructure;
+use RuntimeException;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
@@ -56,8 +58,8 @@ HELP;
                        throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
                }
 
-               if (!\dba::connected()) {
-                       throw new \RuntimeException('Unable to connect to database');
+               if (!dba::connected()) {
+                       throw new RuntimeException('Unable to connect to database');
                }
 
                Core\Config::load();
index ccd6014e9c727bfbd7f9731d7d0723c445b6c557..6330d08a12afc3f8055f733aae8673d8e0e18ad7 100644 (file)
@@ -3,8 +3,10 @@
 namespace Friendica\Core\Console;
 
 use Friendica\Core\Protocol;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Network\Probe;
+use RuntimeException;
 
 require_once 'include/text.php';
 
@@ -65,7 +67,7 @@ HELP;
                }
 
                if ($a->isInstallMode()) {
-                       throw new \RuntimeException('Database isn\'t ready or populated yet');
+                       throw new RuntimeException('Database isn\'t ready or populated yet');
                }
 
                /**
@@ -75,16 +77,16 @@ HELP;
                 * */
                $net = Probe::uri($this->getArgument(0));
                if (in_array($net['network'], [Protocol::PHANTOM, Protocol::MAIL])) {
-                       throw new \RuntimeException('This account seems not to exist.');
+                       throw new RuntimeException('This account seems not to exist.');
                }
 
                $nurl = normalise_link($net['url']);
-               $contact = \dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
+               $contact = dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
                if (DBM::is_result($contact)) {
-                       \dba::update("contact", ["hidden" => true], ["id" => $contact["id"]]);
+                       dba::update("contact", ["hidden" => true], ["id" => $contact["id"]]);
                        $this->out('NOTICE: The account should be silenced from the global community page');
                } else {
-                       throw new \RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')');
+                       throw new RuntimeException('NOTICE: Could not find any entry for this URL (' . $nurl . ')');
                }
 
                return 0;
index 003597472716c990e1fab7560623ddbf39060e74..cdf31422d157a90b1b25ff0a3364ad50ab579f8d 100644 (file)
@@ -2,12 +2,12 @@
 
 namespace Friendica\Core\Console;
 
-use Friendica\Core\L10n;
-use Friendica\Model\Contact;
-use Friendica\Model\User;
 use Friendica\Core\Config;
+use Friendica\Core\L10n;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use dba;
+use Friendica\Model\User;
+use RuntimeException;
 
 /**
  * @brief tool to set a new password for a user
@@ -59,14 +59,14 @@ HELP;
                }
 
                if ($a->isInstallMode()) {
-                       throw new \RuntimeException('Database isn\'t ready or populated yet');
+                       throw new RuntimeException('Database isn\'t ready or populated yet');
                }
 
                $nick = $this->getArgument(0);
 
                $user = dba::selectFirst('user', ['uid'], ['nickname' => $nick]);
                if (!DBM::is_result($user)) {
-                       throw new \RuntimeException(L10n::t('User not found'));
+                       throw new RuntimeException(L10n::t('User not found'));
                }
 
                $password = $this->getArgument(1);
@@ -76,15 +76,15 @@ HELP;
                }
 
                if (!$password) {
-                       throw new \RuntimeException(L10n::t('Password can\'t be empty'));
+                       throw new RuntimeException(L10n::t('Password can\'t be empty'));
                }
 
                if (!Config::get('system', 'disable_password_exposed', false) && User::isPasswordExposed($password)) {
-                       throw new \RuntimeException(L10n::t('The new password has been exposed in a public data dump, please choose another.'));
+                       throw new RuntimeException(L10n::t('The new password has been exposed in a public data dump, please choose another.'));
                }
 
                if (!User::updatePassword($user['uid'], $password)) {
-                       throw new \RuntimeException(L10n::t('Password update failed. Please try again.'));
+                       throw new RuntimeException(L10n::t('Password update failed. Please try again.'));
                }
 
                $this->out(L10n::t('Password changed.'));
index 2389817021b2a5bc26e9e511f94ec8a4df7f1ef5..32f87a4703c9728d7076ff4ae9e6d6f57f79a1f6 100644 (file)
@@ -4,8 +4,8 @@
  */
 namespace Friendica\Core;
 
-use Friendica\Core\Config;
-use dba;
+use Friendica\BaseObject;
+use Friendica\Database\dba;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
@@ -14,7 +14,7 @@ require_once 'include/dba.php';
  * Provide Languange, Translation, and Localisation functions to the application
  * Localisation can be referred to by the numeronym L10N (as in: "L", followed by ten more letters, and then "N").
  */
-class L10n extends \Friendica\BaseObject
+class L10n extends BaseObject
 {
        /**
         * @brief get the prefered language from the HTTP_ACCEPT_LANGUAGE header
index fc057c6b55a8c2c91a171e0a9a544f92d0ee4565..10612a91e4abdb8ddf78c2a6a463cb439bf080f0 100644 (file)
@@ -2,8 +2,8 @@
 
 namespace Friendica\Core\Lock;
 
-use dba;
 use Friendica\Core\Cache;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Util\DateTimeFormat;
 
index 6605abf79bf5245859fcc8674e19a987a796b98d..1154206d3c080a22d25079e3fac63778f9c9cc25 100644 (file)
@@ -9,17 +9,12 @@ namespace Friendica\Core;
 use Friendica\BaseObject;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
-use Friendica\Core\System;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
-use Friendica\Model\Profile;
 use Friendica\Model\Item;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Temporal;
 use Friendica\Util\XML;
-use dba;
 
 require_once 'include/dba.php';
 
index f69531a8882ebb954f0e3324ae331b1dc70e7f49..82cb36aacb6d6e852f5be72db5d716b8b968879b 100644 (file)
@@ -4,9 +4,9 @@ namespace Friendica\Core\Session;
 
 use Friendica\BaseObject;
 use Friendica\Core\Session;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use SessionHandlerInterface;
-use dba;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
index 0832dae45a49453398d0c241b3800c56f056ad3b..1b25a66ba002c5b6ac4ed348d0cfb4ae567c0814 100644 (file)
@@ -5,14 +5,9 @@
 namespace Friendica\Core;
 
 use Friendica\App;
-use Friendica\Core\L10n;
-use Friendica\Core\System;
-use Friendica\Core\PConfig;
-use Friendica\Core\Worker;
-use Friendica\Database\DBM;
+use Friendica\Database\dba;
 use Friendica\Model\Photo;
 use Friendica\Object\Image;
-use dba;
 
 require_once "include/dba.php";
 
index 897a80111d67d4d6cc6c7309c8ee645ae3894d02..fbd162615f0f8a1a29c93762f43e27ec152de310 100644 (file)
@@ -4,7 +4,7 @@
  */
 namespace Friendica\Core;
 
-use dba;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Process;
 use Friendica\Util\DateTimeFormat;
diff --git a/src/Database/DBA.php b/src/Database/DBA.php
new file mode 100644 (file)
index 0000000..5635beb
--- /dev/null
@@ -0,0 +1,1525 @@
+<?php
+
+namespace Friendica\Database;
+
+// Do not use Core\Config in this class at risk of infinite loop.
+// Please use App->getConfigVariable() instead.
+//use Friendica\Core\Config;
+
+use Friendica\Core\System;
+use Friendica\Util\DateTimeFormat;
+use PDO;
+use PDOException;
+use PDOStatement;
+
+/**
+ * @class MySQL database class
+ *
+ * This class is for the low level database stuff that does driver specific things.
+ */
+class dba
+{
+       public static $connected = false;
+
+       private static $server_info = '';
+       private static $db;
+       private static $driver;
+       private static $error = false;
+       private static $errorno = 0;
+       private static $affected_rows = 0;
+       private static $in_transaction = false;
+       private static $in_retrial = false;
+       private static $relation = [];
+       private static $db_serveraddr = '';
+       private static $db_user = '';
+       private static $db_pass = '';
+       private static $db_name = '';
+       private static $db_charset = '';
+
+       public static function connect($serveraddr, $user, $pass, $db, $charset = null)
+       {
+               if (!is_null(self::$db) && self::connected()) {
+                       return true;
+               }
+
+               // We are storing these values for being able to perform a reconnect
+               self::$db_serveraddr = $serveraddr;
+               self::$db_user = $user;
+               self::$db_pass = $pass;
+               self::$db_name = $db;
+               self::$db_charset = $charset;
+
+               $serveraddr = trim($serveraddr);
+
+               $serverdata = explode(':', $serveraddr);
+               $server = $serverdata[0];
+
+               if (count($serverdata) > 1) {
+                       $port = trim($serverdata[1]);
+               }
+
+               $server = trim($server);
+               $user = trim($user);
+               $pass = trim($pass);
+               $db = trim($db);
+               $charset = trim($charset);
+
+               if (!(strlen($server) && strlen($user))) {
+                       return false;
+               }
+
+               if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
+                       self::$driver = 'pdo';
+                       $connect = "mysql:host=".$server.";dbname=".$db;
+
+                       if (isset($port)) {
+                               $connect .= ";port=".$port;
+                       }
+
+                       if ($charset) {
+                               $connect .= ";charset=".$charset;
+                       }
+
+                       try {
+                               self::$db = @new PDO($connect, $user, $pass);
+                               self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
+                               self::$connected = true;
+                       } catch (PDOException $e) {
+                       }
+               }
+
+               if (!self::$connected && class_exists('mysqli')) {
+                       self::$driver = 'mysqli';
+                       self::$db = @new mysqli($server, $user, $pass, $db, $port);
+                       if (!mysqli_connect_errno()) {
+                               self::$connected = true;
+
+                               if ($charset) {
+                                       self::$db->set_charset($charset);
+                               }
+                       }
+               }
+
+               // No suitable SQL driver was found.
+               if (!self::$connected) {
+                       self::$driver = null;
+                       self::$db = null;
+               }
+
+               return self::$connected;
+       }
+
+       /**
+        * Disconnects the current database connection
+        */
+       public static function disconnect()
+       {
+               if (is_null(self::$db)) {
+                       return;
+               }
+
+               switch (self::$driver) {
+                       case 'pdo':
+                               self::$db = null;
+                               break;
+                       case 'mysqli':
+                               self::$db->close();
+                               self::$db = null;
+                               break;
+               }
+       }
+
+       /**
+        * Perform a reconnect of an existing database connection
+        */
+       public static function reconnect() {
+               self::disconnect();
+
+               $ret = self::connect(self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset);
+               return $ret;
+       }
+
+       /**
+        * Return the database object.
+        * @return PDO|mysqli
+        */
+       public static function get_db()
+       {
+               return self::$db;
+       }
+
+       /**
+        * @brief Returns the MySQL server version string
+        *
+        * This function discriminate between the deprecated mysql API and the current
+        * object-oriented mysqli API. Example of returned string: 5.5.46-0+deb8u1
+        *
+        * @return string
+        */
+       public static function server_info() {
+               if (self::$server_info == '') {
+                       switch (self::$driver) {
+                               case 'pdo':
+                                       self::$server_info = self::$db->getAttribute(PDO::ATTR_SERVER_VERSION);
+                                       break;
+                               case 'mysqli':
+                                       self::$server_info = self::$db->server_info;
+                                       break;
+                       }
+               }
+               return self::$server_info;
+       }
+
+       /**
+        * @brief Returns the selected database name
+        *
+        * @return string
+        */
+       public static function database_name() {
+               $ret = self::p("SELECT DATABASE() AS `db`");
+               $data = self::inArray($ret);
+               return $data[0]['db'];
+       }
+
+       /**
+        * @brief Analyze a database query and log this if some conditions are met.
+        *
+        * @param string $query The database query that will be analyzed
+        */
+       private static function logIndex($query) {
+               $a = get_app();
+
+               if (!$a->getConfigVariable('system', 'db_log_index')) {
+                       return;
+               }
+
+               // Don't explain an explain statement
+               if (strtolower(substr($query, 0, 7)) == "explain") {
+                       return;
+               }
+
+               // Only do the explain on "select", "update" and "delete"
+               if (!in_array(strtolower(substr($query, 0, 6)), ["select", "update", "delete"])) {
+                       return;
+               }
+
+               $r = self::p("EXPLAIN ".$query);
+               if (!DBM::is_result($r)) {
+                       return;
+               }
+
+               $watchlist = explode(',', $a->getConfigVariable('system', 'db_log_index_watch'));
+               $blacklist = explode(',', $a->getConfigVariable('system', 'db_log_index_blacklist'));
+
+               while ($row = self::fetch($r)) {
+                       if ((intval($a->getConfigVariable('system', 'db_loglimit_index')) > 0)) {
+                               $log = (in_array($row['key'], $watchlist) &&
+                                       ($row['rows'] >= intval($a->getConfigVariable('system', 'db_loglimit_index'))));
+                       } else {
+                               $log = false;
+                       }
+
+                       if ((intval($a->getConfigVariable('system', 'db_loglimit_index_high')) > 0) && ($row['rows'] >= intval($a->getConfigVariable('system', 'db_loglimit_index_high')))) {
+                               $log = true;
+                       }
+
+                       if (in_array($row['key'], $blacklist) || ($row['key'] == "")) {
+                               $log = false;
+                       }
+
+                       if ($log) {
+                               $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+                               @file_put_contents($a->getConfigVariable('system', 'db_log_index'), DateTimeFormat::utcNow()."\t".
+                                               $row['key']."\t".$row['rows']."\t".$row['Extra']."\t".
+                                               basename($backtrace[1]["file"])."\t".
+                                               $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
+                                               substr($query, 0, 2000)."\n", FILE_APPEND);
+                       }
+               }
+       }
+
+       public static function escape($str) {
+               switch (self::$driver) {
+                       case 'pdo':
+                               return substr(@self::$db->quote($str, PDO::PARAM_STR), 1, -1);
+                       case 'mysqli':
+                               return @self::$db->real_escape_string($str);
+               }
+       }
+
+       public static function connected() {
+               $connected = false;
+
+               if (is_null(self::$db)) {
+                       return false;
+               }
+
+               switch (self::$driver) {
+                       case 'pdo':
+                               $r = self::p("SELECT 1");
+                               if (DBM::is_result($r)) {
+                                       $row = self::inArray($r);
+                                       $connected = ($row[0]['1'] == '1');
+                               }
+                               break;
+                       case 'mysqli':
+                               $connected = self::$db->ping();
+                               break;
+               }
+               return $connected;
+       }
+
+       /**
+        * @brief Replaces ANY_VALUE() function by MIN() function,
+        *  if the database server does not support ANY_VALUE().
+        *
+        * Considerations for Standard SQL, or MySQL with ONLY_FULL_GROUP_BY (default since 5.7.5).
+        * ANY_VALUE() is available from MySQL 5.7.5 https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html
+        * A standard fall-back is to use MIN().
+        *
+        * @param string $sql An SQL string without the values
+        * @return string The input SQL string modified if necessary.
+        */
+       public static function any_value_fallback($sql) {
+               $server_info = self::server_info();
+               if (version_compare($server_info, '5.7.5', '<') ||
+                       (stripos($server_info, 'MariaDB') !== false)) {
+                       $sql = str_ireplace('ANY_VALUE(', 'MIN(', $sql);
+               }
+               return $sql;
+       }
+
+       /**
+        * @brief beautifies the query - useful for "SHOW PROCESSLIST"
+        *
+        * This is safe when we bind the parameters later.
+        * The parameter values aren't part of the SQL.
+        *
+        * @param string $sql An SQL string without the values
+        * @return string The input SQL string modified if necessary.
+        */
+       public static function clean_query($sql) {
+               $search = ["\t", "\n", "\r", "  "];
+               $replace = [' ', ' ', ' ', ' '];
+               do {
+                       $oldsql = $sql;
+                       $sql = str_replace($search, $replace, $sql);
+               } while ($oldsql != $sql);
+
+               return $sql;
+       }
+
+
+       /**
+        * @brief Replaces the ? placeholders with the parameters in the $args array
+        *
+        * @param string $sql SQL query
+        * @param array $args The parameters that are to replace the ? placeholders
+        * @return string The replaced SQL query
+        */
+       private static function replaceParameters($sql, $args) {
+               $offset = 0;
+               foreach ($args AS $param => $value) {
+                       if (is_int($args[$param]) || is_float($args[$param])) {
+                               $replace = intval($args[$param]);
+                       } else {
+                               $replace = "'".self::escape($args[$param])."'";
+                       }
+
+                       $pos = strpos($sql, '?', $offset);
+                       if ($pos !== false) {
+                               $sql = substr_replace($sql, $replace, $pos, 1);
+                       }
+                       $offset = $pos + strlen($replace);
+               }
+               return $sql;
+       }
+
+       /**
+        * @brief Convert parameter array to an universal form
+        * @param array $args Parameter array
+        * @return array universalized parameter array
+        */
+       private static function getParam($args) {
+               unset($args[0]);
+
+               // When the second function parameter is an array then use this as the parameter array
+               if ((count($args) > 0) && (is_array($args[1]))) {
+                       return $args[1];
+               } else {
+                       return $args;
+               }
+       }
+
+       /**
+        * @brief Executes a prepared statement that returns data
+        * @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
+        *
+        * @param string $sql SQL statement
+        * @return bool|object statement object or result object
+        */
+       public static function p($sql) {
+               $a = get_app();
+
+               $stamp1 = microtime(true);
+
+               $params = self::getParam(func_get_args());
+
+               // Renumber the array keys to be sure that they fit
+               $i = 0;
+               $args = [];
+               foreach ($params AS $param) {
+                       // Avoid problems with some MySQL servers and boolean values. See issue #3645
+                       if (is_bool($param)) {
+                               $param = (int)$param;
+                       }
+                       $args[++$i] = $param;
+               }
+
+               if (!self::$connected) {
+                       return false;
+               }
+
+               if ((substr_count($sql, '?') != count($args)) && (count($args) > 0)) {
+                       // Question: Should we continue or stop the query here?
+                       logger('Parameter mismatch. Query "'.$sql.'" - Parameters '.print_r($args, true), LOGGER_DEBUG);
+               }
+
+               $sql = self::clean_query($sql);
+               $sql = self::any_value_fallback($sql);
+
+               $orig_sql = $sql;
+
+               if ($a->getConfigValue('system', 'db_callstack')) {
+                       $sql = "/*".System::callstack()." */ ".$sql;
+               }
+
+               self::$error = '';
+               self::$errorno = 0;
+               self::$affected_rows = 0;
+
+               // We have to make some things different if this function is called from "e"
+               $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
+
+               if (isset($trace[1])) {
+                       $called_from = $trace[1];
+               } else {
+                       // We use just something that is defined to avoid warnings
+                       $called_from = $trace[0];
+               }
+               // We are having an own error logging in the function "e"
+               $called_from_e = ($called_from['function'] == 'e');
+
+               switch (self::$driver) {
+                       case 'pdo':
+                               // If there are no arguments we use "query"
+                               if (count($args) == 0) {
+                                       if (!$retval = self::$db->query($sql)) {
+                                               $errorInfo = self::$db->errorInfo();
+                                               self::$error = $errorInfo[2];
+                                               self::$errorno = $errorInfo[1];
+                                               $retval = false;
+                                               break;
+                                       }
+                                       self::$affected_rows = $retval->rowCount();
+                                       break;
+                               }
+
+                               if (!$stmt = self::$db->prepare($sql)) {
+                                       $errorInfo = self::$db->errorInfo();
+                                       self::$error = $errorInfo[2];
+                                       self::$errorno = $errorInfo[1];
+                                       $retval = false;
+                                       break;
+                               }
+
+                               foreach ($args AS $param => $value) {
+                                       if (is_int($args[$param])) {
+                                               $data_type = PDO::PARAM_INT;
+                                       } else {
+                                               $data_type = PDO::PARAM_STR;
+                                       }
+                                       $stmt->bindParam($param, $args[$param], $data_type);
+                               }
+
+                               if (!$stmt->execute()) {
+                                       $errorInfo = $stmt->errorInfo();
+                                       self::$error = $errorInfo[2];
+                                       self::$errorno = $errorInfo[1];
+                                       $retval = false;
+                               } else {
+                                       $retval = $stmt;
+                                       self::$affected_rows = $retval->rowCount();
+                               }
+                               break;
+                       case 'mysqli':
+                               // There are SQL statements that cannot be executed with a prepared statement
+                               $parts = explode(' ', $orig_sql);
+                               $command = strtolower($parts[0]);
+                               $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)) {
+                                       $retval = self::$db->query(self::replaceParameters($sql, $args));
+                                       if (self::$db->errno) {
+                                               self::$error = self::$db->error;
+                                               self::$errorno = self::$db->errno;
+                                               $retval = false;
+                                       } else {
+                                               if (isset($retval->num_rows)) {
+                                                       self::$affected_rows = $retval->num_rows;
+                                               } else {
+                                                       self::$affected_rows = self::$db->affected_rows;
+                                               }
+                                       }
+                                       break;
+                               }
+
+                               $stmt = self::$db->stmt_init();
+
+                               if (!$stmt->prepare($sql)) {
+                                       self::$error = $stmt->error;
+                                       self::$errorno = $stmt->errno;
+                                       $retval = false;
+                                       break;
+                               }
+
+                               $param_types = '';
+                               $values = [];
+                               foreach ($args AS $param => $value) {
+                                       if (is_int($args[$param])) {
+                                               $param_types .= 'i';
+                                       } elseif (is_float($args[$param])) {
+                                               $param_types .= 'd';
+                                       } elseif (is_string($args[$param])) {
+                                               $param_types .= 's';
+                                       } else {
+                                               $param_types .= 'b';
+                                       }
+                                       $values[] = &$args[$param];
+                               }
+
+                               if (count($values) > 0) {
+                                       array_unshift($values, $param_types);
+                                       call_user_func_array([$stmt, 'bind_param'], $values);
+                               }
+
+                               if (!$stmt->execute()) {
+                                       self::$error = self::$db->error;
+                                       self::$errorno = self::$db->errno;
+                                       $retval = false;
+                               } else {
+                                       $stmt->store_result();
+                                       $retval = $stmt;
+                                       self::$affected_rows = $retval->affected_rows;
+                               }
+                               break;
+               }
+
+               // We are having an own error logging in the function "e"
+               if ((self::$errorno != 0) && !$called_from_e) {
+                       // We have to preserve the error code, somewhere in the logging it get lost
+                       $error = self::$error;
+                       $errorno = self::$errorno;
+
+                       logger('DB Error '.self::$errorno.': '.self::$error."\n".
+                               System::callstack(8)."\n".self::replaceParameters($sql, $args));
+
+                       // On a lost connection we try to reconnect - but only once.
+                       if ($errorno == 2006) {
+                               if (self::$in_retrial || !self::reconnect()) {
+                                       // It doesn't make sense to continue when the database connection was lost
+                                       if (self::$in_retrial) {
+                                               logger('Giving up retrial because of database error '.$errorno.': '.$error);
+                                       } else {
+                                               logger("Couldn't reconnect after database error ".$errorno.': '.$error);
+                                       }
+                                       exit(1);
+                               } else {
+                                       // We try it again
+                                       logger('Reconnected after database error '.$errorno.': '.$error);
+                                       self::$in_retrial = true;
+                                       $ret = self::p($sql, $args);
+                                       self::$in_retrial = false;
+                                       return $ret;
+                               }
+                       }
+
+                       self::$error = $error;
+                       self::$errorno = $errorno;
+               }
+
+               $a->save_timestamp($stamp1, 'database');
+
+               if ($a->getConfigValue('system', 'db_log')) {
+                       $stamp2 = microtime(true);
+                       $duration = (float)($stamp2 - $stamp1);
+
+                       if (($duration > $a->getConfigValue('system', 'db_loglimit'))) {
+                               $duration = round($duration, 3);
+                               $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+
+                               @file_put_contents($a->getConfigValue('system', 'db_log'), DateTimeFormat::utcNow()."\t".$duration."\t".
+                                               basename($backtrace[1]["file"])."\t".
+                                               $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
+                                               substr(self::replaceParameters($sql, $args), 0, 2000)."\n", FILE_APPEND);
+                       }
+               }
+               return $retval;
+       }
+
+       /**
+        * @brief Executes a prepared statement like UPDATE or INSERT that doesn't return data
+        *
+        * 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
+        */
+       public static function e($sql) {
+               $a = get_app();
+
+               $stamp = microtime(true);
+
+               $params = self::getParam(func_get_args());
+
+               // In a case of a deadlock we are repeating the query 20 times
+               $timeout = 20;
+
+               do {
+                       $stmt = self::p($sql, $params);
+
+                       if (is_bool($stmt)) {
+                               $retval = $stmt;
+                       } elseif (is_object($stmt)) {
+                               $retval = true;
+                       } else {
+                               $retval = false;
+                       }
+
+                       self::close($stmt);
+
+               } while ((self::$errorno == 1213) && (--$timeout > 0));
+
+               if (self::$errorno != 0) {
+                       // We have to preserve the error code, somewhere in the logging it get lost
+                       $error = self::$error;
+                       $errorno = self::$errorno;
+
+                       logger('DB Error '.self::$errorno.': '.self::$error."\n".
+                               System::callstack(8)."\n".self::replaceParameters($sql, $params));
+
+                       // On a lost connection we simply quit.
+                       // A reconnect like in self::p could be dangerous with modifications
+                       if ($errorno == 2006) {
+                               logger('Giving up because of database error '.$errorno.': '.$error);
+                               exit(1);
+                       }
+
+                       self::$error = $error;
+                       self::$errorno = $errorno;
+               }
+
+               $a->save_timestamp($stamp, "database_write");
+
+               return $retval;
+       }
+
+       /**
+        * @brief Check if data exists
+        *
+        * @param string $table Table name
+        * @param array $condition array of fields for condition
+        *
+        * @return boolean Are there rows for that condition?
+        */
+       public static function exists($table, $condition) {
+               if (empty($table)) {
+                       return false;
+               }
+
+               $fields = [];
+
+               reset($condition);
+               $first_key = key($condition);
+               if (!is_int($first_key)) {
+                       $fields = [$first_key];
+               }
+
+               $stmt = self::select($table, $fields, $condition, ['limit' => 1]);
+
+               if (is_bool($stmt)) {
+                       $retval = $stmt;
+               } else {
+                       $retval = (self::num_rows($stmt) > 0);
+               }
+
+               self::close($stmt);
+
+               return $retval;
+       }
+
+       /**
+        * Fetches the first row
+        *
+        * Please use dba::selectFirst or dba::exists whenever this is possible.
+        *
+        * @brief Fetches the first row
+        * @param string $sql SQL statement
+        * @return array first row of query
+        */
+       public static function fetch_first($sql) {
+               $params = self::getParam(func_get_args());
+
+               $stmt = self::p($sql, $params);
+
+               if (is_bool($stmt)) {
+                       $retval = $stmt;
+               } else {
+                       $retval = self::fetch($stmt);
+               }
+
+               self::close($stmt);
+
+               return $retval;
+       }
+
+       /**
+        * @brief Returns the number of affected rows of the last statement
+        *
+        * @return int Number of rows
+        */
+       public static function affected_rows() {
+               return self::$affected_rows;
+       }
+
+       /**
+        * @brief Returns the number of columns of a statement
+        *
+        * @param object Statement object
+        * @return int Number of columns
+        */
+       public static function columnCount($stmt) {
+               if (!is_object($stmt)) {
+                       return 0;
+               }
+               switch (self::$driver) {
+                       case 'pdo':
+                               return $stmt->columnCount();
+                       case 'mysqli':
+                               return $stmt->field_count;
+               }
+               return 0;
+       }
+       /**
+        * @brief Returns the number of rows of a statement
+        *
+        * @param PDOStatement|mysqli_result|mysqli_stmt Statement object
+        * @return int Number of rows
+        */
+       public static function num_rows($stmt) {
+               if (!is_object($stmt)) {
+                       return 0;
+               }
+               switch (self::$driver) {
+                       case 'pdo':
+                               return $stmt->rowCount();
+                       case 'mysqli':
+                               return $stmt->num_rows;
+               }
+               return 0;
+       }
+
+       /**
+        * @brief Fetch a single row
+        *
+        * @param mixed $stmt statement object
+        * @return array current row
+        */
+       public static function fetch($stmt) {
+               $a = get_app();
+
+               $stamp1 = microtime(true);
+
+               $columns = [];
+
+               if (!is_object($stmt)) {
+                       return false;
+               }
+
+               switch (self::$driver) {
+                       case 'pdo':
+                               $columns = $stmt->fetch(PDO::FETCH_ASSOC);
+                               break;
+                       case 'mysqli':
+                               if (get_class($stmt) == 'mysqli_result') {
+                                       $columns = $stmt->fetch_assoc();
+                                       break;
+                               }
+
+                               // This code works, but is slow
+
+                               // Bind the result to a result array
+                               $cols = [];
+
+                               $cols_num = [];
+                               for ($x = 0; $x < $stmt->field_count; $x++) {
+                                       $cols[] = &$cols_num[$x];
+                               }
+
+                               call_user_func_array([$stmt, 'bind_result'], $cols);
+
+                               if (!$stmt->fetch()) {
+                                       return false;
+                               }
+
+                               // The slow part:
+                               // We need to get the field names for the array keys
+                               // It seems that there is no better way to do this.
+                               $result = $stmt->result_metadata();
+                               $fields = $result->fetch_fields();
+
+                               foreach ($cols_num AS $param => $col) {
+                                       $columns[$fields[$param]->name] = $col;
+                               }
+               }
+
+               $a->save_timestamp($stamp1, 'database');
+
+               return $columns;
+       }
+
+       /**
+        * @brief Insert a row into a table
+        *
+        * @param string $table Table name
+        * @param array $param parameter array
+        * @param bool $on_duplicate_update Do an update on a duplicate entry
+        *
+        * @return boolean was the insert successfull?
+        */
+       public static function insert($table, $param, $on_duplicate_update = false) {
+
+               if (empty($table) || empty($param)) {
+                       logger('Table and fields have to be set');
+                       return false;
+               }
+
+               $sql = "INSERT INTO `".self::escape($table)."` (`".implode("`, `", array_keys($param))."`) VALUES (".
+                       substr(str_repeat("?, ", count($param)), 0, -2).")";
+
+               if ($on_duplicate_update) {
+                       $sql .= " ON DUPLICATE KEY UPDATE `".implode("` = ?, `", array_keys($param))."` = ?";
+
+                       $values = array_values($param);
+                       $param = array_merge_recursive($values, $values);
+               }
+
+               return self::e($sql, $param);
+       }
+
+       /**
+        * @brief Fetch the id of the last insert command
+        *
+        * @return integer Last inserted id
+        */
+       public static function lastInsertId() {
+               switch (self::$driver) {
+                       case 'pdo':
+                               $id = self::$db->lastInsertId();
+                               break;
+                       case 'mysqli':
+                               $id = self::$db->insert_id;
+                               break;
+               }
+               return $id;
+       }
+
+       /**
+        * @brief Locks a table for exclusive write access
+        *
+        * This function can be extended in the future to accept a table array as well.
+        *
+        * @param string $table Table name
+        *
+        * @return boolean was the lock successful?
+        */
+       public static function lock($table) {
+               // See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
+               if (self::$driver == 'pdo') {
+                       self::e("SET autocommit=0");
+                       self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+               } else {
+                       self::$db->autocommit(false);
+               }
+
+               $success = self::e("LOCK TABLES `".self::escape($table)."` WRITE");
+
+               if (self::$driver == 'pdo') {
+                       self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
+               }
+
+               if (!$success) {
+                       if (self::$driver == 'pdo') {
+                               self::e("SET autocommit=1");
+                       } else {
+                               self::$db->autocommit(true);
+                       }
+               } else {
+                       self::$in_transaction = true;
+               }
+               return $success;
+       }
+
+       /**
+        * @brief Unlocks all locked tables
+        *
+        * @return boolean was the unlock successful?
+        */
+       public static function unlock() {
+               // See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
+               self::performCommit();
+
+               if (self::$driver == 'pdo') {
+                       self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+               }
+
+               $success = self::e("UNLOCK TABLES");
+
+               if (self::$driver == 'pdo') {
+                       self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
+                       self::e("SET autocommit=1");
+               } else {
+                       self::$db->autocommit(true);
+               }
+
+               self::$in_transaction = false;
+               return $success;
+       }
+
+       /**
+        * @brief Starts a transaction
+        *
+        * @return boolean Was the command executed successfully?
+        */
+       public static function transaction() {
+               if (!self::performCommit()) {
+                       return false;
+               }
+
+               switch (self::$driver) {
+                       case 'pdo':
+                               if (self::$db->inTransaction()) {
+                                       break;
+                               }
+                               if (!self::$db->beginTransaction()) {
+                                       return false;
+                               }
+                               break;
+                       case 'mysqli':
+                               if (!self::$db->begin_transaction()) {
+                                       return false;
+                               }
+                               break;
+               }
+
+               self::$in_transaction = true;
+               return true;
+       }
+
+       private static function performCommit()
+       {
+               switch (self::$driver) {
+                       case 'pdo':
+                               if (!self::$db->inTransaction()) {
+                                       return true;
+                               }
+                               return self::$db->commit();
+                       case 'mysqli':
+                               return self::$db->commit();
+               }
+               return true;
+       }
+
+       /**
+        * @brief Does a commit
+        *
+        * @return boolean Was the command executed successfully?
+        */
+       public static function commit() {
+               if (!self::performCommit()) {
+                       return false;
+               }
+               self::$in_transaction = false;
+               return true;
+       }
+
+       /**
+        * @brief Does a rollback
+        *
+        * @return boolean Was the command executed successfully?
+        */
+       public static function rollback() {
+               $ret = false;
+
+               switch (self::$driver) {
+                       case 'pdo':
+                               if (!self::$db->inTransaction()) {
+                                       $ret = true;
+                                       break;
+                               }
+                               $ret = self::$db->rollBack();
+                               break;
+                       case 'mysqli':
+                               $ret = self::$db->rollback();
+                               break;
+               }
+               self::$in_transaction = false;
+               return $ret;
+       }
+
+       /**
+        * @brief Build the array with the table relations
+        *
+        * The array is build from the database definitions in DBStructure.php
+        *
+        * This process must only be started once, since the value is cached.
+        */
+       private static function buildRelationData() {
+               $definition = DBStructure::definition();
+
+               foreach ($definition AS $table => $structure) {
+                       foreach ($structure['fields'] AS $field => $field_struct) {
+                               if (isset($field_struct['relation'])) {
+                                       foreach ($field_struct['relation'] AS $rel_table => $rel_field) {
+                                               self::$relation[$rel_table][$rel_field][$table][] = $field;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /**
+        * @brief Delete a row from a table
+        *
+        * @param string  $table       Table name
+        * @param array   $conditions  Field condition(s)
+        * @param array   $options
+        *                - cascade: If true we delete records in other tables that depend on the one we're deleting through
+        *                           relations (default: true)
+        * @param boolean $in_process  Internal use: Only do a commit after the last delete
+        * @param array   $callstack   Internal use: prevent endless loops
+        *
+        * @return boolean|array was the delete successful? When $in_process is set: deletion data
+        */
+       public static function delete($table, array $conditions, array $options = [], $in_process = false, array &$callstack = [])
+       {
+               if (empty($table) || empty($conditions)) {
+                       logger('Table and conditions have to be set');
+                       return false;
+               }
+
+               $commands = [];
+
+               // Create a key for the loop prevention
+               $key = $table . ':' . json_encode($conditions);
+
+               // We quit when this key already exists in the callstack.
+               if (isset($callstack[$key])) {
+                       return $commands;
+               }
+
+               $callstack[$key] = true;
+
+               $table = self::escape($table);
+
+               $commands[$key] = ['table' => $table, 'conditions' => $conditions];
+
+               $cascade = defaults($options, 'cascade', true);
+
+               // To speed up the whole process we cache the table relations
+               if ($cascade && count(self::$relation) == 0) {
+                       self::buildRelationData();
+               }
+
+               // Is there a relation entry for the table?
+               if ($cascade && isset(self::$relation[$table])) {
+                       // We only allow a simple "one field" relation.
+                       $field = array_keys(self::$relation[$table])[0];
+                       $rel_def = array_values(self::$relation[$table])[0];
+
+                       // Create a key for preventing double queries
+                       $qkey = $field . '-' . $table . ':' . json_encode($conditions);
+
+                       // When the search field is the relation field, we don't need to fetch the rows
+                       // This is useful when the leading record is already deleted in the frontend but the rest is done in the backend
+                       if ((count($conditions) == 1) && ($field == array_keys($conditions)[0])) {
+                               foreach ($rel_def AS $rel_table => $rel_fields) {
+                                       foreach ($rel_fields AS $rel_field) {
+                                               $retval = self::delete($rel_table, [$rel_field => array_values($conditions)[0]], $options, true, $callstack);
+                                               $commands = array_merge($commands, $retval);
+                                       }
+                               }
+                               // We quit when this key already exists in the callstack.
+                       } elseif (!isset($callstack[$qkey])) {
+
+                               $callstack[$qkey] = true;
+
+                               // Fetch all rows that are to be deleted
+                               $data = self::select($table, [$field], $conditions);
+
+                               while ($row = self::fetch($data)) {
+                                       // Now we accumulate the delete commands
+                                       $retval = self::delete($table, [$field => $row[$field]], $options, true, $callstack);
+                                       $commands = array_merge($commands, $retval);
+                               }
+
+                               self::close($data);
+
+                               // Since we had split the delete command we don't need the original command anymore
+                               unset($commands[$key]);
+                       }
+               }
+
+               if (!$in_process) {
+                       // Now we finalize the process
+                       $do_transaction = !self::$in_transaction;
+
+                       if ($do_transaction) {
+                               self::transaction();
+                       }
+
+                       $compacted = [];
+                       $counter = [];
+
+                       foreach ($commands AS $command) {
+                               $conditions = $command['conditions'];
+                               reset($conditions);
+                               $first_key = key($conditions);
+
+                               $condition_string = self::buildCondition($conditions);
+
+                               if ((count($command['conditions']) > 1) || is_int($first_key)) {
+                                       $sql = "DELETE FROM `" . $command['table'] . "`" . $condition_string;
+                                       logger(self::replaceParameters($sql, $conditions), LOGGER_DATA);
+
+                                       if (!self::e($sql, $conditions)) {
+                                               if ($do_transaction) {
+                                                       self::rollback();
+                                               }
+                                               return false;
+                                       }
+                               } else {
+                                       $key_table = $command['table'];
+                                       $key_condition = array_keys($command['conditions'])[0];
+                                       $value = array_values($command['conditions'])[0];
+
+                                       // Split the SQL queries in chunks of 100 values
+                                       // We do the $i stuff here to make the code better readable
+                                       $i = isset($counter[$key_table][$key_condition]) ? $counter[$key_table][$key_condition] : 0;
+                                       if (isset($compacted[$key_table][$key_condition][$i]) && count($compacted[$key_table][$key_condition][$i]) > 100) {
+                                               ++$i;
+                                       }
+
+                                       $compacted[$key_table][$key_condition][$i][$value] = $value;
+                                       $counter[$key_table][$key_condition] = $i;
+                               }
+                       }
+                       foreach ($compacted AS $table => $values) {
+                               foreach ($values AS $field => $field_value_list) {
+                                       foreach ($field_value_list AS $field_values) {
+                                               $sql = "DELETE FROM `" . $table . "` WHERE `" . $field . "` IN (" .
+                                                       substr(str_repeat("?, ", count($field_values)), 0, -2) . ");";
+
+                                               logger(self::replaceParameters($sql, $field_values), LOGGER_DATA);
+
+                                               if (!self::e($sql, $field_values)) {
+                                                       if ($do_transaction) {
+                                                               self::rollback();
+                                                       }
+                                                       return false;
+                                               }
+                                       }
+                               }
+                       }
+                       if ($do_transaction) {
+                               self::commit();
+                       }
+                       return true;
+               }
+
+               return $commands;
+       }
+
+       /**
+        * @brief Updates rows
+        *
+        * Updates rows in the database. When $old_fields is set to an array,
+        * the system will only do an update if the fields in that array changed.
+        *
+        * Attention:
+        * Only the values in $old_fields are compared.
+        * This is an intentional behaviour.
+        *
+        * Example:
+        * We include the timestamp field in $fields but not in $old_fields.
+        * Then the row will only get the new timestamp when the other fields had changed.
+        *
+        * When $old_fields is set to a boolean value the system will do this compare itself.
+        * When $old_fields is set to "true" the system will do an insert if the row doesn't exists.
+        *
+        * Attention:
+        * Only set $old_fields to a boolean value when you are sure that you will update a single row.
+        * When you set $old_fields to "true" then $fields must contain all relevant fields!
+        *
+        * @param string $table Table name
+        * @param array $fields contains the fields that are updated
+        * @param array $condition condition array with the key values
+        * @param array|boolean $old_fields array with the old field values that are about to be replaced (true = update on duplicate)
+        *
+        * @return boolean was the update successfull?
+        */
+       public static function update($table, $fields, $condition, $old_fields = []) {
+
+               if (empty($table) || empty($fields) || empty($condition)) {
+                       logger('Table, fields and condition have to be set');
+                       return false;
+               }
+
+               $table = self::escape($table);
+
+               $condition_string = self::buildCondition($condition);
+
+               if (is_bool($old_fields)) {
+                       $do_insert = $old_fields;
+
+                       $old_fields = self::selectFirst($table, [], $condition);
+
+                       if (is_bool($old_fields)) {
+                               if ($do_insert) {
+                                       $values = array_merge($condition, $fields);
+                                       return self::insert($table, $values, $do_insert);
+                               }
+                               $old_fields = [];
+                       }
+               }
+
+               $do_update = (count($old_fields) == 0);
+
+               foreach ($old_fields AS $fieldname => $content) {
+                       if (isset($fields[$fieldname])) {
+                               if ($fields[$fieldname] == $content) {
+                                       unset($fields[$fieldname]);
+                               } else {
+                                       $do_update = true;
+                               }
+                       }
+               }
+
+               if (!$do_update || (count($fields) == 0)) {
+                       return true;
+               }
+
+               $sql = "UPDATE `".$table."` SET `".
+                       implode("` = ?, `", array_keys($fields))."` = ?".$condition_string;
+
+               $params1 = array_values($fields);
+               $params2 = array_values($condition);
+               $params = array_merge_recursive($params1, $params2);
+
+               return self::e($sql, $params);
+       }
+
+       /**
+        * Retrieve a single record from a table and returns it in an associative array
+        *
+        * @brief Retrieve a single record from a table
+        * @param string $table
+        * @param array  $fields
+        * @param array  $condition
+        * @param array  $params
+        * @return bool|array
+        * @see self::select
+        */
+       public static function selectFirst($table, array $fields = [], array $condition = [], $params = [])
+       {
+               $params['limit'] = 1;
+               $result = self::select($table, $fields, $condition, $params);
+
+               if (is_bool($result)) {
+                       return $result;
+               } else {
+                       $row = self::fetch($result);
+                       self::close($result);
+                       return $row;
+               }
+       }
+
+       /**
+        * @brief Select rows from a table
+        *
+        * @param string $table     Table name
+        * @param array  $fields    Array of selected fields, empty for all
+        * @param array  $condition Array of fields for condition
+        * @param array  $params    Array of several parameters
+        *
+        * @return boolean|object
+        *
+        * Example:
+        * $table = "item";
+        * $fields = array("id", "uri", "uid", "network");
+        *
+        * $condition = array("uid" => 1, "network" => 'dspr');
+        * or:
+        * $condition = array("`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr');
+        *
+        * $params = array("order" => array("id", "received" => true), "limit" => 10);
+        *
+        * $data = dba::select($table, $fields, $condition, $params);
+        */
+       public static function select($table, array $fields = [], array $condition = [], array $params = [])
+       {
+               if ($table == '') {
+                       return false;
+               }
+
+               $table = self::escape($table);
+
+               if (count($fields) > 0) {
+                       $select_fields = "`" . implode("`, `", array_values($fields)) . "`";
+               } else {
+                       $select_fields = "*";
+               }
+
+               $condition_string = self::buildCondition($condition);
+
+               $param_string = self::buildParameter($params);
+
+               $sql = "SELECT " . $select_fields . " FROM `" . $table . "`" . $condition_string . $param_string;
+
+               $result = self::p($sql, $condition);
+
+               return $result;
+       }
+
+       /**
+        * @brief Counts the rows from a table satisfying the provided condition
+        *
+        * @param string $table Table name
+        * @param array $condition array of fields for condition
+        *
+        * @return int
+        *
+        * Example:
+        * $table = "item";
+        *
+        * $condition = ["uid" => 1, "network" => 'dspr'];
+        * or:
+        * $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr'];
+        *
+        * $count = dba::count($table, $condition);
+        */
+       public static function count($table, array $condition = [])
+       {
+               if ($table == '') {
+                       return false;
+               }
+
+               $condition_string = self::buildCondition($condition);
+
+               $sql = "SELECT COUNT(*) AS `count` FROM `".$table."`".$condition_string;
+
+               $row = self::fetch_first($sql, $condition);
+
+               return $row['count'];
+       }
+
+       /**
+        * @brief Returns the SQL condition string built from the provided condition array
+        *
+        * This function operates with two modes.
+        * - Supplied with a filed/value associative array, it builds simple strict
+        *   equality conditions linked by AND.
+        * - Supplied with a flat list, the first element is the condition string and
+        *   the following arguments are the values to be interpolated
+        *
+        * $condition = ["uid" => 1, "network" => 'dspr'];
+        * or:
+        * $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr'];
+        *
+        * In either case, the provided array is left with the parameters only
+        *
+        * @param array $condition
+        * @return string
+        */
+       public static function buildCondition(array &$condition = [])
+       {
+               $condition_string = '';
+               if (count($condition) > 0) {
+                       reset($condition);
+                       $first_key = key($condition);
+                       if (is_int($first_key)) {
+                               $condition_string = " WHERE (" . array_shift($condition) . ")";
+                       } else {
+                               $new_values = [];
+                               $condition_string = "";
+                               foreach ($condition as $field => $value) {
+                                       if ($condition_string != "") {
+                                               $condition_string .= " AND ";
+                                       }
+                                       if (is_array($value)) {
+                                               /* 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.
+                                                */
+                                               $is_int = false;
+                                               $is_alpha = false;
+                                               foreach ($value as $single_value) {
+                                                       if (is_int($single_value)) {
+                                                               $is_int = true;
+                                                       } else {
+                                                               $is_alpha = true;
+                                                       }
+                                               }
+
+                                               if ($is_int && $is_alpha) {
+                                                       foreach ($value as &$ref) {
+                                                               if (is_int($ref)) {
+                                                                       $ref = (string)$ref;
+                                                               }
+                                                       }
+                                                       unset($ref); //Prevent accidental re-use.
+                                               }
+
+                                               $new_values = array_merge($new_values, array_values($value));
+                                               $placeholders = substr(str_repeat("?, ", count($value)), 0, -2);
+                                               $condition_string .= "`" . $field . "` IN (" . $placeholders . ")";
+                                       } else {
+                                               $new_values[$field] = $value;
+                                               $condition_string .= "`" . $field . "` = ?";
+                                       }
+                               }
+                               $condition_string = " WHERE (" . $condition_string . ")";
+                               $condition = $new_values;
+                       }
+               }
+
+               return $condition_string;
+       }
+
+       /**
+        * @brief Returns the SQL parameter string built from the provided parameter array
+        *
+        * @param array $params
+        * @return string
+        */
+       public static function buildParameter(array $params = [])
+       {
+               $order_string = '';
+               if (isset($params['order'])) {
+                       $order_string = " ORDER BY ";
+                       foreach ($params['order'] AS $fields => $order) {
+                               if (!is_int($fields)) {
+                                       $order_string .= "`" . $fields . "` " . ($order ? "DESC" : "ASC") . ", ";
+                               } else {
+                                       $order_string .= "`" . $order . "`, ";
+                               }
+                       }
+                       $order_string = substr($order_string, 0, -2);
+               }
+
+               $limit_string = '';
+               if (isset($params['limit']) && is_int($params['limit'])) {
+                       $limit_string = " LIMIT " . $params['limit'];
+               }
+
+               if (isset($params['limit']) && is_array($params['limit'])) {
+                       $limit_string = " LIMIT " . intval($params['limit'][0]) . ", " . intval($params['limit'][1]);
+               }
+
+               return $order_string.$limit_string;
+       }
+
+       /**
+        * @brief Fills an array with data from a query
+        *
+        * @param object $stmt statement object
+        * @return array Data array
+        */
+       public static function inArray($stmt, $do_close = true) {
+               if (is_bool($stmt)) {
+                       return $stmt;
+               }
+
+               $data = [];
+               while ($row = self::fetch($stmt)) {
+                       $data[] = $row;
+               }
+               if ($do_close) {
+                       self::close($stmt);
+               }
+               return $data;
+       }
+
+       /**
+        * @brief Returns the error number of the last query
+        *
+        * @return string Error number (0 if no error)
+        */
+       public static function errorNo() {
+               return self::$errorno;
+       }
+
+       /**
+        * @brief Returns the error message of the last query
+        *
+        * @return string Error message ('' if no error)
+        */
+       public static function errorMessage() {
+               return self::$error;
+       }
+
+       /**
+        * @brief Closes the current statement
+        *
+        * @param object $stmt statement object
+        * @return boolean was the close successful?
+        */
+       public static function close($stmt) {
+               $a = get_app();
+
+               $stamp1 = microtime(true);
+
+               if (!is_object($stmt)) {
+                       return false;
+               }
+
+               switch (self::$driver) {
+                       case 'pdo':
+                               $ret = $stmt->closeCursor();
+                               break;
+                       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.
+                               if ($stmt instanceof mysqli_stmt) {
+                                       $stmt->free_result();
+                                       $ret = $stmt->close();
+                               } elseif ($stmt instanceof mysqli_result) {
+                                       $stmt->free();
+                                       $ret = true;
+                               } else {
+                                       $ret = false;
+                               }
+                               break;
+               }
+
+               $a->save_timestamp($stamp1, 'database');
+
+               return $ret;
+       }
+}
index 7daf6b545f0c972a91db565d8d633011b262ab15..bbe60e0f2c5813edb8adbe49431b312747e783b0 100644 (file)
@@ -4,7 +4,6 @@
  */
 namespace Friendica\Database;
 
-use dba;
 use Friendica\Util\DateTimeFormat;
 
 require_once 'include/dba.php';
index 67750c3479251bec06a6d2d9414cb45b00e052c6..bfecdba20ef5f5d4cc7369ede2ef7e7a1a472a25 100644 (file)
@@ -4,7 +4,8 @@
  */
 namespace Friendica\Database;
 
-use dba;
+use Exception;
+use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 
@@ -629,7 +630,7 @@ class DBStructure
        private static function createIndex($indexname, $fieldnames, $method = "ADD") {
                $method = strtoupper(trim($method));
                if ($method!="" && $method!="ADD") {
-                       throw new \Exception("Invalid parameter 'method' in self::createIndex(): '$method'");
+                       throw new Exception("Invalid parameter 'method' in self::createIndex(): '$method'");
                }
 
                if ($fieldnames[0] == "UNIQUE") {
@@ -1941,7 +1942,7 @@ class DBStructure
                                                ]
                                ];
 
-               \Friendica\Core\Addon::callHooks('dbstructure_definition', $database);
+               Addon::callHooks('dbstructure_definition', $database);
 
                return $database;
        }
index 5593d932a3b3cf75d4624efa838fc75a3eaae493..4ce89d49e5b67c1f6d97c51c2f30d7c1455e20a2 100644 (file)
@@ -5,11 +5,9 @@
 namespace Friendica\Database;
 
 use Friendica\Core\Config;
-use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\PermissionSet;
-use dba;
 
 require_once 'include/dba.php';
 
index 093ee0d91e831b599aa03b39f9dfca722c078c6a..13283009378787576cc28e50b919e1905efcb873 100644 (file)
@@ -11,19 +11,16 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Model\Photo;
-use Friendica\Model\Profile;
 use Friendica\Network\Probe;
-use Friendica\Protocol\DFRN;
+use Friendica\Object\Image;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\PortableContact;
 use Friendica\Protocol\Salmon;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
-use Friendica\Object\Image;
-use dba;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
index 69bbc3bb6dd4b4718d03ac51ebad98d3b497d8fd..4b1adc250fe36a860a003605d2457948ff4c80ff 100644 (file)
@@ -4,8 +4,8 @@
  */
 namespace Friendica\Model;
 
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use dba;
 
 require_once "include/dba.php";
 
index 47ec50aaa0719d502a9f9ba717c96c8df0e60959..bd614f0bfbfd503d81f6d9aec840994f9497c07c 100644 (file)
@@ -5,15 +5,14 @@
 
 namespace Friendica\Model;
 
-use dba;
 use Friendica\BaseObject;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Addon;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Model\Item;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Map;
 
index d77e81a4c78d819390ecfc402e72f55bb548a286..52924b6416d4c1e0831e0d3d82c12907e365bd74 100644 (file)
@@ -6,18 +6,16 @@
  */
 namespace Friendica\Model;
 
-use Friendica\Core\Config;
+use Exception;
+use Friendica\Core\Console\Config;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Model\Contact;
-use Friendica\Model\Profile;
 use Friendica\Network\Probe;
 use Friendica\Protocol\PortableContact;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
-use dba;
-use Exception;
 
 require_once 'include/dba.php';
 
index 79604e2ca0b7e2948c071ca833c1993507da52bd..5247a055692ae058877e2621055ce67c2be2b1b2 100644 (file)
@@ -6,8 +6,8 @@ namespace Friendica\Model;
 
 use Friendica\BaseObject;
 use Friendica\Core\L10n;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use dba;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
index 74a4ebba5f481ac6f62efeed9ec1cb961775e01a..4f9f1cf9049992a4b86773f526ff663fa0a1b7b6 100644 (file)
@@ -6,18 +6,16 @@
 
 namespace Friendica\Model;
 
-use dba;
 use Friendica\BaseObject;
-use Friendica\Content\Text;
+use Friendica\Content\Text\BBCode;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
-use Friendica\Core\L10n;
 use Friendica\Core\Lock;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Model\PermissionSet;
 use Friendica\Object\Image;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
@@ -2219,7 +2217,7 @@ class Item extends BaseObject
         */
        private static function addLanguageToItemArray(&$item)
        {
-               $naked_body = Text\BBCode::toPlaintext($item['body'], false);
+               $naked_body = BBCode::toPlaintext($item['body'], false);
 
                $ld = new Text_LanguageDetect();
                $ld->setNameMode(2);
index f10ad368ba4b02052d26c009975ee4fa4e803944..1e5c8648721cf2a973a189d845a95aff955883c1 100644 (file)
@@ -8,10 +8,10 @@ namespace Friendica\Model;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
-use dba;
 
 require_once 'include/dba.php';
 
index 5c405b27d3c1f7e902d1ef202f1bd879ebced6e7..336f4ab0691d431fab1a896a6a225f0f2e526738 100644 (file)
@@ -5,9 +5,9 @@
  */
 namespace Friendica\Model;
 
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Util\DateTimeFormat;
-use dba;
 
 /**
  * Methods to deal with entries of the 'openwebauth-token' table.
@@ -16,12 +16,12 @@ class OpenWebAuthToken
 {
        /**
         * Create an entry in the 'openwebauth-token' table.
-        * 
+        *
         * @param string $type   Verify type.
         * @param int    $uid    The user ID.
         * @param string $token
         * @param string $meta
-        * 
+        *
         * @return boolean
         */
        public static function create($type, $uid, $token, $meta)
@@ -38,11 +38,11 @@ class OpenWebAuthToken
 
        /**
         * Get the "meta" field of an entry in the openwebauth-token table.
-        * 
+        *
         * @param string $type   Verify type.
         * @param int    $uid    The user ID.
         * @param string $token
-        * 
+        *
         * @return string|boolean The meta enry or false if not found.
         */
        public static function getMeta($type, $uid, $token)
@@ -60,7 +60,7 @@ class OpenWebAuthToken
 
        /**
         * Purge entries of a verify-type older than interval.
-        * 
+        *
         * @param string $type     Verify type.
         * @param string $interval SQL compatible time interval
         */
index c31e88bf17680a312cb8c8bbd088272d4a1d1b5b..983261fd617643b12907eabea14ae6ae80df4ea5 100644 (file)
@@ -5,8 +5,8 @@
 namespace Friendica\Model;
 
 use Friendica\BaseObject;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use dba;
 
 require_once 'include/dba.php';
 
index b08c6f0459b8654fe0fdfa220255e24107674376..2d740c3933bab75b2d86dbd34741360d6456f21f 100644 (file)
@@ -10,11 +10,11 @@ use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Object\Image;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
-use dba;
 
 require_once 'include/dba.php';
 
index 75d898065cdf71b9f6120ae22a9b388ed01bdd1f..d4595976513689fdf1d551d5fa3637187fa651b1 100644 (file)
@@ -5,8 +5,8 @@
 namespace Friendica\Model;
 
 use Friendica\BaseObject;
+use Friendica\Database\dba;
 use Friendica\Util\DateTimeFormat;
-use dba;
 
 require_once 'include/dba.php';
 
index 92355b216e945f3c58d790ce657f3b6c4780ad6e..79f3262410fc2229edcc9011d2734e58204d9663 100644 (file)
@@ -15,16 +15,12 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Model\Contact;
-use Friendica\Model\OpenWebAuthToken;
 use Friendica\Protocol\Diaspora;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\Temporal;
-use dba;
-
-use InvalidArgumentException;
 
 require_once 'include/dba.php';
 require_once 'mod/proxy.php';
index 925a461e2a54c55b74720244f6a55a8c69f5715e..fc08ca6cbb5c3788f950376b30eaf82a4de8f141 100644 (file)
@@ -5,9 +5,9 @@
 namespace Friendica\Model;
 
 use Friendica\Core\Worker;
-use Friendica\Util\DateTimeFormat;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use dba;
+use Friendica\Util\DateTimeFormat;
 
 require_once 'include/dba.php';
 
index 8b9e801c3ffc616af346e94322b4be112bbcc74c..8e9ed40d031003b550b324b052db9b4549b6b5a7 100644 (file)
@@ -5,9 +5,9 @@
 namespace Friendica\Model;
 
 use Friendica\Core\Config;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Util\DateTimeFormat;
-use dba;
 
 require_once 'include/dba.php';
 
index e9918c23b848669ac1343ce799a29bcc394c3907..9f0b595014bdaf245ab6c8f4f86cdbad4b3338e9 100644 (file)
@@ -5,9 +5,8 @@
 namespace Friendica\Model;
 
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Model\Item;
-use dba;
 
 require_once 'boot.php';
 require_once 'include/conversation.php';
index 57a3ecb50dfb681fcb425860b841bbe907759a5e..4dca908b61fdf93cdac24878df78d6f6dcb92b69 100644 (file)
@@ -6,22 +6,19 @@
 namespace Friendica\Model;
 
 use DivineOmega\PasswordExposed\PasswordStatus;
+use Exception;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Model\Contact;
-use Friendica\Model\Group;
-use Friendica\Model\Photo;
 use Friendica\Object\Image;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
-use dba;
-use Exception;
 use LightOpenID;
 use function password_exposed;
 
index c35a6440c0d3b379cdd3105cf39f2f3ca65860c7..a53585c28412f1aec644427fb3bd958afb7657d6 100644 (file)
@@ -6,7 +6,7 @@ namespace Friendica\Module;
 
 use Friendica\BaseModule;
 use Friendica\Core\System;
-use dba;
+use Friendica\Database\dba;
 
 require_once 'include/dba.php';
 require_once 'include/text.php';
index 06d724bb2adc5eac1b48871ecd515c3fef665e99..fb7a60613d5b949dca4caf3d4e67905bd1bf8c09 100644 (file)
@@ -4,16 +4,16 @@
  */
 namespace Friendica\Module;
 
+use Exception;
 use Friendica\BaseModule;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
-use dba;
-use Exception;
 use LightOpenID;
 
 require_once 'boot.php';
index d55e8f93bc5939aed5a622ba9e3fe515de90b60f..c1e2a7c9780f491df1847ed122d4c287b82f9d4c 100644 (file)
@@ -5,12 +5,11 @@
 namespace Friendica\Module;
 
 use Friendica\BaseModule;
+use Friendica\Database\dba;
 use Friendica\Model\Contact;
 use Friendica\Util\HTTPSignature;
 use Friendica\Util\Network;
 
-use dba;
-
 /**
  * Magic Auth (remote authentication) module.
  *
index 306c525c062698bcdf88516d6f1b666b6700f356..84f25024475eedeed06e41298987761d5b767312 100644 (file)
@@ -6,23 +6,22 @@ namespace Friendica\Module;
 
 use Friendica\BaseModule;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\OpenWebAuthToken;
 use Friendica\Util\HTTPSignature;
 
-use dba;
-
 /**
  * @brief OpenWebAuth verifier and token generator
- * 
+ *
  * See https://macgirvin.com/wiki/mike/OpenWebAuth/Home
  * Requests to this endpoint should be signed using HTTP Signatures
  * using the 'Authorization: Signature' authentication method
  * If the signature verifies a token is returned.
  *
  * This token may be exchanged for an authenticated cookie.
- * 
+ *
  * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/Zotlabs/Module/Owa.php
  */
 class Owa extends BaseModule
index 8af267be3de557ab082220e14aeed30403b972c8..addaeae115087af3ec66a3cf0dada2c5888ddd83 100644 (file)
@@ -7,10 +7,9 @@ namespace Friendica\Network;
 use Friendica\Core\Addon;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Network\FKOAuthDataStore;
 use Friendica\Util\DateTimeFormat;
-use dba;
 use OAuthServer;
 use OAuthSignatureMethod_HMAC_SHA1;
 use OAuthSignatureMethod_PLAINTEXT;
index 7a3329776aed4d18b20ee11384f608ae92b31c36..154d63b72fbf1bc49324188b49eb8c76cb527dfd 100644 (file)
@@ -10,8 +10,8 @@
 namespace Friendica\Network;
 
 use Friendica\Core\Config;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use dba;
 use OAuthConsumer;
 use OAuthDataStore;
 use OAuthToken;
index 6b278a965f6430cf45d7a3de00ac8f5512a9b65a..1a5ccbfae167e9ae6e527a12deb213b3b3e34797 100644 (file)
@@ -9,21 +9,19 @@ namespace Friendica\Network;
  * @brief Functions for probing URL
  */
 
-use Friendica\App;
-use Friendica\Core\System;
+use DOMDocument;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
+use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Profile;
 use Friendica\Protocol\Email;
 use Friendica\Protocol\Feed;
 use Friendica\Util\Crypto;
+use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\XML;
-use Friendica\Util\DateTimeFormat;
-use dba;
-use DOMXPath;
-use DOMDocument;
 
 require_once 'include/dba.php';
 
index 8b05abc566caa0569852ce876ffc9e639b49a8bf..71431b10db969dc7fdc9a7689331aaa4a4289b78 100644 (file)
@@ -11,12 +11,12 @@ use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Temporal;
-use dba;
 
 require_once 'include/dba.php';
 require_once 'include/text.php';
index 5326e49ac9ee67329bb938be399adc760ede9313..0769d3b1d949067a05c417b11859dfddd20ff01e 100644 (file)
@@ -8,6 +8,8 @@
  */
 namespace Friendica\Protocol;
 
+use DOMDocument;
+use DOMXPath;
 use Friendica\App;
 use Friendica\Content\OEmbed;
 use Friendica\Content\Text\BBCode;
@@ -16,7 +18,7 @@ use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
-use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Event;
@@ -26,15 +28,10 @@ use Friendica\Model\Item;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
 use Friendica\Object\Image;
-use Friendica\Protocol\OStatus;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\XML;
-use Friendica\Protocol\Diaspora;
-use dba;
-use DOMDocument;
-use DOMXPath;
 use HTMLPurifier;
 use HTMLPurifier_Config;
 
index 6b6e75cda4b83beee7626a5c0da0c30430403298..40caa4f06d102582c071be115a42d31a408a872f 100644 (file)
@@ -18,6 +18,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
@@ -29,12 +30,11 @@ use Friendica\Model\User;
 use Friendica\Network\Probe;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Map;
 use Friendica\Util\Network;
 use Friendica\Util\XML;
-use Friendica\Util\Map;
-use dba;
-use stdClass;
 use SimpleXMLElement;
+use stdClass;
 
 require_once 'include/dba.php';
 require_once 'include/items.php';
index d989b99622e427d596072dbfc09009a25d517bc1..3ebf37e4c7de3c4655ca760c1c75fcdeffa6d0f8 100644 (file)
@@ -6,17 +6,15 @@
  */
 namespace Friendica\Protocol;
 
-use Friendica\Database\DBM;
+use DOMDocument;
+use DOMXPath;
+use Friendica\Content\Text\HTML;
 use Friendica\Core\System;
+use Friendica\Database\DBM;
 use Friendica\Model\Item;
 use Friendica\Util\Network;
-use Friendica\Content\Text\HTML;
 use Friendica\Util\XML;
 
-use dba;
-use DOMDocument;
-use DOMXPath;
-
 require_once 'include/dba.php';
 require_once 'include/items.php';
 
index f0f4bed01aabc7d208678c47dd72346da80dfbe8..bd0defa32a0397585c0d9670bcb3bfdd3a96c751 100644 (file)
@@ -4,7 +4,6 @@
  */
 namespace Friendica\Protocol;
 
-use dba;
 use DOMDocument;
 use DOMXPath;
 use Friendica\Content\Text\BBCode;
@@ -14,6 +13,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\Lock;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
index a9e06d19a8c4c3b5401bf8740881363be2aa3948..848662538b93717c98c840117bfa09fee45fe2df 100644 (file)
@@ -9,21 +9,20 @@
 
 namespace Friendica\Protocol;
 
+use DOMDocument;
+use DOMXPath;
+use Exception;
 use Friendica\Content\Text\HTML;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\GContact;
 use Friendica\Model\Profile;
 use Friendica\Network\Probe;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
-use Friendica\Protocol\Diaspora;
 use Friendica\Util\XML;
-use dba;
-use DOMDocument;
-use DOMXPath;
-use Exception;
 
 require_once 'include/dba.php';
 
index d4436e32afaad55b83759f8f53784cef027becee..a01a7c721e0ccf8947d9da62f046640eacecb7ba 100644 (file)
@@ -36,10 +36,9 @@ namespace Friendica\Util;
 
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\User;
-use Friendica\Util\Network;
-use dba;
 
 require_once 'include/dba.php';
 
index a91b6b37e37c1cd230caa42bd66b88013700cee5..c3a45205c37bd9326ada56d9955e8494df79312f 100644 (file)
@@ -6,16 +6,14 @@
 namespace Friendica\Util;
 
 use Friendica\Core\Config;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Util\Crypto;
-use Friendica\Util\HTTPHeaders;
-use dba;
 
 /**
  * @brief Implements HTTP Signatures per draft-cavage-http-signatures-07.
  *
  * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/Zotlabs/Web/HTTPSig.php
- * 
+ *
  * @see https://tools.ietf.org/html/draft-cavage-http-signatures-07
  */
 
@@ -26,13 +24,13 @@ class HTTPSignature
         *
         * Disabled until Friendica's ActivityPub implementation
         * is ready.
-        * 
+        *
         * @see https://tools.ietf.org/html/rfc5843
         *
         * @param string  $body The value to create the digest for
         * @param boolean $set  (optional, default true)
         *   If set send a Digest HTTP header
-        * 
+        *
         * @return string The generated digest of $body
         */
 //     public static function generateDigest($body, $set = true)
@@ -174,7 +172,7 @@ class HTTPSignature
 
        /**
         * Fetch the public key for Activity Pub contact.
-        * 
+        *
         * @param string|int The identifier (contact addr or contact ID).
         * @return string|boolean The public key or false on failure.
         */
@@ -222,7 +220,7 @@ class HTTPSignature
         * @param string  $alg (optional, default 'sha256')
         * @param string  $crypt_key (optional, default null)
         * @param string  $crypt_algo (optional, default 'aes256ctr')
-        * 
+        *
         * @return array
         */
        public static function createSig($request, $head, $prvkey, $keyid = 'Key', $send_headers = false, $auth = false, $alg = 'sha256', $crypt_key = null, $crypt_algo = 'aes256ctr')
@@ -285,7 +283,7 @@ class HTTPSignature
         * @param array  $head
         * @param string $prvkey
         * @param string $alg (optional) default 'sha256'
-        * 
+        *
         * @return array
         */
        private static function sign($request, $head, $prvkey, $alg = 'sha256')
@@ -315,7 +313,7 @@ class HTTPSignature
 
                $ret['headers']   = $fields;
                $ret['signature'] = $sig;
-       
+
                return $ret;
        }
 
@@ -367,7 +365,7 @@ class HTTPSignature
         *
         * @param string $header
         * @param string $prvkey (optional), if not set use site private key
-        * 
+        *
         * @return array|string associative array, empty string if failue
         *   - \e string \b iv
         *   - \e string \b key
index 8fff3bcd87de9bab198bffcd4ce836480545191c..80761032e909ee2c1160d5a766ec5a278bc4e933 100644 (file)
@@ -5,15 +5,12 @@
  */
 namespace Friendica\Util;
 
+use DOMDocument;
+use DOMXPath;
 use Friendica\Content\OEmbed;
 use Friendica\Core\Addon;
+use Friendica\Database\dba;
 use Friendica\Object\Image;
-use Friendica\Util\Network;
-use Friendica\Util\XML;
-
-use dba;
-use DOMXPath;
-use DOMDocument;
 
 require_once 'include/dba.php';
 
index a0dfda3309987ceafb0d2e0a7fa549c696d14888..df7a18a1790e52e469e6fe2dc0d477005f138563 100644 (file)
@@ -4,12 +4,13 @@
  */
 namespace Friendica\Worker;
 
+use Friendica\BaseObject;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Util\DateTimeFormat;
-use dba;
 
 require_once 'include/dba.php';
 
@@ -17,7 +18,7 @@ class Cron
 {
        public static function execute($parameter = '', $generation = 0)
        {
-               $a = \Friendica\BaseObject::getApp();
+               $a = BaseObject::getApp();
 
                // Poll contacts with specific parameters
                if (!empty($parameter)) {
index 8b9d3b9bcf27879f4766952506a02db995b4297c..6454be3e5861055eff9a93c561d5b8af993f7e1b 100644 (file)
@@ -5,8 +5,10 @@
 namespace Friendica\Worker;
 
 use Friendica\App;
+use Friendica\BaseObject;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Database\PostUpdate;
 use Friendica\Model\Contact;
@@ -15,7 +17,6 @@ use Friendica\Model\Photo;
 use Friendica\Model\User;
 use Friendica\Network\Probe;
 use Friendica\Protocol\PortableContact;
-use dba;
 
 require_once 'include/dba.php';
 require_once 'mod/nodeinfo.php';
@@ -24,7 +25,7 @@ class CronJobs
 {
        public static function execute($command = '')
        {
-               $a = \Friendica\BaseObject::getApp();
+               $a = BaseObject::getApp();
 
                // No parameter set? So return
                if ($command == '') {
index 7a0b1f8473fa6120b89562c62386eae82ca4f37c..05955167f3e5f8a0adecf4eaef217865029338e7 100644 (file)
@@ -8,7 +8,7 @@ namespace Friendica\Worker;
 
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
-use dba;
+use Friendica\Database\dba;
 
 require_once 'include/dba.php';
 
index b2781d5874a9afe794df0a3815211dc98439659a..13ecc3ad449d7601806cf8303add82fe52bb86f1 100644 (file)
@@ -8,6 +8,7 @@ use Friendica\BaseObject;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
@@ -16,7 +17,6 @@ use Friendica\Model\User;
 use Friendica\Protocol\DFRN;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\Email;
-use dba;
 
 require_once 'include/items.php';
 
index c77830d60af7a19742dca670f951999bfccc9fbe..2e36ab514d54d7df499051643e528ea8bc8f67a3 100644 (file)
@@ -7,13 +7,13 @@ namespace Friendica\Worker;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\GContact;
 use Friendica\Network\Probe;
 use Friendica\Protocol\PortableContact;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
-use dba;
 
 class DiscoverPoCo
 {
index a4342722d5f5f50b501ce6264c63c56db4e48e6b..1d4efb29cd14cf7fdcf7b08742cfac29eb02dfa1 100644 (file)
@@ -6,12 +6,13 @@
 
 namespace Friendica\Worker;
 
+use Friendica\BaseObject;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Item;
-use dba;
 
 require_once 'include/dba.php';
 
@@ -19,7 +20,7 @@ class Expire
 {
        public static function execute($param = '', $hook_name = '')
        {
-               $a = \Friendica\BaseObject::getApp();
+               $a = BaseObject::getApp();
 
                require_once 'include/items.php';
 
index 385892f9916047ae61931d48cbe1301f8afaa5c1..986ade27bfa0487fca27d5d6b5e536d887cb31ed 100644 (file)
@@ -4,21 +4,21 @@
  */
 namespace Friendica\Worker;
 
+use Friendica\BaseObject;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
-use Friendica\Model\User;
 use Friendica\Model\PushSubscriber;
+use Friendica\Model\User;
 use Friendica\Network\Probe;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\Salmon;
-use Friendica\Worker\Delivery;
-use dba;
 
 require_once 'include/dba.php';
 require_once 'include/items.php';
@@ -52,7 +52,7 @@ class Notifier
 {
        public static function execute($cmd, $item_id)
        {
-               $a = \Friendica\BaseObject::getApp();
+               $a = BaseObject::getApp();
 
                logger('notifier: invoked: '.$cmd.': '.$item_id, LOGGER_DEBUG);
 
index 951a20b0124436a8bea02cb13c0422ddbd34f82a..7704c3826ac22234dbe3c145a20b6775d9523dec 100644 (file)
@@ -4,9 +4,11 @@
  */
 namespace Friendica\Worker;
 
+use Friendica\BaseObject;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
@@ -15,7 +17,6 @@ use Friendica\Protocol\PortableContact;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\XML;
-use dba;
 
 require_once 'include/dba.php';
 
@@ -23,7 +24,7 @@ class OnePoll
 {
        public static function execute($contact_id = 0, $command = '')
        {
-               $a = \Friendica\BaseObject::getApp();
+               $a = BaseObject::getApp();
 
                require_once 'include/items.php';
 
index b90fc11a499810e71f22596932877f040d63a824..50f01e294e2311374bb2fede2270639f014456da 100644 (file)
@@ -5,13 +5,13 @@
 
 namespace Friendica\Worker;
 
-use Friendica\App;
+use Friendica\BaseObject;
 use Friendica\Core\System;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
+use Friendica\Model\PushSubscriber;
 use Friendica\Protocol\OStatus;
 use Friendica\Util\Network;
-use Friendica\Model\PushSubscriber;
-use dba;
 
 require_once 'include/items.php';
 
@@ -28,7 +28,7 @@ class PubSubPublish
 
        private static function publish($id)
        {
-               $a = \Friendica\BaseObject::getApp();
+               $a = BaseObject::getApp();
 
                $subscriber = dba::selectFirst('push_subscriber', [], ['id' => $id]);
                if (!DBM::is_result($subscriber)) {
index 1ec40905657cb16236862b8c2c53f8530ac4b752..53d93ba910db71ce6fefbb7fc51851d81c914bce 100644 (file)
@@ -8,15 +8,15 @@ use Friendica\Core\Addon;
 use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Model\Queue as QueueModel;
 use Friendica\Model\PushSubscriber;
+use Friendica\Model\Queue as QueueModel;
 use Friendica\Model\User;
 use Friendica\Protocol\DFRN;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\PortableContact;
 use Friendica\Protocol\Salmon;
-use dba;
 
 require_once 'include/dba.php';
 require_once 'include/items.php';
index 9a7a257770ba8982b42d6df1fca13341e08babd6..aa2325d5492e4bd67073b4fdcc1b2bfc80a47847 100644 (file)
@@ -5,8 +5,7 @@
  */
 namespace Friendica\Worker;
 
-use Friendica\Core\Config;
-use dba;
+use Friendica\Database\dba;
 
 require_once 'include/dba.php';
 
index 1ecc4b5e9b1aee6f82d7d97d79a702d0852c435a..6db06380c8515c876ab7f6884db516c94f38f383 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace Friendica\Worker;
 
-use dba;
+use Friendica\Database\dba;
 
 class TagUpdate
 {
index 579e45084d5617277b5f71fa367bf36b025534b7..9f0990a72d5e0e420a3f97c93d67ba4df9977a71 100644 (file)
@@ -5,12 +5,11 @@
 
 namespace Friendica\Test;
 
-use dba;
-use Friendica\Database\DBStructure;
-use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
+use Friendica\Database\dba;
 use PHPUnit\DbUnit\DataSet\YamlDataSet;
 use PHPUnit\DbUnit\TestCaseTrait;
 use PHPUnit\Framework\TestCase;
+use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
 
 /**
  * Abstract class used by tests that need a database.
index f55ab0f9e26f54145b9cc28449ac89ed7e087e55..1fd728888e962d17c9cd54aa261985a8f8bdf9b3 100644 (file)
@@ -2,12 +2,8 @@
 
 namespace Friendica\Test\src\Core\Lock;
 
-use dba;
 use Friendica\Core\Lock\DatabaseLockDriver;
-use Friendica\Database\DBStructure;
-use PHPUnit\DbUnit\DataSet\YamlDataSet;
-use PHPUnit\DbUnit\TestCaseTrait;
-use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
+use Friendica\Database\dba;
 
 class DatabaseLockDriverTest extends LockTest
 {
index ca427186d4bb547b11f073672e63463c0f43a9aa..47055852ca10deb6b04f2bd32e6fc55de3c0711e 100644 (file)
@@ -2,13 +2,14 @@
 
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
+use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\User;
-use Friendica\Core\L10n;
 
 require_once 'include/dba.php';