Some more replaced old database functions

This commit is contained in:
Michael 2017-11-22 07:21:19 +00:00
parent 663c38afed
commit 7c3fd2adb5
10 changed files with 65 additions and 107 deletions

View file

@ -1016,7 +1016,6 @@ class dba {
public static function update($table, $fields, $condition, $old_fields = array()) {
$table = self::escape($table);
if (count($condition) > 0) {
$array_element = each($condition);
$array_key = $array_element['key'];
if (is_int($array_key)) {
@ -1024,9 +1023,6 @@ class dba {
} else {
$condition_string = " WHERE `".implode("` = ? AND `", array_keys($condition))."` = ?";
}
} else {
$condition_string = "";
}
if (is_bool($old_fields)) {
$do_insert = $old_fields;

View file

@ -216,7 +216,7 @@ function event_delete($event_id) {
return;
}
q("DELETE FROM `event` WHERE `id` = %d", intval($event_id));
dba::delete('event', array('id' => $event_id));
logger("Deleted event ".$event_id, LOGGER_DEBUG);
}

View file

@ -2122,7 +2122,7 @@ function drop_item($id, $interactive = true) {
}
if ((local_user() == $item['uid']) || ($contact_id) || (! $interactive)) {
if ((local_user() == $item['uid']) || $contact_id || !$interactive) {
// Check if we should do HTML-based delete confirmation
if ($_REQUEST['confirm']) {
@ -2189,30 +2189,18 @@ function drop_item($id, $interactive = true) {
* generate a resource-id and therefore aren't intimately linked to the item.
*/
if (strlen($item['resource-id'])) {
q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ",
dbesc($item['resource-id']),
intval($item['uid'])
);
// ignore the result
dba::delete('photo', array('resource-id' => $item['resource-id'], 'uid' => $item['uid']));
}
// If item is a link to an event, nuke the event record.
if (intval($item['event-id'])) {
q("DELETE FROM `event` WHERE `id` = %d AND `uid` = %d",
intval($item['event-id']),
intval($item['uid'])
);
// ignore the result
dba::delete('event', array('id' => $item['event-id'], 'uid' => $item['uid']));
}
// If item has attachments, drop them
foreach (explode(", ", $item['attach']) as $attach) {
preg_match("|attach/(\d+)|", $attach, $matches);
q("DELETE FROM `attach` WHERE `id` = %d AND `uid` = %d",
intval($matches[1]),
local_user()
);
// ignore the result
dba::delete('attach', array('id' => $matches[1], 'uid' => $item['uid']));
}
// The new code splits the queries since the mysql optimizer really has bad problems with subqueries

View file

@ -163,9 +163,7 @@ function do_like($item_id, $verb) {
// Clean up the Diaspora signatures for this like
// Go ahead and do it even if Diaspora support is disabled. We still want to clean up
// if it had been enabled in the past
q("DELETE FROM `sign` WHERE `iid` = %d",
intval($like_item['id'])
);
dba::delete('sign', array('iid' => $like_item['id']));
$like_item_id = $like_item['id'];
Worker::add(PRIORITY_HIGH, "Notifier", "like", $like_item_id);

View file

@ -113,7 +113,7 @@ class FKOAuthDataStore extends OAuthDataStore {
}
q("DELETE FROM tokens WHERE id='%s'", $token->key);
dba::delete('tokens', array('id' => $token->key));
if (!is_null($ret) && $uverifier!==false){

View file

@ -34,11 +34,11 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
$a = get_app();
$r = q("SELECT * FROM `oembed` WHERE `url` = '%s'",
dbesc(normalise_link($embedurl)));
$condition = array('url' => normalise_link($embedurl));
$r = dba::select('oembed', array('content'), $condition, array('limit' => 1));
if (DBM::is_result($r)) {
$txt = $r[0]["content"];
$txt = $r["content"];
} else {
$txt = Cache::get($a->videowidth . $embedurl);
}

View file

@ -16,19 +16,16 @@ use Friendica\Database\DBM;
* @param string $plugin name of the addon
* @return boolean
*/
if (! function_exists('uninstall_plugin')){
function uninstall_plugin($plugin) {
logger("Addons: uninstalling " . $plugin);
q("DELETE FROM `addon` WHERE `name` = '%s' ",
dbesc($plugin)
);
dba::delete('addon', array('name' => $plugin));
@include_once('addon/' . $plugin . '/' . $plugin . '.php');
if (function_exists($plugin . '_uninstall')) {
$func = $plugin . '_uninstall';
$func();
}
}}
}
/**
* @brief installs an addon.
@ -36,12 +33,12 @@ function uninstall_plugin($plugin){
* @param string $plugin name of the addon
* @return bool
*/
if (! function_exists('install_plugin')){
function install_plugin($plugin) {
// silently fail if plugin was removed
if (! file_exists('addon/' . $plugin . '/' . $plugin . '.php'))
if (!file_exists('addon/' . $plugin . '/' . $plugin . '.php')) {
return false;
}
logger("Addons: installing " . $plugin);
$t = @filemtime('addon/' . $plugin . '/' . $plugin . '.php');
@include_once('addon/' . $plugin . '/' . $plugin . '.php');
@ -62,26 +59,24 @@ function install_plugin($plugin) {
dba::update('addon', array('hidden' => true), array('name' => $plugin));
}
return true;
}
else {
} else {
logger("Addons: FAILED installing " . $plugin);
return false;
}
}}
}
// reload all updated plugins
if (! function_exists('reload_plugins')) {
function reload_plugins() {
$plugins = Config::get('system', 'addon');
if (strlen($plugins)) {
$r = q("SELECT * FROM `addon` WHERE `installed` = 1");
if (DBM::is_result($r))
if (DBM::is_result($r)) {
$installed = $r;
else
} else {
$installed = array();
}
$parr = explode(',',$plugins);
@ -115,7 +110,7 @@ function reload_plugins() {
}
}
}}
}
/**
* @brief check if addon is enabled
@ -137,21 +132,17 @@ function plugin_enabled($plugin) {
* @param int $priority A priority (defaults to 0)
* @return mixed|bool
*/
if (! function_exists('register_hook')) {
function register_hook($hook, $file, $function, $priority=0) {
$r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
dbesc($hook),
dbesc($file),
dbesc($function)
);
if (DBM::is_result($r))
$condition = array('hook' => $hook, 'file' => $file, 'function' => $function);
$exists = dba::exists('hook', $condition);
if ($exists) {
return true;
}
$r = dba::insert('hook', array('hook' => $hook, 'file' => $file, 'function' => $function, 'priority' => $priority));
return $r;
}}
}
/**
* @brief unregisters a hook.
@ -161,16 +152,11 @@ function register_hook($hook,$file,$function,$priority=0) {
* @param string $function the name of the function that the hook called
* @return array
*/
if (! function_exists('unregister_hook')) {
function unregister_hook($hook, $file, $function) {
$r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s'",
dbesc($hook),
dbesc($file),
dbesc($function)
);
$condition = array('hook' => $hook, 'file' => $file, 'function' => $function);
$r = dba::delete('hook', $condition);
return $r;
}}
}
function load_hooks() {
@ -224,17 +210,13 @@ function call_single_hook($a, $name, $hook, &$data = null) {
$func($a, $data);
} else {
// remove orphan hooks
q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s'",
dbesc($name),
dbesc($hook[0]),
dbesc($hook[1])
);
$condition = array('hook' => $name, 'file' => $hook[0], 'function' => $hook[1]);
dba::delete('hook', $condition);
}
}
//check if an app_menu hook exist for plugin $name.
//Return true if the plugin is an app
if (! function_exists('plugin_is_app')) {
function plugin_is_app($name) {
$a = get_app();
@ -246,7 +228,7 @@ function plugin_is_app($name) {
}
return false;
}}
}
/**
* @brief Parse plugin comment in search of plugin infos.
@ -264,7 +246,6 @@ function plugin_is_app($name) {
* @return array with the plugin information
*/
if (! function_exists('get_plugin_info')){
function get_plugin_info($plugin) {
$a = get_app();
@ -310,7 +291,7 @@ function get_plugin_info($plugin){
}
return $info;
}}
}
/**
@ -329,7 +310,6 @@ function get_plugin_info($plugin){
* @return array
*/
if (! function_exists('get_theme_info')){
function get_theme_info($theme) {
$info=Array(
'name' => $theme,
@ -371,8 +351,7 @@ function get_theme_info($theme){
} else {
$info['author'][] = array('name'=>$v);
}
}
elseif ($k=="maintainer"){
} elseif ($k == "maintainer") {
$r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
if ($r) {
$info['maintainer'][] = array('name'=>$m[1], 'link'=>$m[2]);
@ -390,7 +369,7 @@ function get_theme_info($theme){
}
return $info;
}}
}
/**
* @brief Returns the theme's screenshot.
@ -411,7 +390,6 @@ function get_theme_screenshot($theme) {
}
// install and uninstall theme
if (! function_exists('uninstall_theme')){
function uninstall_theme($theme) {
logger("Addons: uninstalling theme " . $theme);
@ -420,9 +398,8 @@ function uninstall_theme($theme){
$func = "{$theme}_uninstall";
$func();
}
}}
}
if (! function_exists('install_theme')){
function install_theme($theme) {
// silently fail if theme was removed
@ -443,7 +420,7 @@ function install_theme($theme) {
return false;
}
}}
}
/**
* @brief Get the full path to relevant theme files by filename

View file

@ -13,9 +13,7 @@ function update_queue_time($id) {
function remove_queue_item($id) {
logger('queue: remove queue item ' . $id);
q("DELETE FROM `queue` WHERE `id` = %d",
intval($id)
);
dba::delete('queue', array('id' => $id));
}
/**

View file

@ -251,7 +251,7 @@ function delete_thread($itemid, $itemuri = "") {
}
// Using dba::delete at this time could delete the associated item entries
$result = q("DELETE FROM `thread` WHERE `iid` = %d", intval($itemid));
$result = dba::e("DELETE FROM `thread` WHERE `iid` = ?", $itemid);
logger("delete_thread: Deleted thread for item ".$itemid." - ".print_r($result, true), LOGGER_DEBUG);

View file

@ -155,14 +155,15 @@ class CronJobs {
if (!$cachetime) {
$cachetime = PROXY_DEFAULT_TIME;
}
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
$condition = array('`uid` = 0 AND `resource-id` LIKE "pic:%" AND `created` < NOW() - INTERVAL ? SECOND', $cachetime);
dba::delete('photo', $condition);
}
// Delete the cached OEmbed entries that are older than one year
q("DELETE FROM `oembed` WHERE `created` < NOW() - INTERVAL 3 MONTH");
// Delete the cached OEmbed entries that are older than three month
dba::delete('oembed', array("`created` < NOW() - INTERVAL 3 MONTH"));
// Delete the cached "parse_url" entries that are older than one year
q("DELETE FROM `parsed_url` WHERE `created` < NOW() - INTERVAL 3 MONTH");
// Delete the cached "parse_url" entries that are older than three month
dba::delete('parsed_url', array("`created` < NOW() - INTERVAL 3 MONTH"));
// Maximum table size in megabyte
$max_tablesize = intval(Config::get('system','optimize_max_tablesize')) * 1000000;