From 31cbd100e5e5441b77cc04ed9e353099033cca48 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Mon, 11 Oct 2010 16:38:40 +0200 Subject: [PATCH] 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 --- modules/profile/page.inc.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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; -- 2.1.4