1
1
Fork 0

Just some more dba::delete

This commit is contained in:
Michael 2017-05-13 04:04:17 +00:00
parent b907ad9dd8
commit 74a0a92742
7 changed files with 41 additions and 64 deletions

View file

@ -23,29 +23,7 @@ function user_remove($uid) {
$r[0]['nickname'] $r[0]['nickname']
); );
/// @todo Should be done in a background job since this likely will run into a time out // The user and related data will be deleted in "cron_expire_and_remove_users" (cronjobs.php)
// don't delete yet, will be done later when contacts have deleted my stuff
// q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `gcign` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `intro` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `event` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `item` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `item_id` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `mail` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `mailacct` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `manage` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `notify` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `photo` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `attach` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `profile` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `profile_check` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `pconfig` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `search` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `spam` WHERE `uid` = %d", intval($uid));
// don't delete yet, will be done later when contacts have deleted my stuff
// q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid)); q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid));
proc_run(PRIORITY_HIGH, "include/notifier.php", "removeme", $uid); proc_run(PRIORITY_HIGH, "include/notifier.php", "removeme", $uid);

View file

@ -110,12 +110,11 @@ function cron_expire_and_remove_users() {
AND `account_expires_on` > '%s' AND `account_expires_on` > '%s'
AND `account_expires_on` < UTC_TIMESTAMP()", dbesc(NULL_DATE)); AND `account_expires_on` < UTC_TIMESTAMP()", dbesc(NULL_DATE));
// delete user and contact records for recently removed accounts // delete user records for recently removed accounts
$r = q("SELECT * FROM `user` WHERE `account_removed` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY"); $r = q("SELECT * FROM `user` WHERE `account_removed` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
foreach ($r as $user) { foreach ($r as $user) {
q("DELETE FROM `contact` WHERE `uid` = %d", intval($user['uid'])); dba::delete('user', array('uid' => $user['uid']));
q("DELETE FROM `user` WHERE `uid` = %d", intval($user['uid']));
} }
} }
} }

View file

@ -53,11 +53,14 @@ function remove_orphans($stage = 0) {
} else { } else {
logger("No global item orphans found"); logger("No global item orphans found");
// We will eventually set this value when we found a good way to delete these items in another way.
// Config::set('system', 'finished-dbclean-1', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." old global item entries from item table without user copy"); logger("Done deleting ".$count." old global item entries from item table without user copy");
// We will eventually set this value when we found a good way to delete these items in another way.
// if ($count < $limit) {
// Config::set('system', 'finished-dbclean-1', true);
// }
} elseif ($stage == 2) { } elseif ($stage == 2) {
logger("Deleting items without parents"); logger("Deleting items without parents");
$r = dba::p("SELECT `id` FROM `item` WHERE NOT EXISTS (SELECT `id` FROM `item` AS `i` WHERE `item`.`parent` = `i`.`id`) LIMIT ".intval($limit)); $r = dba::p("SELECT `id` FROM `item` WHERE NOT EXISTS (SELECT `id` FROM `item` AS `i` WHERE `item`.`parent` = `i`.`id`) LIMIT ".intval($limit));
@ -69,10 +72,13 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No item orphans without parents found"); logger("No item orphans without parents found");
Config::set('system', 'finished-dbclean-2', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." items without parents"); logger("Done deleting ".$count." items without parents");
if ($count < $limit) {
Config::set('system', 'finished-dbclean-2', true);
}
} elseif ($stage == 3) { } elseif ($stage == 3) {
logger("Deleting orphaned data from thread table"); logger("Deleting orphaned data from thread table");
$r = dba::p("SELECT `iid` FROM `thread` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `thread`.`iid`) LIMIT ".intval($limit)); $r = dba::p("SELECT `iid` FROM `thread` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `thread`.`iid`) LIMIT ".intval($limit));
@ -84,11 +90,13 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No thread orphans found"); logger("No thread orphans found");
Config::set('system', 'finished-dbclean-3', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." orphaned data from thread table"); logger("Done deleting ".$count." orphaned data from thread table");
if ($count < $limit) {
Config::set('system', 'finished-dbclean-3', true);
}
} elseif ($stage == 4) { } elseif ($stage == 4) {
logger("Deleting orphaned data from notify table"); logger("Deleting orphaned data from notify table");
$r = dba::p("SELECT `iid` FROM `notify` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `notify`.`iid`) LIMIT ".intval($limit)); $r = dba::p("SELECT `iid` FROM `notify` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `notify`.`iid`) LIMIT ".intval($limit));
@ -100,10 +108,13 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No notify orphans found"); logger("No notify orphans found");
Config::set('system', 'finished-dbclean-4', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." orphaned data from notify table"); logger("Done deleting ".$count." orphaned data from notify table");
if ($count < $limit) {
Config::set('system', 'finished-dbclean-4', true);
}
} elseif ($stage == 5) { } elseif ($stage == 5) {
logger("Deleting orphaned data from notify-threads table"); logger("Deleting orphaned data from notify-threads table");
$r = dba::p("SELECT `id` FROM `notify-threads` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `notify-threads`.`master-parent-item`) LIMIT ".intval($limit)); $r = dba::p("SELECT `id` FROM `notify-threads` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `notify-threads`.`master-parent-item`) LIMIT ".intval($limit));
@ -115,10 +126,13 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No notify-threads orphans found"); logger("No notify-threads orphans found");
Config::set('system', 'finished-dbclean-5', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." orphaned data from notify-threads table"); logger("Done deleting ".$count." orphaned data from notify-threads table");
if ($count < $limit) {
Config::set('system', 'finished-dbclean-5', true);
}
} elseif ($stage == 6) { } elseif ($stage == 6) {
logger("Deleting orphaned data from sign table"); logger("Deleting orphaned data from sign table");
$r = dba::p("SELECT `iid` FROM `sign` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `sign`.`iid`) LIMIT ".intval($limit)); $r = dba::p("SELECT `iid` FROM `sign` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `sign`.`iid`) LIMIT ".intval($limit));
@ -130,10 +144,13 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No sign orphans found"); logger("No sign orphans found");
Config::set('system', 'finished-dbclean-6', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." orphaned data from sign table"); logger("Done deleting ".$count." orphaned data from sign table");
if ($count < $limit) {
Config::set('system', 'finished-dbclean-6', true);
}
} elseif ($stage == 7) { } elseif ($stage == 7) {
logger("Deleting orphaned data from term table"); logger("Deleting orphaned data from term table");
$r = dba::p("SELECT `oid` FROM `term` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `term`.`oid`) LIMIT ".intval($limit)); $r = dba::p("SELECT `oid` FROM `term` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `term`.`oid`) LIMIT ".intval($limit));
@ -145,10 +162,13 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No term orphans found"); logger("No term orphans found");
Config::set('system', 'finished-dbclean-7', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." orphaned data from term table"); logger("Done deleting ".$count." orphaned data from term table");
if ($count < $limit) {
Config::set('system', 'finished-dbclean-7', true);
}
} }
// Call it again if not all entries were purged // Call it again if not all entries were purged

View file

@ -245,9 +245,7 @@ function delete_thread($itemid, $itemuri = "") {
intval($item["uid"]) intval($item["uid"])
); );
if (!dbm::is_result($r)) { if (!dbm::is_result($r)) {
$r = q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = 0", dba::delete('item', array('uri' => $itemuri, 'uid' => 0));
dbesc($itemuri)
);
logger("delete_thread: Deleted shadow for item ".$itemuri." - ".print_r($result, true), LOGGER_DEBUG); logger("delete_thread: Deleted shadow for item ".$itemuri." - ".print_r($result, true), LOGGER_DEBUG);
} }
} }

View file

@ -62,13 +62,7 @@ function db_import_assoc($table, $arr) {
} }
function import_cleanup($newuid) { function import_cleanup($newuid) {
q("DELETE FROM `user` WHERE uid = %d", $newuid); dba::delete('user', array('uid' => $newuid));
q("DELETE FROM `contact` WHERE uid = %d", $newuid);
q("DELETE FROM `profile` WHERE uid = %d", $newuid);
q("DELETE FROM `photo` WHERE uid = %d", $newuid);
q("DELETE FROM `group` WHERE uid = %d", $newuid);
q("DELETE FROM `group_member` WHERE uid = %d", $newuid);
q("DELETE FROM `pconfig` WHERE uid = %d", $newuid);
} }
/** /**

View file

@ -226,9 +226,7 @@ function create_user($arr) {
); );
if ((dbm::is_result($r)) && (count($r) > 1) && $newuid) { if ((dbm::is_result($r)) && (count($r) > 1) && $newuid) {
$result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL;
q("DELETE FROM `user` WHERE `uid` = %d", dba::delete('user', array('uid' => $newuid));
intval($newuid)
);
return $result; return $result;
} }
@ -248,8 +246,7 @@ function create_user($arr) {
if ($r === false) { if ($r === false) {
$result['message'] .= t('An error occurred creating your default profile. Please try again.') . EOL; $result['message'] .= t('An error occurred creating your default profile. Please try again.') . EOL;
// Start fresh next time. // Start fresh next time.
$r = q("DELETE FROM `user` WHERE `uid` = %d", dba::delete('user', array('uid' => $newuid));
intval($newuid));
return $result; return $result;
} }

View file

@ -74,27 +74,18 @@ function user_deny($hash) {
dbesc($hash) dbesc($hash)
); );
if(! dbm::is_result($register)) if (!dbm::is_result($register)) {
return false; return false;
}
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($register[0]['uid']) intval($register[0]['uid'])
); );
$r = q("DELETE FROM `user` WHERE `uid` = %d", dba::delete('user', array('uid' => $register[0]['uid']));
intval($register[0]['uid']) dba::delete('register', array('hash' => $register[0]['hash']));
);
$r = q("DELETE FROM `contact` WHERE `uid` = %d",
intval($register[0]['uid'])
);
$r = q("DELETE FROM `profile` WHERE `uid` = %d",
intval($register[0]['uid'])
);
$r = q("DELETE FROM `register` WHERE `hash` = '%s'", notice(sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
dbesc($register[0]['hash'])
);
notice( sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
return true; return true;
} }