Mercurial > hg > fapweb
changeset 723:5ef230336e67
Clean up DB transactions in the admin ajax backend code.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 18 Nov 2014 20:29:59 +0200 |
parents | bf33cec02dc6 |
children | fd84eb4d8b74 |
files | admajax.php |
diffstat | 1 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/admajax.php Tue Nov 18 20:00:41 2014 +0200 +++ b/admajax.php Tue Nov 18 20:29:59 2014 +0200 @@ -538,6 +538,7 @@ $index = 1; } + stDBBeginTransaction(); foreach ($final as $entry) { $sql = stPrepareSQL("UPDATE entries SET show_id=%d WHERE id=%d", $index, $entry); @@ -548,6 +549,7 @@ } $index++; } + stDBCommitTransaction(); } } @@ -661,6 +663,7 @@ // // Party information system control // + stDBBeginTransaction(); switch ($type) { case "setRotateDuration": @@ -911,6 +914,7 @@ } break; } + stDBCommitTransaction(); break; case "get": @@ -1406,6 +1410,7 @@ // // Delete entry // + stDBBeginTransaction(); if (stChkRequestItem("id", $id, array(CHK_TYPE, VT_INT, "Invalid data."))) { if ($type == "news") @@ -1449,8 +1454,6 @@ else if ($type == "compo") { - stDBBeginTransaction(); - // Delete votes for compo entry foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$id) as $sentry) { @@ -1468,8 +1471,6 @@ stExecSQLCond( "DELETE FROM compos WHERE id=".$id, "OK, compo ".$id." deleted."); - - stDBCommitTransaction(); } } else @@ -1478,12 +1479,15 @@ $sql = stPrepareSQL("DELETE FROM votekeys"); stExecSQLCond($sql, "OK, all votekeys purged"); } + + stDBCommitTransaction(); break; case "add": // // Add new entry // + stDBBeginTransaction(); if ($type == "news" && stValidateRequestNewsData()) { $sql = stPrepareSQL( @@ -1523,24 +1527,24 @@ stExecSQLCond($sql, "OK, entry added."); } } + stDBCommitTransaction(); break; case "update": // // Update existing entry // + stDBBeginTransaction(); if (stChkRequestItem("id", $id, array(CHK_TYPE, VT_INT, "Invalid data."))) { if ($type == "settings") { - stDBBeginTransaction(); foreach (stExecSQL("SELECT * FROM settings WHERE vgroup=".$id) as $item) if (($val = stGetRequestItem($item["key"], FALSE)) !== FALSE) { $sql = "UPDATE settings SET ".stGetSettingSQL($item, $val)." WHERE key=".$db->quote($item["key"]); stExecSQL($sql); } - stDBCommitTransaction(); stSetStatus(200, "Updated settings."); } else @@ -1633,9 +1637,14 @@ } } } + stDBCommitTransaction(); break; case "votekey": + // + // Votekey activation/deactivation handling + // + stDBBeginTransaction(); if (stChkRequestItem("id", $id, array(CHK_TYPE, VT_INT, "Invalid data."))) { switch ($type) @@ -1672,10 +1681,11 @@ break; } } + stDBCommitTransaction(); break; default: - stSetStatus(404, "Not Found"); + stSetStatus(903, "Not Found"); break; }