From: Florent Bruneau Date: Mon, 11 Oct 2010 14:38:40 +0000 (+0200) Subject: Save profile within a SQL transaction in order to avoid inconsistent X-Git-Tag: xorg/1.0.1~60 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=31cbd100e5e5441b77cc04ed9e353099033cca48;p=platal.git Save profile within a SQL transaction in order to avoid inconsistent states if a SQL error occurs while saving the changes. This change should not have any consequence if the site behave normally but may improve robustness in case of code errors. Signed-off-by: Florent Bruneau --- diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index d8c89de..aad3b96 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -262,7 +262,7 @@ abstract class ProfilePage implements PlWizardPage { } - protected function saveData() + public function saveData() { require_once 'notifs.inc.php'; $changedFields = array(); @@ -309,6 +309,7 @@ abstract class ProfilePage implements PlWizardPage $this->pid(), $user->id(), $field, $values[0], $values[1]); } } + return true; } protected function checkChanges() @@ -384,7 +385,13 @@ abstract class ProfilePage implements PlWizardPage } if ($global_success) { if ($this->checkChanges()) { - $this->saveData(); + /* Save changes atomically to avoid inconsistent state + * in case of error. + */ + if (!XDB::runTransaction(array($this, 'saveData'))) { + $global_success = false; + return PlWizard::CURRENT_PAGE; + } $this->markChange(); } return Post::has('next_page') ? PlWizard::NEXT_PAGE : PlWizard::CURRENT_PAGE;