This is better
This commit is contained in:
parent
0d7996d852
commit
e6cbe3be11
|
@ -812,20 +812,14 @@ class dba {
|
||||||
// Is there a relation entry for the table?
|
// Is there a relation entry for the table?
|
||||||
if (isset(self::$relation[$table])) {
|
if (isset(self::$relation[$table])) {
|
||||||
foreach (self::$relation[$table] AS $field => $rel_def) {
|
foreach (self::$relation[$table] AS $field => $rel_def) {
|
||||||
// Currently we only support relations with a single variable
|
|
||||||
if (count($rel_def) > 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$rel_field = array_values($rel_def)[0];
|
|
||||||
$rel_table = array_keys($rel_def)[0];
|
|
||||||
|
|
||||||
// When the search field is the relation field, we don't need to fetch the rows
|
// 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
|
// This is useful when the leading record is already deleted in the frontend but the rest is done in the backend
|
||||||
if ((count($param) == 1) AND ($field == array_keys($param)[0])) {
|
if ((count($param) == 1) AND ($field == array_keys($param)[0])) {
|
||||||
$retval = self::delete($rel_table, array($rel_field => array_values($param)[0]), true, $callstack);
|
foreach ($rel_def AS $rel_table => $rel_field) {
|
||||||
if (!$retval) {
|
$retval = self::delete($rel_table, array($rel_field => array_values($param)[0]), true, $callstack);
|
||||||
return false;
|
if (!$retval) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fetch all rows that are to be deleted
|
// Fetch all rows that are to be deleted
|
||||||
|
@ -834,10 +828,12 @@ class dba {
|
||||||
$retval = false;
|
$retval = false;
|
||||||
$data = self::p($sql, $param);
|
$data = self::p($sql, $param);
|
||||||
while ($row = self::fetch($data)) {
|
while ($row = self::fetch($data)) {
|
||||||
// We have to do a separate delete process per row
|
foreach ($rel_def AS $rel_table => $rel_field) {
|
||||||
$retval = self::delete($rel_table, array($rel_field => $row[$field]), true, $callstack);
|
// We have to do a separate delete process per row
|
||||||
if (!$retval) {
|
$retval = self::delete($rel_table, array($rel_field => $row[$field]), true, $callstack);
|
||||||
return false;
|
if (!$retval) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$retval) {
|
if (!$retval) {
|
||||||
|
|
|
@ -19,14 +19,7 @@ function remove_contact_run($argv, $argc) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
q("DELETE FROM `item` WHERE `contact-id` = %d", intval($id));
|
// Now we delete all the depending table entries
|
||||||
|
dba::delete('contact', array('id' => $id));
|
||||||
q("DELETE FROM `photo` WHERE `contact-id` = %d", intval($id));
|
|
||||||
|
|
||||||
q("DELETE FROM `mail` WHERE `contact-id` = %d", intval($id));
|
|
||||||
|
|
||||||
q("DELETE FROM `event` WHERE `cid` = %d", intval($id));
|
|
||||||
|
|
||||||
q("DELETE FROM `queue` WHERE `cid` = %d", intval($id));
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in a new issue