Safe deletion of users

This commit is contained in:
Phyks 2013-09-15 16:19:37 +02:00
parent 2fc4311c54
commit 1a9acc5ece
2 changed files with 12 additions and 9 deletions

2
TODO
View File

@ -5,6 +5,8 @@
* cf TODO in files * cf TODO in files
* French template * French template
* Favicon * Favicon
* Take account of paybacks in balance table
* Confirm all paybacks
Improvements : Improvements :
============== ==============

View File

@ -278,34 +278,35 @@
if($invoices !== FALSE) { if($invoices !== FALSE) {
foreach($invoices as $invoice) { foreach($invoices as $invoice) {
if($invoice->getBuyer() == $_GET['user_id']) { if($invoice->getBuyer() == $_GET['user_id']) {
$invoice->setBuyer(0); $invoice->delete();
$invoice->save();
} }
if($invoice->getUsersIn()->inUsersIn($_GET['user_id'])) { if($invoice->getUsersIn()->inUsersIn($_GET['user_id'])) {
$users_in = $invoice->getUsersIn()->get(); $users_in = $invoice->getUsersIn()->get();
$users_in[0] = $users_in[$_GET['user_id']];
unset($users_in[$_GET['user_id']]); unset($users_in[$_GET['user_id']]);
if(empty($users_in))
$invoice->delete();
else {
$invoice->setUsersIn($users_in); $invoice->setUsersIn($users_in);
$invoice->save(); $invoice->save();
} }
} }
} }
}
// Update paybacks // Update paybacks
$paybacks = new Payback(); $paybacks = new Payback();
$paybacks = $paybacks->load(array('from_user'=>(int) $_GET['user_id'])); $paybacks = $paybacks->load(array('from_user'=>(int) $_GET['user_id']));
if($paybacks !== FALSE) { if($paybacks !== FALSE) {
foreach($paybacks as $payback) { foreach($paybacks as $payback) {
$payback->setFrom(0); $payback->delete();
$payback->save();
} }
} }
$paybacks = new Payback();
$paybacks = $paybacks->load(array('to_user'=>(int) $_GET['user_id'])); $paybacks = $paybacks->load(array('to_user'=>(int) $_GET['user_id']));
if($paybacks !== FALSE) { if($paybacks !== FALSE) {
foreach($paybacks as $payback) { foreach($paybacks as $payback) {
$payback->setTo(0); $payback->delete();
$payback->save();
} }
} }