kopia lustrzana https://github.com/friendica/friendica
Replace old database queries with the new ones
rodzic
8f9757aba5
commit
4ad655ab80
|
@ -1763,13 +1763,10 @@ function api_statuses_home_timeline($type)
|
||||||
$idarray[] = intval($item["id"]);
|
$idarray[] = intval($item["id"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$idlist = implode(",", $idarray);
|
if (!empty($idarray)) {
|
||||||
|
$unseen = dba::exists('item', ['unseen' => true, 'id' => $idarray]);
|
||||||
if ($idlist != "") {
|
|
||||||
$unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `id` IN (%s)", $idlist);
|
|
||||||
|
|
||||||
if ($unseen) {
|
if ($unseen) {
|
||||||
q("UPDATE `item` SET `unseen` = 0 WHERE `unseen` AND `id` IN (%s)", $idlist);
|
Item::update(['unseen' => false], ['unseen' => true, 'id' => $idarray]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1106,9 +1106,7 @@ function admin_page_site_post(App $a)
|
||||||
Config::set('system', 'touch_icon', $touch_icon);
|
Config::set('system', 'touch_icon', $touch_icon);
|
||||||
|
|
||||||
if ($banner == "") {
|
if ($banner == "") {
|
||||||
// don't know why, but del_config doesn't work...
|
Config::delete('system', 'banner');
|
||||||
q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", dbesc("system"), dbesc("banner")
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
Config::set('system', 'banner', $banner);
|
Config::set('system', 'banner', $banner);
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,12 +283,9 @@ function dfrn_confirm_post(App $a, $handsfree = null)
|
||||||
notice(L10n::t('Remote site reported: ') . $message . EOL);
|
notice(L10n::t('Remote site reported: ') . $message . EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($status == 0) && ($intro_id)) {
|
if (($status == 0) && $intro_id) {
|
||||||
// Success. Delete the notification.
|
// Success. Delete the notification.
|
||||||
q("DELETE FROM `intro` WHERE `id` = %d AND `uid` = %d",
|
dba::delete('intro', ['id' => $intro_id]);
|
||||||
intval($intro_id),
|
|
||||||
intval($uid)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($status != 0) {
|
if ($status != 0) {
|
||||||
|
@ -360,10 +357,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
q("DELETE FROM `intro` WHERE `id` = %d AND `uid` = %d",
|
dba::delete('intro', ['id' => $intro_id]);
|
||||||
intval($intro_id),
|
|
||||||
intval($uid)
|
|
||||||
);
|
|
||||||
|
|
||||||
$r = q("UPDATE `contact` SET `name-date` = '%s',
|
$r = q("UPDATE `contact` SET `name-date` = '%s',
|
||||||
`uri-date` = '%s',
|
`uri-date` = '%s',
|
||||||
|
|
|
@ -140,7 +140,7 @@ function dfrn_poll_init(App $a)
|
||||||
|
|
||||||
if ($type === 'profile-check' && $dfrn_version < 2.2) {
|
if ($type === 'profile-check' && $dfrn_version < 2.2) {
|
||||||
if ((strlen($challenge)) && (strlen($sec))) {
|
if ((strlen($challenge)) && (strlen($sec))) {
|
||||||
q("DELETE FROM `profile_check` WHERE `expire` < " . intval(time()));
|
dba::delete('profile_check', ["`expire` < ?", time()]);
|
||||||
$r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1",
|
$r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1",
|
||||||
dbesc($sec)
|
dbesc($sec)
|
||||||
);
|
);
|
||||||
|
@ -205,7 +205,7 @@ function dfrn_poll_init(App $a)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
q("DELETE FROM `profile_check` WHERE `expire` < " . intval(time()));
|
dba::delete('profile_check', ["`expire` < ?", time()]);
|
||||||
$r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC",
|
$r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC",
|
||||||
dbesc($dfrn_id));
|
dbesc($dfrn_id));
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
|
@ -232,7 +232,7 @@ function dfrn_poll_post(App $a)
|
||||||
if (strlen($challenge) && strlen($sec)) {
|
if (strlen($challenge) && strlen($sec)) {
|
||||||
logger('dfrn_poll: POST: profile-check');
|
logger('dfrn_poll: POST: profile-check');
|
||||||
|
|
||||||
q("DELETE FROM `profile_check` WHERE `expire` < " . intval(time()));
|
dba::delete('profile_check', ["`expire` < ?", time()]);
|
||||||
$r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1",
|
$r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1",
|
||||||
dbesc($sec)
|
dbesc($sec)
|
||||||
);
|
);
|
||||||
|
@ -305,11 +305,7 @@ function dfrn_poll_post(App $a)
|
||||||
$type = $r[0]['type'];
|
$type = $r[0]['type'];
|
||||||
$last_update = $r[0]['last_update'];
|
$last_update = $r[0]['last_update'];
|
||||||
|
|
||||||
$r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s'",
|
dba::delete('challenge', ['dfrn-id' => $dfrn_id, 'challenge' => $challenge]);
|
||||||
dbesc($dfrn_id),
|
|
||||||
dbesc($challenge)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$sql_extra = '';
|
$sql_extra = '';
|
||||||
switch ($direction) {
|
switch ($direction) {
|
||||||
|
@ -414,7 +410,7 @@ function dfrn_poll_content(App $a)
|
||||||
|
|
||||||
$status = 0;
|
$status = 0;
|
||||||
|
|
||||||
$r = q("DELETE FROM `challenge` WHERE `expire` < " . intval(time()));
|
dba::delete('challenge', ["`expire` < ?", time()]);
|
||||||
|
|
||||||
if ($type !== 'profile') {
|
if ($type !== 'profile') {
|
||||||
$r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` , `type`, `last_update` )
|
$r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` , `type`, `last_update` )
|
||||||
|
|
|
@ -263,13 +263,9 @@ function dfrn_request_post(App $a)
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
foreach ($r as $rr) {
|
foreach ($r as $rr) {
|
||||||
if (!$rr['rel']) {
|
if (!$rr['rel']) {
|
||||||
q("DELETE FROM `contact` WHERE `id` = %d AND NOT `self`",
|
dba::delete('contact', ['id' => $rr['cid'], 'self' => false]);
|
||||||
intval($rr['cid'])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
q("DELETE FROM `intro` WHERE `id` = %d",
|
dba::delete('intro', ['id' => $rr['iid']]);
|
||||||
intval($rr['iid'])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,11 +148,7 @@ function message_content(App $a)
|
||||||
|
|
||||||
$cmd = $a->argv[1];
|
$cmd = $a->argv[1];
|
||||||
if ($cmd === 'drop') {
|
if ($cmd === 'drop') {
|
||||||
$r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
if (dba::delete('mail', ['id' => $a->argv[2]])) {
|
||||||
intval($a->argv[2]),
|
|
||||||
intval(local_user())
|
|
||||||
);
|
|
||||||
if ($r) {
|
|
||||||
info(L10n::t('Message deleted.') . EOL);
|
info(L10n::t('Message deleted.') . EOL);
|
||||||
}
|
}
|
||||||
//goaway(System::baseUrl(true) . '/message' );
|
//goaway(System::baseUrl(true) . '/message' );
|
||||||
|
@ -166,22 +162,7 @@ function message_content(App $a)
|
||||||
$parent = $r[0]['parent-uri'];
|
$parent = $r[0]['parent-uri'];
|
||||||
$convid = $r[0]['convid'];
|
$convid = $r[0]['convid'];
|
||||||
|
|
||||||
$r = q("DELETE FROM `mail` WHERE `parent-uri` = '%s' AND `uid` = %d ",
|
if (dba::delete('mail', ['parent-uri' => $parent, 'uid' => local_user()])) {
|
||||||
dbesc($parent),
|
|
||||||
intval(local_user())
|
|
||||||
);
|
|
||||||
|
|
||||||
// remove diaspora conversation pointer
|
|
||||||
// Actually if we do this, we can never receive another reply to that conversation,
|
|
||||||
// as we will never again have the info we need to re-create it.
|
|
||||||
// We'll just have to orphan it.
|
|
||||||
//if ($convid) {
|
|
||||||
// q("delete from conv where id = %d limit 1",
|
|
||||||
// intval($convid)
|
|
||||||
// );
|
|
||||||
//}
|
|
||||||
|
|
||||||
if ($r) {
|
|
||||||
info(L10n::t('Conversation removed.') . EOL);
|
info(L10n::t('Conversation removed.') . EOL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,8 +135,7 @@ function pubsubhubbub_init(App $a) {
|
||||||
dbesc($hub_callback));
|
dbesc($hub_callback));
|
||||||
|
|
||||||
// delete old subscription if it exists
|
// delete old subscription if it exists
|
||||||
q("DELETE FROM `push_subscriber` WHERE `callback_url` = '%s'",
|
dba::delete('push_subscriber', ['callback_url' => $hub_callback]);
|
||||||
dbesc($hub_callback));
|
|
||||||
|
|
||||||
if ($subscribe) {
|
if ($subscribe) {
|
||||||
$last_update = DateTimeFormat::utcNow();
|
$last_update = DateTimeFormat::utcNow();
|
||||||
|
|
|
@ -149,9 +149,7 @@ function settings_post(App $a)
|
||||||
check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
|
check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
|
||||||
|
|
||||||
$key = $_POST['remove'];
|
$key = $_POST['remove'];
|
||||||
q("DELETE FROM tokens WHERE id='%s' AND uid=%d",
|
dba::delete('tokens', ['id' => $key]);
|
||||||
dbesc($key),
|
|
||||||
local_user());
|
|
||||||
goaway(System::baseUrl(true)."/settings/oauth/");
|
goaway(System::baseUrl(true)."/settings/oauth/");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -714,9 +712,7 @@ function settings_content(App $a)
|
||||||
if (($a->argc > 3) && ($a->argv[2] === 'delete')) {
|
if (($a->argc > 3) && ($a->argv[2] === 'delete')) {
|
||||||
check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't');
|
check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't');
|
||||||
|
|
||||||
q("DELETE FROM clients WHERE client_id='%s' AND uid=%d",
|
dba::delete('clients', ['client_id' => $a->argv[3], 'uid' => local_user()]);
|
||||||
dbesc($a->argv[3]),
|
|
||||||
local_user());
|
|
||||||
goaway(System::baseUrl(true)."/settings/oauth/");
|
goaway(System::baseUrl(true)."/settings/oauth/");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,10 +239,8 @@ class GContact
|
||||||
|
|
||||||
if ($alternate && ($gcontact['network'] == NETWORK_OSTATUS)) {
|
if ($alternate && ($gcontact['network'] == NETWORK_OSTATUS)) {
|
||||||
// Delete the old entry - if it exists
|
// Delete the old entry - if it exists
|
||||||
$r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($orig_profile)));
|
if (dba::exists('item', ['nurl' => normalise_link($orig_profile)])) {
|
||||||
if (DBM::is_result($r)) {
|
dba::delete('gcontact', ['nurl' => normalise_link($orig_profile)]);
|
||||||
q("DELETE FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($orig_profile)));
|
|
||||||
q("DELETE FROM `glink` WHERE `gcid` = %d", intval($r[0]["id"]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,7 @@ class Term
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up all tags
|
// Clean up all tags
|
||||||
dba::e("DELETE FROM `term` WHERE `otype` = ? AND `oid` = ? AND `type` IN (?, ?)",
|
dba::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]]);
|
||||||
TERM_OBJ_POST, $itemid, TERM_HASHTAG, TERM_MENTION);
|
|
||||||
|
|
||||||
if ($message['deleted']) {
|
if ($message['deleted']) {
|
||||||
return;
|
return;
|
||||||
|
@ -135,11 +134,7 @@ class Term
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up all tags
|
// Clean up all tags
|
||||||
q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
|
dba::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_FILE, TERM_CATEGORY]]);
|
||||||
intval(TERM_OBJ_POST),
|
|
||||||
intval($itemid),
|
|
||||||
intval(TERM_FILE),
|
|
||||||
intval(TERM_CATEGORY));
|
|
||||||
|
|
||||||
if ($message["deleted"]) {
|
if ($message["deleted"]) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -2078,94 +2078,30 @@ class DFRN
|
||||||
// Update the gcontact entry
|
// Update the gcontact entry
|
||||||
$relocate["server_url"] = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $relocate["url"]);
|
$relocate["server_url"] = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $relocate["url"]);
|
||||||
|
|
||||||
$x = q(
|
$fields = ['name' => $relocate["name"], 'photo' => $relocate["avatar"],
|
||||||
"UPDATE `gcontact` SET
|
'url' => $relocate["url"], 'nurl' => normalise_link($relocate["url"]),
|
||||||
`name` = '%s',
|
'addr' => $relocate["addr"], 'connect' => $relocate["addr"],
|
||||||
`photo` = '%s',
|
'notify' => $relocate["notify"], 'server_url' => $relocate["server_url"]];
|
||||||
`url` = '%s',
|
dba::update('gcontact', $fields, ['nurl' => normalise_link($old["url"])]);
|
||||||
`nurl` = '%s',
|
|
||||||
`addr` = '%s',
|
|
||||||
`connect` = '%s',
|
|
||||||
`notify` = '%s',
|
|
||||||
`server_url` = '%s'
|
|
||||||
WHERE `nurl` = '%s';",
|
|
||||||
dbesc($relocate["name"]),
|
|
||||||
dbesc($relocate["avatar"]),
|
|
||||||
dbesc($relocate["url"]),
|
|
||||||
dbesc(normalise_link($relocate["url"])),
|
|
||||||
dbesc($relocate["addr"]),
|
|
||||||
dbesc($relocate["addr"]),
|
|
||||||
dbesc($relocate["notify"]),
|
|
||||||
dbesc($relocate["server_url"]),
|
|
||||||
dbesc(normalise_link($old["url"]))
|
|
||||||
);
|
|
||||||
|
|
||||||
// Update the contact table. We try to find every entry.
|
// Update the contact table. We try to find every entry.
|
||||||
$x = q(
|
$fields = ['name' => $relocate["name"], 'avatar' => $relocate["avatar"],
|
||||||
"UPDATE `contact` SET
|
'url' => $relocate["url"], 'nurl' => normalise_link($relocate["url"]),
|
||||||
`name` = '%s',
|
'addr' => $relocate["addr"], 'request' => $relocate["request"],
|
||||||
`avatar` = '%s',
|
'confirm' => $relocate["confirm"], 'notify' => $relocate["notify"],
|
||||||
`url` = '%s',
|
'poll' => $relocate["poll"], 'site-pubkey' => $relocate["sitepubkey"]];
|
||||||
`nurl` = '%s',
|
$condition = ["(`id` = ?) OR (`nurl` = ?)", $importer["id"], normalise_link($old["url"])];
|
||||||
`addr` = '%s',
|
|
||||||
`request` = '%s',
|
|
||||||
`confirm` = '%s',
|
|
||||||
`notify` = '%s',
|
|
||||||
`poll` = '%s',
|
|
||||||
`site-pubkey` = '%s'
|
|
||||||
WHERE (`id` = %d AND `uid` = %d) OR (`nurl` = '%s');",
|
|
||||||
dbesc($relocate["name"]),
|
|
||||||
dbesc($relocate["avatar"]),
|
|
||||||
dbesc($relocate["url"]),
|
|
||||||
dbesc(normalise_link($relocate["url"])),
|
|
||||||
dbesc($relocate["addr"]),
|
|
||||||
dbesc($relocate["request"]),
|
|
||||||
dbesc($relocate["confirm"]),
|
|
||||||
dbesc($relocate["notify"]),
|
|
||||||
dbesc($relocate["poll"]),
|
|
||||||
dbesc($relocate["sitepubkey"]),
|
|
||||||
intval($importer["id"]),
|
|
||||||
intval($importer["importer_uid"]),
|
|
||||||
dbesc(normalise_link($old["url"]))
|
|
||||||
);
|
|
||||||
|
|
||||||
Contact::updateAvatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true);
|
Contact::updateAvatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true);
|
||||||
|
|
||||||
if ($x === false) {
|
logger('Contacts are updated.');
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update items
|
// update items
|
||||||
/// @todo This is an extreme performance killer
|
// This is an extreme performance killer
|
||||||
$fields = [
|
Item::update(['owner-link' => $relocate["url"]], ['owner-link' => $old["url"], 'uid' => $importer["importer_uid"]]);
|
||||||
'owner-link' => [$old["url"], $relocate["url"]],
|
Item::update(['author-link' => $relocate["url"]], ['author-link' => $old["url"], 'uid' => $importer["importer_uid"]]);
|
||||||
'author-link' => [$old["url"], $relocate["url"]],
|
|
||||||
//'owner-avatar' => array($old["photo"], $relocate["photo"]),
|
|
||||||
//'author-avatar' => array($old["photo"], $relocate["photo"]),
|
|
||||||
];
|
|
||||||
foreach ($fields as $n => $f) {
|
|
||||||
$r = q(
|
|
||||||
"SELECT `id` FROM `item` WHERE `%s` = '%s' AND `uid` = %d LIMIT 1",
|
|
||||||
$n,
|
|
||||||
dbesc($f[0]),
|
|
||||||
intval($importer["importer_uid"])
|
|
||||||
);
|
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
logger('Items are updated.');
|
||||||
$x = q(
|
|
||||||
"UPDATE `item` SET `%s` = '%s' WHERE `%s` = '%s' AND `uid` = %d",
|
|
||||||
$n,
|
|
||||||
dbesc($f[1]),
|
|
||||||
$n,
|
|
||||||
dbesc($f[0]),
|
|
||||||
intval($importer["importer_uid"])
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($x === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @TODO
|
/// @TODO
|
||||||
/// merge with current record, current contents have priority
|
/// merge with current record, current contents have priority
|
||||||
|
|
|
@ -1608,34 +1608,9 @@ class Diaspora
|
||||||
logger('Contacts are updated.');
|
logger('Contacts are updated.');
|
||||||
|
|
||||||
// update items
|
// update items
|
||||||
/// @todo This is an extreme performance killer
|
// This is an extreme performance killer
|
||||||
$fields = [
|
Item::update(['owner-link' => $data["url"]], ['owner-link' => $contact["url"], 'uid' => $importer["uid"]]);
|
||||||
'owner-link' => [$contact["url"], $data["url"]],
|
Item::update(['author-link' => $data["url"]], ['author-link' => $contact["url"], 'uid' => $importer["uid"]]);
|
||||||
'author-link' => [$contact["url"], $data["url"]],
|
|
||||||
];
|
|
||||||
foreach ($fields as $n => $f) {
|
|
||||||
$r = q(
|
|
||||||
"SELECT `id` FROM `item` WHERE `%s` = '%s' AND `uid` = %d LIMIT 1",
|
|
||||||
$n,
|
|
||||||
dbesc($f[0]),
|
|
||||||
intval($importer["uid"])
|
|
||||||
);
|
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
$x = q(
|
|
||||||
"UPDATE `item` SET `%s` = '%s' WHERE `%s` = '%s' AND `uid` = %d",
|
|
||||||
$n,
|
|
||||||
dbesc($f[1]),
|
|
||||||
$n,
|
|
||||||
dbesc($f[0]),
|
|
||||||
intval($importer["uid"])
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($x === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger('Items are updated.');
|
logger('Items are updated.');
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue