Rename Friendica\Database\dba to Friendica\Database\DBA

This commit is contained in:
Hypolite Petovan 2018-07-20 08:19:26 -04:00
parent b6a1df0598
commit af6dbc654f
127 changed files with 1169 additions and 1169 deletions

View file

@ -8,7 +8,7 @@ namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Content\Feature;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
@ -100,13 +100,13 @@ class ACL extends BaseObject
$o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"" . $x['size'] . "$\" $tabindex >\r\n";
}
$stmt = dba::p("SELECT `id`, `name`, `url`, `network` FROM `contact`
$stmt = DBA::p("SELECT `id`, `name`, `url`, `network` FROM `contact`
WHERE `uid` = ? AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
$sql_extra
ORDER BY `name` ASC ", intval(local_user())
);
$contacts = dba::inArray($stmt);
$contacts = DBA::inArray($stmt);
$arr = ['contact' => $contacts, 'entry' => $o];
@ -165,13 +165,13 @@ class ACL extends BaseObject
$o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\"$tabindex_attr$hidepreselected>\r\n";
$stmt = dba::p("SELECT `id`, `name`, `url`, `network` FROM `contact`
$stmt = DBA::p("SELECT `id`, `name`, `url`, `network` FROM `contact`
WHERE `uid` = ? AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
$sql_extra
ORDER BY `name` ASC ", intval(local_user())
);
$contacts = dba::inArray($stmt);
$contacts = DBA::inArray($stmt);
$arr = ['contact' => $contacts, 'entry' => $o];
@ -268,7 +268,7 @@ class ACL extends BaseObject
$pubmail_enabled = false;
if (!$imap_disabled) {
$mailacct = dba::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', local_user()]);
$mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', local_user()]);
if (DBM::is_result($mailacct)) {
$mail_enabled = true;
$pubmail_enabled = !empty($mailacct['pubmail']);

View file

@ -5,7 +5,7 @@
namespace Friendica\Core;
use Friendica\App;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
require_once 'include/dba.php';
@ -24,7 +24,7 @@ class Addon
public static function uninstall($addon)
{
logger("Addons: uninstalling " . $addon);
dba::delete('addon', ['name' => $addon]);
DBA::delete('addon', ['name' => $addon]);
@include_once('addon/' . $addon . '/' . $addon . '.php');
if (function_exists($addon . '_uninstall')) {
@ -55,7 +55,7 @@ class Addon
$addon_admin = (function_exists($addon."_addon_admin") ? 1 : 0);
dba::insert('addon', ['name' => $addon, 'installed' => true,
DBA::insert('addon', ['name' => $addon, 'installed' => true,
'timestamp' => $t, 'plugin_admin' => $addon_admin]);
// we can add the following with the previous SQL
@ -63,7 +63,7 @@ class Addon
// This way the system won't fall over dead during the update.
if (file_exists('addon/' . $addon . '/.hidden')) {
dba::update('addon', ['hidden' => true], ['name' => $addon]);
DBA::update('addon', ['hidden' => true], ['name' => $addon]);
}
return true;
} else {
@ -79,9 +79,9 @@ class Addon
{
$addons = Config::get('system', 'addon');
if (strlen($addons)) {
$r = dba::select('addon', [], ['installed' => 1]);
$r = DBA::select('addon', [], ['installed' => 1]);
if (DBM::is_result($r)) {
$installed = dba::inArray($r);
$installed = DBA::inArray($r);
} else {
$installed = [];
}
@ -108,7 +108,7 @@ class Addon
$func = $addon . '_install';
$func();
}
dba::update('addon', ['timestamp' => $t], ['id' => $i['id']]);
DBA::update('addon', ['timestamp' => $t], ['id' => $i['id']]);
}
}
}
@ -125,7 +125,7 @@ class Addon
*/
public static function isEnabled($addon)
{
return dba::exists('addon', ['installed' => true, 'name' => $addon]);
return DBA::exists('addon', ['installed' => true, 'name' => $addon]);
}
@ -141,12 +141,12 @@ class Addon
public static function registerHook($hook, $file, $function, $priority = 0)
{
$condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
$exists = dba::exists('hook', $condition);
$exists = DBA::exists('hook', $condition);
if ($exists) {
return true;
}
$r = dba::insert('hook', ['hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority]);
$r = DBA::insert('hook', ['hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority]);
return $r;
}
@ -162,7 +162,7 @@ class Addon
public static function unregisterHook($hook, $file, $function)
{
$condition = ['hook' => $hook, 'file' => $file, 'function' => $function];
$r = dba::delete('hook', $condition);
$r = DBA::delete('hook', $condition);
return $r;
}
@ -173,15 +173,15 @@ class Addon
{
$a = get_app();
$a->hooks = [];
$r = dba::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
$r = DBA::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
while ($rr = dba::fetch($r)) {
while ($rr = DBA::fetch($r)) {
if (! array_key_exists($rr['hook'], $a->hooks)) {
$a->hooks[$rr['hook']] = [];
}
$a->hooks[$rr['hook']][] = [$rr['file'],$rr['function']];
}
dba::close($r);
DBA::close($r);
}
/**
@ -245,7 +245,7 @@ class Addon
} else {
// remove orphan hooks
$condition = ['hook' => $name, 'file' => $hook[0], 'function' => $hook[1]];
dba::delete('hook', $condition, ['cascade' => false]);
DBA::delete('hook', $condition, ['cascade' => false]);
}
}

View file

@ -3,7 +3,7 @@
namespace Friendica\Core\Cache;
use Friendica\Core\Cache;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
use Friendica\Util\DateTimeFormat;
@ -16,7 +16,7 @@ class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver
{
public function get($key)
{
$cache = dba::selectFirst('cache', ['v'], ['`k` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);
$cache = DBA::selectFirst('cache', ['v'], ['`k` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);
if (DBM::is_result($cache)) {
$cached = $cache['v'];
@ -41,20 +41,20 @@ class DatabaseCacheDriver extends AbstractCacheDriver implements ICacheDriver
'updated' => DateTimeFormat::utcNow()
];
return dba::update('cache', $fields, ['k' => $key], true);
return DBA::update('cache', $fields, ['k' => $key], true);
}
public function delete($key)
{
return dba::delete('cache', ['k' => $key]);
return DBA::delete('cache', ['k' => $key]);
}
public function clear($outdated = true)
{
if ($outdated) {
return dba::delete('cache', ['`expires` < NOW()']);
return DBA::delete('cache', ['`expires` < NOW()']);
} else {
return dba::delete('cache', ['`k` IS NOT NULL ']);
return DBA::delete('cache', ['`k` IS NOT NULL ']);
}
}
}

View file

@ -2,7 +2,7 @@
namespace Friendica\Core\Config;
use Friendica\BaseObject;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
require_once 'include/dba.php';
@ -27,8 +27,8 @@ class JITConfigAdapter extends BaseObject implements IConfigAdapter
return;
}
$configs = dba::select('config', ['v', 'k'], ['cat' => $cat]);
while ($config = dba::fetch($configs)) {
$configs = DBA::select('config', ['v', 'k'], ['cat' => $cat]);
while ($config = DBA::fetch($configs)) {
$k = $config['k'];
self::getApp()->setConfigValue($cat, $k, $config['v']);
@ -38,7 +38,7 @@ class JITConfigAdapter extends BaseObject implements IConfigAdapter
$this->in_db[$cat][$k] = true;
}
}
dba::close($configs);
DBA::close($configs);
}
public function get($cat, $k, $default_value = null, $refresh = false)
@ -56,7 +56,7 @@ class JITConfigAdapter extends BaseObject implements IConfigAdapter
}
}
$config = dba::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $k]);
$config = DBA::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $k]);
if (DBM::is_result($config)) {
// manage array value
$value = (preg_match("|^a:[0-9]+:{.*}$|s", $config['v']) ? unserialize($config['v']) : $config['v']);
@ -115,7 +115,7 @@ class JITConfigAdapter extends BaseObject implements IConfigAdapter
// manage array value
$dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
$result = dba::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $k], true);
$result = DBA::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $k], true);
if ($result) {
$this->in_db[$cat][$k] = true;
@ -131,7 +131,7 @@ class JITConfigAdapter extends BaseObject implements IConfigAdapter
unset($this->in_db[$cat][$k]);
}
$result = dba::delete('config', ['cat' => $cat, 'k' => $k]);
$result = DBA::delete('config', ['cat' => $cat, 'k' => $k]);
return $result;
}

View file

@ -2,7 +2,7 @@
namespace Friendica\Core\Config;
use Friendica\BaseObject;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
require_once 'include/dba.php';
@ -22,9 +22,9 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
{
$a = self::getApp();
$pconfigs = dba::select('pconfig', ['v', 'k'], ['cat' => $cat, 'uid' => $uid]);
$pconfigs = DBA::select('pconfig', ['v', 'k'], ['cat' => $cat, 'uid' => $uid]);
if (DBM::is_result($pconfigs)) {
while ($pconfig = dba::fetch($pconfigs)) {
while ($pconfig = DBA::fetch($pconfigs)) {
$k = $pconfig['k'];
self::getApp()->setPConfigValue($uid, $cat, $k, $pconfig['v']);
@ -35,7 +35,7 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
// Negative caching
$a->config[$uid][$cat] = "!<unset>!";
}
dba::close($pconfigs);
DBA::close($pconfigs);
}
public function get($uid, $cat, $k, $default_value = null, $refresh = false)
@ -58,7 +58,7 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
}
}
$pconfig = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
$pconfig = DBA::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
if (DBM::is_result($pconfig)) {
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $pconfig['v']) ? unserialize($pconfig['v']) : $pconfig['v']);
@ -94,7 +94,7 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
// manage array value
$dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
$result = dba::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $k], true);
$result = DBA::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $k], true);
if ($result) {
$this->in_db[$uid][$cat][$k] = true;
@ -111,7 +111,7 @@ class JITPConfigAdapter extends BaseObject implements IPConfigAdapter
unset($this->in_db[$uid][$cat][$k]);
}
$result = dba::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
$result = DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
return $result;
}

View file

@ -4,7 +4,7 @@ namespace Friendica\Core\Config;
use Exception;
use Friendica\BaseObject;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
require_once 'include/dba.php';
@ -31,11 +31,11 @@ class PreloadConfigAdapter extends BaseObject implements IConfigAdapter
return;
}
$configs = dba::select('config', ['cat', 'v', 'k']);
while ($config = dba::fetch($configs)) {
$configs = DBA::select('config', ['cat', 'v', 'k']);
while ($config = DBA::fetch($configs)) {
self::getApp()->setConfigValue($config['cat'], $config['k'], $config['v']);
}
dba::close($configs);
DBA::close($configs);
$this->config_loaded = true;
}
@ -43,7 +43,7 @@ class PreloadConfigAdapter extends BaseObject implements IConfigAdapter
public function get($cat, $k, $default_value = null, $refresh = false)
{
if ($refresh) {
$config = dba::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $k]);
$config = DBA::selectFirst('config', ['v'], ['cat' => $cat, 'k' => $k]);
if (DBM::is_result($config)) {
self::getApp()->setConfigValue($cat, $k, $config['v']);
}
@ -70,7 +70,7 @@ class PreloadConfigAdapter extends BaseObject implements IConfigAdapter
// manage array value
$dbvalue = is_array($value) ? serialize($value) : $value;
$result = dba::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $k], true);
$result = DBA::update('config', ['v' => $dbvalue], ['cat' => $cat, 'k' => $k], true);
if (!$result) {
throw new Exception('Unable to store config value in [' . $cat . '][' . $k . ']');
}
@ -82,7 +82,7 @@ class PreloadConfigAdapter extends BaseObject implements IConfigAdapter
{
self::getApp()->deleteConfigValue($cat, $k);
$result = dba::delete('config', ['cat' => $cat, 'k' => $k]);
$result = DBA::delete('config', ['cat' => $cat, 'k' => $k]);
return $result;
}

View file

@ -4,7 +4,7 @@ namespace Friendica\Core\Config;
use Exception;
use Friendica\BaseObject;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
require_once 'include/dba.php';
@ -35,11 +35,11 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
return;
}
$pconfigs = dba::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
while ($pconfig = dba::fetch($pconfigs)) {
$pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
while ($pconfig = DBA::fetch($pconfigs)) {
self::getApp()->setPConfigValue($uid, $pconfig['cat'], $pconfig['k'], $pconfig['v']);
}
dba::close($pconfigs);
DBA::close($pconfigs);
$this->config_loaded = true;
}
@ -51,7 +51,7 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
}
if ($refresh) {
$config = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
$config = DBA::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
if (DBM::is_result($config)) {
self::getApp()->setPConfigValue($uid, $cat, $k, $config['v']);
} else {
@ -83,7 +83,7 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
// manage array value
$dbvalue = is_array($value) ? serialize($value) : $value;
$result = dba::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $k], true);
$result = DBA::update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $k], true);
if (!$result) {
throw new Exception('Unable to store config value in [' . $uid . '][' . $cat . '][' . $k . ']');
}
@ -99,7 +99,7 @@ class PreloadPConfigAdapter extends BaseObject implements IPConfigAdapter
self::getApp()->deletePConfigValue($uid, $cat, $k);
$result = dba::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
$result = DBA::delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $k]);
return $result;
}

View file

@ -4,7 +4,7 @@ namespace Friendica\Core\Console;
use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use RuntimeException;
/**
@ -61,12 +61,12 @@ HELP;
}
$nurl = normalise_link($this->getArgument(0));
if (!dba::exists('contact', ['nurl' => $nurl, 'archive' => false])) {
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));
}
if (dba::update('contact', ['archive' => true], ['nurl' => $nurl])) {
if (DBA::update('contact', ['archive' => true], ['nurl' => $nurl])) {
$condition = ["`cid` IN (SELECT `id` FROM `contact` WHERE `archive`)"];
dba::delete('queue', $condition);
DBA::delete('queue', $condition);
$this->out(L10n::t('The contact entries have been archived'));
} else {
throw new RuntimeException('The contact archival failed.');

View file

@ -7,7 +7,7 @@ use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\Install;
use Friendica\Core\Theme;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use RuntimeException;
require_once 'mod/install.php';
@ -155,7 +155,7 @@ HELP;
);
if (!dba::connect($db_host, $db_user, $db_pass, $db_data)) {
if (!DBA::connect($db_host, $db_user, $db_pass, $db_data)) {
$result['status'] = false;
$result['help'] = 'Failed, please check your MySQL settings and credentials.';
}

View file

@ -3,7 +3,7 @@
namespace Friendica\Core\Console;
use Friendica\Core;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use RuntimeException;
@ -58,7 +58,7 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
}
if (!dba::connected()) {
if (!DBA::connected()) {
throw new RuntimeException('Unable to connect to database');
}

View file

@ -3,7 +3,7 @@
namespace Friendica\Core\Console;
use Friendica\Core\Protocol;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
use Friendica\Network\Probe;
use RuntimeException;
@ -81,9 +81,9 @@ HELP;
}
$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 . ')');

View file

@ -4,7 +4,7 @@ namespace Friendica\Core\Console;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
use Friendica\Model\User;
use RuntimeException;
@ -64,7 +64,7 @@ HELP;
$nick = $this->getArgument(0);
$user = dba::selectFirst('user', ['uid'], ['nickname' => $nick]);
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $nick]);
if (!DBM::is_result($user)) {
throw new RuntimeException(L10n::t('User not found'));
}

View file

@ -5,7 +5,7 @@
namespace Friendica\Core;
use Friendica\BaseObject;
use Friendica\Database\dba;
use Friendica\Database\DBA;
require_once 'boot.php';
require_once 'include/dba.php';
@ -111,8 +111,8 @@ class L10n extends BaseObject
$a->strings = [];
// load enabled addons strings
$addons = dba::select('addon', ['name'], ['installed' => true]);
while ($p = dba::fetch($addons)) {
$addons = DBA::select('addon', ['name'], ['installed' => true]);
while ($p = DBA::fetch($addons)) {
$name = $p['name'];
if (file_exists("addon/$name/lang/$lang/strings.php")) {
include "addon/$name/lang/$lang/strings.php";

View file

@ -3,7 +3,7 @@
namespace Friendica\Core\Lock;
use Friendica\Core\Cache;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
use Friendica\Util\DateTimeFormat;
@ -21,8 +21,8 @@ class DatabaseLockDriver extends AbstractLockDriver
$start = time();
do {
dba::lock('locks');
$lock = dba::selectFirst('locks', ['locked', 'pid'], ['`name` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);
DBA::lock('locks');
$lock = DBA::selectFirst('locks', ['locked', 'pid'], ['`name` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);
if (DBM::is_result($lock)) {
if ($lock['locked']) {
@ -32,16 +32,16 @@ class DatabaseLockDriver extends AbstractLockDriver
}
}
if (!$lock['locked']) {
dba::update('locks', ['locked' => true, 'pid' => getmypid(), 'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds')], ['name' => $key]);
DBA::update('locks', ['locked' => true, 'pid' => getmypid(), 'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds')], ['name' => $key]);
$got_lock = true;
}
} else {
dba::insert('locks', ['name' => $key, 'locked' => true, 'pid' => getmypid(), 'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds')]);
DBA::insert('locks', ['name' => $key, 'locked' => true, 'pid' => getmypid(), 'expires' => DateTimeFormat::utc('now + ' . $ttl . 'seconds')]);
$got_lock = true;
$this->markAcquire($key);
}
dba::unlock();
DBA::unlock();
if (!$got_lock && ($timeout > 0)) {
usleep(rand(100000, 2000000));
@ -56,7 +56,7 @@ class DatabaseLockDriver extends AbstractLockDriver
*/
public function releaseLock($key)
{
dba::delete('locks', ['name' => $key, 'pid' => getmypid()]);
DBA::delete('locks', ['name' => $key, 'pid' => getmypid()]);
$this->markRelease($key);
@ -68,7 +68,7 @@ class DatabaseLockDriver extends AbstractLockDriver
*/
public function releaseAll()
{
dba::delete('locks', ['pid' => getmypid()]);
DBA::delete('locks', ['pid' => getmypid()]);
$this->acquiredLocks = [];
}
@ -78,7 +78,7 @@ class DatabaseLockDriver extends AbstractLockDriver
*/
public function isLocked($key)
{
$lock = dba::selectFirst('locks', ['locked'], ['`name` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);
$lock = DBA::selectFirst('locks', ['locked'], ['`name` = ? AND `expires` >= ?', $key, DateTimeFormat::utcNow()]);
if (DBM::is_result($lock)) {
return $lock['locked'] !== false;

View file

@ -4,7 +4,7 @@ namespace Friendica\Core\Session;
use Friendica\BaseObject;
use Friendica\Core\Session;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
use SessionHandlerInterface;
@ -30,7 +30,7 @@ class DatabaseSessionHandler extends BaseObject implements SessionHandlerInterfa
return '';
}
$session = dba::selectFirst('session', ['data'], ['sid' => $session_id]);
$session = DBA::selectFirst('session', ['data'], ['sid' => $session_id]);
if (DBM::is_result($session)) {
Session::$exists = true;
return $session['data'];
@ -67,10 +67,10 @@ class DatabaseSessionHandler extends BaseObject implements SessionHandlerInterfa
if (Session::$exists) {
$fields = ['data' => $session_data, 'expire' => $expire];
$condition = ["`sid` = ? AND (`data` != ? OR `expire` != ?)", $session_id, $session_data, $expire];
dba::update('session', $fields, $condition);
DBA::update('session', $fields, $condition);
} else {
$fields = ['sid' => $session_id, 'expire' => $default_expire, 'data' => $session_data];
dba::insert('session', $fields);
DBA::insert('session', $fields);
}
return true;
@ -83,13 +83,13 @@ class DatabaseSessionHandler extends BaseObject implements SessionHandlerInterfa
public function destroy($id)
{
dba::delete('session', ['sid' => $id]);
DBA::delete('session', ['sid' => $id]);
return true;
}
public function gc($maxlifetime)
{
dba::delete('session', ["`expire` < ?", time()]);
DBA::delete('session', ["`expire` < ?", time()]);
return true;
}
}

View file

@ -5,7 +5,7 @@
namespace Friendica\Core;
use Friendica\App;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Model\Photo;
use Friendica\Object\Image;
@ -24,7 +24,7 @@ class UserImport
return 1;
}
return dba::lastInsertId();
return DBA::lastInsertId();
}
/**
@ -108,8 +108,8 @@ class UserImport
// check for username
// check if username matches deleted account
if (dba::exists('user', ['nickname' => $account['user']['nickname']])
|| dba::exists('userd', ['username' => $account['user']['nickname']])) {
if (DBA::exists('user', ['nickname' => $account['user']['nickname']])
|| DBA::exists('userd', ['username' => $account['user']['nickname']])) {
notice(L10n::t("User '%s' already exists on this server!", $account['user']['nickname']));
return;
}
@ -142,7 +142,7 @@ class UserImport
// import user
$r = self::dbImportAssoc('user', $account['user']);
if ($r === false) {
logger("uimport:insert user : ERROR : " . dba::errorMessage(), LOGGER_NORMAL);
logger("uimport:insert user : ERROR : " . DBA::errorMessage(), LOGGER_NORMAL);
notice(L10n::t("User creation error"));
return;
}
@ -160,9 +160,9 @@ class UserImport
$profile['uid'] = $newuid;
$r = self::dbImportAssoc('profile', $profile);
if ($r === false) {
logger("uimport:insert profile " . $profile['profile-name'] . " : ERROR : " . dba::errorMessage(), LOGGER_NORMAL);
logger("uimport:insert profile " . $profile['profile-name'] . " : ERROR : " . DBA::errorMessage(), LOGGER_NORMAL);
info(L10n::t("User profile creation error"));
dba::delete('user', ['uid' => $newuid]);
DBA::delete('user', ['uid' => $newuid]);
return;
}
}
@ -198,7 +198,7 @@ class UserImport
$contact['uid'] = $newuid;
$r = self::dbImportAssoc('contact', $contact);
if ($r === false) {
logger("uimport:insert contact " . $contact['nick'] . "," . $contact['network'] . " : ERROR : " . dba::errorMessage(), LOGGER_NORMAL);
logger("uimport:insert contact " . $contact['nick'] . "," . $contact['network'] . " : ERROR : " . DBA::errorMessage(), LOGGER_NORMAL);
$errorcount++;
} else {
$contact['newid'] = self::lastInsertId();
@ -212,7 +212,7 @@ class UserImport
$group['uid'] = $newuid;
$r = self::dbImportAssoc('group', $group);
if ($r === false) {
logger("uimport:insert group " . $group['name'] . " : ERROR : " . dba::errorMessage(), LOGGER_NORMAL);
logger("uimport:insert group " . $group['name'] . " : ERROR : " . DBA::errorMessage(), LOGGER_NORMAL);
} else {
$group['newid'] = self::lastInsertId();
}
@ -237,7 +237,7 @@ class UserImport
if ($import == 2) {
$r = self::dbImportAssoc('group_member', $group_member);
if ($r === false) {
logger("uimport:insert group member " . $group_member['id'] . " : ERROR : " . dba::errorMessage(), LOGGER_NORMAL);
logger("uimport:insert group member " . $group_member['id'] . " : ERROR : " . DBA::errorMessage(), LOGGER_NORMAL);
}
}
}
@ -255,7 +255,7 @@ class UserImport
);
if ($r === false) {
logger("uimport:insert photo " . $photo['resource-id'] . "," . $photo['scale'] . " : ERROR : " . dba::errorMessage(), LOGGER_NORMAL);
logger("uimport:insert photo " . $photo['resource-id'] . "," . $photo['scale'] . " : ERROR : " . DBA::errorMessage(), LOGGER_NORMAL);
}
}
@ -263,7 +263,7 @@ class UserImport
$pconfig['uid'] = $newuid;
$r = self::dbImportAssoc('pconfig', $pconfig);
if ($r === false) {
logger("uimport:insert pconfig " . $pconfig['id'] . " : ERROR : " . dba::errorMessage(), LOGGER_NORMAL);
logger("uimport:insert pconfig " . $pconfig['id'] . " : ERROR : " . DBA::errorMessage(), LOGGER_NORMAL);
}
}

View file

@ -4,7 +4,7 @@
*/
namespace Friendica\Core;
use Friendica\Database\dba;
use Friendica\Database\DBA;
use Friendica\Database\DBM;
use Friendica\Model\Process;
use Friendica\Util\DateTimeFormat;
@ -151,7 +151,7 @@ class Worker
*/
private static function totalEntries()
{
return dba::count('workerqueue', ["`executed` <= ? AND NOT `done`", NULL_DATE]);
return DBA::count('workerqueue', ["`executed` <= ? AND NOT `done`", NULL_DATE]);
}
/**
@ -162,7 +162,7 @@ class Worker
private static function highestPriority()
{
$condition = ["`executed` <= ? AND NOT `done`", NULL_DATE];
$workerqueue = dba::selectFirst('workerqueue', ['priority'], $condition, ['order' => ['priority']]);
$workerqueue = DBA::selectFirst('workerqueue', ['priority'], $condition, ['order' => ['priority']]);
if (DBM::is_result($workerqueue)) {
return $workerqueue["priority"];
} else {
@ -180,7 +180,7 @@ class Worker
private static function processWithPriorityActive($priority)
{
$condition = ["`priority` <= ? AND `executed` > ? AND NOT `done`", $priority, NULL_DATE];
return dba::exists('workerqueue', $condition);
return DBA::exists('workerqueue', $condition);
}
/**
@ -230,7 +230,7 @@ class Worker
if ($age > 1) {
$stamp = (float)microtime(true);
dba::update('workerqueue', ['executed' => DateTimeFormat::utcNow()], ['pid' => $mypid, 'done' => false]);
DBA::update('workerqueue', ['executed' => DateTimeFormat::utcNow()], ['pid' => $mypid, 'done' => false]);
self::$db_duration += (microtime(true) - $stamp);
}
@ -239,7 +239,7 @@ class Worker
self::execFunction($queue, $include, $argv, true);
$stamp = (float)microtime(true);
if (dba::update('workerqueue', ['done' => true], ['id' => $queue["id"]])) {
if (DBA::update('workerqueue', ['done' => true], ['id' => $queue["id"]])) {
Config::set('system', 'last_worker_execution', DateTimeFormat::utcNow());
}
self::$db_duration = (microtime(true) - $stamp);
@ -254,7 +254,7 @@ class Worker
if (!validate_include($include)) {
logger("Include file ".$argv[0]." is not valid!");
dba::delete('workerqueue', ['id' => $queue["id"]]);
DBA::delete('workerqueue', ['id' => $queue["id"]]);
return true;
}
@ -273,20 +273,20 @@ class Worker
if ($age > 1) {
$stamp = (float)microtime(true);
dba::update('workerqueue', ['executed' => DateTimeFormat::utcNow()], ['pid' => $mypid, 'done' => false]);
DBA::update('workerqueue', ['executed' => DateTimeFormat::utcNow()], ['pid' => $mypid, 'done' => false]);
self::$db_duration += (microtime(true) - $stamp);
}
self::execFunction($queue, $funcname, $argv, false);
$stamp = (float)microtime(true);
if (dba::update('workerqueue', ['done' => true], ['id' => $queue["id"]])) {
if (DBA::update('workerqueue', ['done' => true], ['id' => $queue["id"]])) {
Config::set('system', 'last_worker_execution', DateTimeFormat::utcNow());
}
self::$db_duration = (microtime(true) - $stamp);
} else {
logger("Function ".$funcname." does not exist");
dba::delete('workerqueue', ['id' => $queue["id"]]);
DBA::delete('workerqueue', ['id' => $queue["id"]]);
}
return true;
@ -477,13 +477,13 @@ class Worker
if ($max == 0) {
// the maximum number of possible user connections can be a system variable
$r = dba::fetch_first("SHOW VARIABLES WHERE `variable_name` = 'max_user_connections'");
$r = DBA::fetch_first("SHOW VARIABLES WHERE `variable_name` = 'max_user_connections'");
if (DBM::is_result($r)) {
$max = $r["Value"];
}
// Or it can be granted. This overrides the system variable
$r = dba::p('SHOW GRANTS');
while ($grants = dba::fetch($r)) {
$r = DBA::p('SHOW GRANTS');
while ($grants = DBA::fetch($r)) {
$grant = array_pop($grants);
if (stristr($grant, "GRANT USAGE ON")) {
if (preg_match("/WITH MAX_USER_CONNECTIONS (\d*)/", $grant, $match)) {
@ -491,15 +491,15 @@ class Worker
}
}
}
dba::close($r);
DBA::close($r);
}
// If $max is set we will use the processlist to determine the current number of connections
// The processlist only shows entries of the current user
if ($max != 0) {
$r = dba::p('SHOW PROCESSLIST');
$used = dba::num_rows($r);
dba::close($r);
$r = DBA::p('SHOW PROCESSLIST');
$used = DBA::num_rows($r);
DBA::close($r);
logger("Connection usage (user values): ".$used."/".$max, LOGGER_DEBUG);
@ -513,7 +513,7 @@ class Worker
// We will now check for the system values.
// This limit could be reached although the user limits are fine.
$r = dba::fetch_first("SHOW VARIABLES WHERE `variable_name` = 'max_connections'");
$r = DBA::fetch_first("SHOW VARIABLES WHERE `variable_name` = 'max_connections'");
if (!DBM::is_result($r)) {
return false;
}
@ -521,7 +521,7 @@ class Worker
if ($max == 0) {
return false;
}
$r = dba::fetch_first("SHOW STATUS WHERE `variable_name` = 'Threads_connected'");
$r = DBA::fetch_first("SHOW STATUS WHERE `variable_name` = 'Threads_connected'");
if (!DBM::is_result($r)) {
return false;
}
@ -546,16 +546,16 @@ class Worker
*/
private static function killStaleWorkers()
{
$entries = dba::select(
$entries = DBA::select(
'workerqueue',
['id', 'pid', 'executed', 'priority', 'parameter'],
['`executed` > ? AND NOT `done` AND `pid` != 0', NULL_DATE],
['order' => ['priority', 'created']]
);
while ($entry = dba::fetch($entries)) {
while ($entry = DBA::fetch($entries)) {
if (!posix_kill($entry["pid"], 0)) {
dba::update(
DBA::update(
'workerqueue',
['executed' => NULL_DATE, 'pid' => 0],
['id' => $entry["id"]]
@ -591,7 +591,7 @@ class Worker
} elseif ($entry["priority"] != PRIORITY_CRITICAL) {
$new_priority = PRIORITY_NEGLIGIBLE;
}
dba::update(
DBA::update(
'workerqueue',
['executed' => NULL_DATE, 'created' => DateTimeFormat::utcNow(), 'priority' => $new_priority, 'pid' => 0],
['id' => $entry["id"]]
@ -637,37 +637,37 @@ class Worker
$listitem = [];
// Adding all processes with no workerqueue entry
$processes = dba::p(
$processes = DBA::p(
"SELECT COUNT(*) AS `running` FROM `process` WHERE NOT EXISTS
(SELECT id FROM `workerqueue`
WHERE `workerqueue`.`pid` = `process`.`pid` AND NOT `done` AND `pid` != ?)",
getmypid()
);
if ($process = dba::fetch($processes)) {
if ($process = DBA::fetch($processes)) {
$listitem[0] = "0:".$process["running"];
}
dba::close($processes);
DBA::close($processes);
// Now adding all processes with workerqueue entries
$entries = dba::p("SELECT COUNT(*) AS `entries`, `priority` FROM `workerqueue` WHERE NOT `done` GROUP BY `priority`");
while ($entry = dba::fetch($entries)) {
$processes = dba::p("SELECT COUNT(*) AS `running` FROM `process` INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` AND NOT `done` WHERE `priority` = ?", $entry["priority"]);
if ($process = dba::fetch($processes)) {
$entries = DBA::p("SELECT COUNT(*) AS `entries`, `priority` FROM `workerqueue` WHERE NOT `done` GROUP BY `priority`");
while ($entry = DBA::fetch($entries)) {
$processes = DBA::p("SELECT COUNT(*) AS `running` FROM `process` INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` AND NOT `done` WHERE `priority` = ?", $entry["priority"]);
if ($process = DBA::fetch($processes)) {
$listitem[$entry["priority"]] = $entry["priority"].":".$process["running"]."/".$entry["entries"];
}
dba::close($processes);
DBA::close($processes);
}
dba::close($entries);
DBA::close($entries);
$intervals = [1, 10, 60];
$jobs_per_minute = [];
foreach ($intervals as $interval) {
$jobs = dba::p("SELECT COUNT(*) AS `jobs` FROM `workerqueue` WHERE `done` AND `executed` > UTC_TIMESTAMP() - INTERVAL ".intval($interval)." MINUTE");
if ($job = dba::fetch($jobs)) {
$jobs = DBA::p("SELECT COUNT(*) AS `jobs` FROM `workerqueue` WHERE `done` AND `executed` > UTC_TIMESTAMP() - INTERVAL ".intval($interval)." MINUTE");
if ($job = DBA::fetch($jobs)) {
$jobs_per_minute[$interval] = number_format($job['jobs'] / $interval, 0);
}
dba::close($jobs);
DBA::close($jobs);
}
$processlist = ' - jpm: '.implode('/', $jobs_per_minute).' ('.implode(', ', $listitem).')';
}
@ -712,7 +712,7 @@ class Worker
*/
private static function activeWorkers()
{
return dba::count('process', ['command' => 'Worker.php']);
return DBA::count('process', ['command' => 'Worker.php']);
}
/**
@ -728,7 +728,7 @@ class Worker
{
$highest_priority = 0;
$r = dba::p(
$r = DBA::p(
"SELECT `priority`
FROM `process`
INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` AND NOT `done`"
@ -739,10 +739,10 @@ class Worker
return false;
}
$priorities = [];
while ($line = dba::fetch($r)) {
while ($line = DBA::fetch($r)) {
$priorities[] = $line["priority"];
}
dba::close($r);
DBA::close($r);
// Should not happen
if (count($priorities) == 0) {
@ -801,33 +801,33 @@ class Worker
$ids = [];
if (self::passingSlow($highest_priority)) {
// Are there waiting processes with a higher priority than the currently highest?
$result = dba::select(
$result = DBA::select(
'workerqueue',
['id'],
["`executed` <= ? AND `priority` < ? AND NOT `done`", NULL_DATE, $highest_priority],
['limit' => $limit, 'order' => ['priority', 'created']]
);
while ($id = dba::fetch($result)) {
while ($id = DBA::fetch($result)) {
$ids[] = $id["id"];
}
dba::close($result);
DBA::close($result);
$found = (count($ids) > 0);
if (!$found) {
// Give slower processes some processing time
$result = dba::select(
$result = DBA::select(
'workerqueue',
['id'],
["`executed` <= ? AND `priority` > ? AND NOT `done`", NULL_DATE, $highest_priority],
['limit' => $limit, 'order' => ['priority', 'created']]
);
while ($id = dba::fetch($result)) {
while ($id = DBA::fetch($result)) {
$ids[] = $id["id"];
}
dba::close($result);
DBA::close($result);
$found = (count($ids) > 0);
$passing_slow = $found;
@ -836,17 +836,17 @@ class Worker
// If there is no result (or we shouldn't pass lower processes) we check without priority limit
if (!$found) {
$result = dba::select(
$result = DBA::select(
'workerqueue',
['id'],
["`executed` <= ? AND NOT `done`", NULL_DATE],
['limit' => $limit, 'order' => ['priority', 'created']]
);
while ($id = dba::fetch($result)) {
while ($id = DBA::fetch($result)) {
$ids[] = $id["id"];
}
dba::close($result);
DBA::close($result);
$found = (count($ids) > 0);
}
@ -854,7 +854,7 @@ class Worker
if ($found) {
$condition = "`id` IN (".substr(str_repeat("?, ", count($ids)), 0, -2).") AND `pid` = 0 AND NOT `done`";
array_unshift($ids, $condition);
dba::update('workerqueue', ['executed' => DateTimeFormat::utcNow(), 'pid' => $mypid], $ids);
DBA::update('workerqueue', ['executed' => DateTimeFormat::utcNow(), 'pid' => $mypid], $ids);
}
return $found;
@ -871,12 +871,12 @@ class Worker
$stamp = (float)microtime(true);
// There can already be jobs for us in the queue.
$r = dba::select('workerqueue', [], ['pid' => getmypid(), 'done' => false]);
$r = DBA::select('workerqueue', [], ['pid' => getmypid(), 'done' => false]);
if (DBM::is_result($r)) {
self::$db_duration += (microtime(true) - $stamp);
return dba::inArray($r);
return DBA::inArray($r);
}
dba::close($r);
DBA::close($r);
$stamp = (float)microtime(true);
if (!Lock::acquire('worker_process')) {
@ -891,8 +891,8 @@ class Worker
Lock::release('worker_process');
if ($found) {
$r = dba::select('workerqueue', [], ['pid' => getmypid(), 'done' => false]);
return dba::inArray($r);
$r = DBA::select('workerqueue', [], ['pid' => getmypid(), 'done' => false]);
return DBA::inArray($r);
}
return false;
}
@ -905,7 +905,7 @@ class Worker
{
$mypid = getmypid();
dba::update('workerqueue', ['executed' => NULL_DATE, 'pid' => 0], ['pid' => $mypid, 'done' => false]);
DBA::update('workerqueue', ['executed' => NULL_DATE, 'pid' => 0], ['pid' => $mypid, 'done' => false]);
}
/**
@ -983,7 +983,7 @@ class Worker
/// @todo We should clean up the corresponding workerqueue entries as well
$condition = ["`created` < ? AND `command` = 'worker.php'",
DateTimeFormat::utc("now - ".$timeout." minutes")];
dba::delete('process', $condition);
DBA::delete('process', $condition);
}
/**
@ -1076,15 +1076,15 @@ class Worker
}
$parameters = json_encode($args);
$found = dba::exists('workerqueue', ['parameter' => $parameters, 'done' => false]);
$found = DBA::exists('workerqueue', ['parameter' => $parameters, 'done' => false]);
// Quit if there was a database error - a precaution for the update process to 3.5.3
if (dba::errorNo() != 0) {
if (DBA::errorNo() != 0) {
return false;
}
if (!$found) {
dba::insert('workerqueue', ['parameter' => $parameters, 'created' => $created, 'priority' => $priority]);
DBA::insert('workerqueue', ['parameter' => $parameters, 'created' => $created, 'priority' => $priority]);
}
// Should we quit and wait for the worker to be called as a cronjob?
@ -1152,7 +1152,7 @@ class Worker
*/
public static function IPCSetJobState($jobs)
{
dba::update('worker-ipc', ['jobs' => $jobs], ['key' => 1], true);
DBA::update('worker-ipc', ['jobs' => $jobs], ['key' => 1], true);
}
/**
@ -1163,7 +1163,7 @@ class Worker
*/
public static function IPCJobsExists()
{
$row = dba::selectFirst('worker-ipc', ['jobs'], ['key' => 1]);
$row = DBA::selectFirst('worker-ipc', ['jobs'], ['key' => 1]);
// When we don't have a row, no job is running
if (!DBM::is_result($row)) {