Rewritten to use transactions

This commit is contained in:
Jean-Philippe Guérard 2011-12-30 04:16:41 +01:00
parent 5f1825179a
commit aa8523e318
3 changed files with 75 additions and 20 deletions

View File

@ -86,19 +86,36 @@ while($dsondage = $sondage->FetchNextObject(false)) {
if (issetAndNoEmpty('confirmesuppression'.$i) === true) {
// On inclut la routine de suppression
$date=date('H:i:s d/m/Y');
$req = 'DELETE FROM sujet_studs WHERE id_sondage = ' . $connect->Param('id_sondage') . '; ' .
'DELETE FROM user_studs WHERE id_sondage = ' . $connect->Param('id_sondage') . '; ' .
'DELETE FROM comments WHERE id_sondage = ' . $connect->Param('id_sondage') . '; ' .
'DELETE FROM sondage WHERE id_sondage = ' . $connect->Param('id_sondage') ;
$connect->StartTrans();
$req = 'DELETE FROM sondage WHERE id_sondage = ' . $connect->Param('id_sondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($dsondage->id_sondage));
// ecriture des traces dans le fichier de logs
error_log($date . " SUPPRESSION: $dsondage->id_sondage\t$dsondage->format\t$dsondage->nom_admin\t$dsondage->mail_admin\n", 3, 'logs_studs.txt');
$req = 'DELETE FROM sujet_studs WHERE id_sondage = ' . $connect->Param('id_sondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($dsondage->id_sondage));
$req = 'DELETE FROM user_studs WHERE id_sondage = ' . $connect->Param('id_sondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($dsondage->id_sondage));
$req = 'DELETE FROM comments WHERE id_sondage = ' . $connect->Param('id_sondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($dsondage->id_sondage));
if (! $connect->HasFailedTrans() ) {
// ecriture des traces dans le fichier de logs
error_log($date . " SUPPRESSION: $dsondage->id_sondage\t$dsondage->format\t$dsondage->nom_admin\t$dsondage->mail_admin\n", 3, 'logs_studs.txt');
}
$connect->CompleteTrans();
}
$i++;
}

View File

@ -319,8 +319,29 @@ if (isset($_POST["confirmesuppression"]) || isset($_POST["confirmesuppression_x"
'DELETE FROM comments WHERE id_sondage = ' . $connect->Param('numsondage') . '; ' .
'DELETE FROM sondage WHERE id_sondage = ' . $connect->Param('numsondage') ;
$sql = $connect->Prepare($sql);
if ($connect->Execute($sql, array($numsondage))) {
$connect->StartTrans();
$req = 'DELETE FROM sondage WHERE id_sondage = ' . $connect->Param('numsondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($numsondage));
$req = 'DELETE FROM sujet_studs WHERE id_sondage = ' . $connect->Param('numsondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($numsondage));
$req = 'DELETE FROM user_studs WHERE id_sondage = ' . $connect->Param('numsondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($numsondage));
$req = 'DELETE FROM comments WHERE id_sondage = ' . $connect->Param('numsondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($numsondage));
$suppression_OK = ! $connect->HasFailedTrans() ;
$connect->CompleteTrans();
if ( $suppression_OK ) {
// on ecrit dans le fichier de logs la suppression du sondage
error_log($date . " SUPPRESSION: $dsondage->id_sondage\t$dsondage->format\t$dsondage->nom_admin\t$dsondage->mail_admin\n", 3, 'admin/logs_studs.txt');

View File

@ -49,15 +49,32 @@ $sondage=$connect->Execute("select * from sondage");
while ($dsondage=$sondage->FetchNextObject(false)) {
if ($date_courante > strtotime($dsondage->date_fin)) {
//destruction des données dans la base
$req = 'DELETE FROM sujet_studs WHERE id_sondage = ' . $connect->Param('id_sondage') . '; ' .
'DELETE FROM user_studs WHERE id_sondage = ' . $connect->Param('id_sondage') . '; ' .
'DELETE FROM comments WHERE id_sondage = ' . $connect->Param('id_sondage') . '; ' .
'DELETE FROM sondage WHERE id_sondage = ' . $connect->Param('id_sondage') ;
$connect->StartTrans();
$req = 'DELETE FROM sondage WHERE id_sondage = ' . $connect->Param('id_sondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($dsondage->id_sondage));
// ecriture des traces dans le fichier de logs
error_log($date . " SUPPRESSION: $dsondage->id_sondage\t$dsondage->format\t$dsondage->nom_admin\t$dsondage->mail_admin\n", 3, '../admin/logs_studs.txt');
$req = 'DELETE FROM sujet_studs WHERE id_sondage = ' . $connect->Param('id_sondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($dsondage->id_sondage));
$req = 'DELETE FROM user_studs WHERE id_sondage = ' . $connect->Param('id_sondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($dsondage->id_sondage));
$req = 'DELETE FROM comments WHERE id_sondage = ' . $connect->Param('id_sondage') ;
$sql = $connect->Prepare($req);
$connect->Execute($sql, array($dsondage->id_sondage));
if ( ! $connect->HasFailedTrans() ) {
// ecriture des traces dans le fichier de logs
error_log($date . " SUPPRESSION: $dsondage->id_sondage\t$dsondage->format\t$dsondage->nom_admin\t$dsondage->mail_admin\n", 3, '../admin/logs_studs.txt');
}
$connect->CompleteTrans();
}
}