From 4917a422a1fe1d22827e07cb61c54b7978fa7958 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 25 Jan 2015 12:07:26 +0100 Subject: [PATCH] updateKeys -> updateWithKeys (w/ functionality) --- actions/confirmaddress.php | 2 +- actions/emailsettings.php | 6 +++--- actions/recoverpassword.php | 2 +- actions/smssettings.php | 6 +++--- classes/Managed_DataObject.php | 7 +++++-- classes/Profile.php | 2 +- .../RequireValidatedEmail/actions/confirmfirstemail.php | 2 +- scripts/clear_jabber.php | 2 +- scripts/registeruser.php | 2 +- 9 files changed, 17 insertions(+), 14 deletions(-) diff --git a/actions/confirmaddress.php b/actions/confirmaddress.php index 05ddce75a9..1e2d3a92d6 100644 --- a/actions/confirmaddress.php +++ b/actions/confirmaddress.php @@ -108,7 +108,7 @@ class ConfirmaddressAction extends Action $cur->smsemail = $carrier->toEmailAddress($cur->sms); } - $result = $cur->updateKeys($orig_user); + $result = $cur->updateWithKeys($orig_user); if (!$result) { common_log_db_error($cur, 'UPDATE', __FILE__); diff --git a/actions/emailsettings.php b/actions/emailsettings.php index fea649d6de..483131c779 100644 --- a/actions/emailsettings.php +++ b/actions/emailsettings.php @@ -484,7 +484,7 @@ class EmailsettingsAction extends SettingsAction $user->email = null; - $result = $user->updateKeys($original); + $result = $user->updateWithKeys($original); if (!$result) { common_log_db_error($user, 'UPDATE', __FILE__); @@ -517,7 +517,7 @@ class EmailsettingsAction extends SettingsAction $user->incomingemail = null; $user->emailpost = 0; - if (!$user->updateKeys($orig)) { + if (!$user->updateWithKeys($orig)) { common_log_db_error($user, 'UPDATE', __FILE__); // TRANS: Server error thrown on database error removing incoming e-mail address. $this->serverError(_('Could not update user record.')); @@ -541,7 +541,7 @@ class EmailsettingsAction extends SettingsAction $user->incomingemail = mail_new_incoming_address(); $user->emailpost = 1; - if (!$user->updateKeys($orig)) { + if (!$user->updateWithKeys($orig)) { common_log_db_error($user, 'UPDATE', __FILE__); // TRANS: Server error thrown on database error adding incoming e-mail address. $this->serverError(_('Could not update user record.')); diff --git a/actions/recoverpassword.php b/actions/recoverpassword.php index 2bdb6774ea..46df772b73 100644 --- a/actions/recoverpassword.php +++ b/actions/recoverpassword.php @@ -105,7 +105,7 @@ class RecoverpasswordAction extends Action if (!$user->email) { $orig = clone($user); $user->email = $email; - $result = $user->updateKeys($orig); + $result = $user->updateWithKeys($orig); if (!$result) { common_log_db_error($user, 'UPDATE', __FILE__); // TRANS: Server error displayed when updating a user's e-mail address in the database fails while recovering a password. diff --git a/actions/smssettings.php b/actions/smssettings.php index d8e219db41..ec2fcfd89e 100644 --- a/actions/smssettings.php +++ b/actions/smssettings.php @@ -444,7 +444,7 @@ class SmssettingsAction extends SettingsAction $user->carrier = null; $user->smsemail = null; - $result = $user->updateKeys($original); + $result = $user->updateWithKeys($original); if (!$result) { common_log_db_error($user, 'UPDATE', __FILE__); // TRANS: Server error thrown on database error removing a registered SMS phone number. @@ -556,7 +556,7 @@ class SmssettingsAction extends SettingsAction $user->incomingemail = null; - if (!$user->updateKeys($orig)) { + if (!$user->updateWithKeys($orig)) { common_log_db_error($user, 'UPDATE', __FILE__); // TRANS: Server error displayed when the user could not be updated in SMS settings. $this->serverError(_('Could not update user record.')); @@ -581,7 +581,7 @@ class SmssettingsAction extends SettingsAction $user->incomingemail = mail_new_incoming_address(); - if (!$user->updateKeys($orig)) { + if (!$user->updateWithKeys($orig)) { common_log_db_error($user, 'UPDATE', __FILE__); // TRANS: Server error displayed when the user could not be updated in SMS settings. $this->serverError(_('Could not update user record.')); diff --git a/classes/Managed_DataObject.php b/classes/Managed_DataObject.php index d20d3cc27e..8428d11dcb 100644 --- a/classes/Managed_DataObject.php +++ b/classes/Managed_DataObject.php @@ -322,13 +322,16 @@ abstract class Managed_DataObject extends Memcached_DataObject } // 'update' won't write key columns, so we have to do it ourselves. - public function updateKeys(&$orig) + // This also automatically calls "update" _before_ it sets the keys. + public function updateWithKeys(&$orig) { if (!$orig instanceof $this) { throw new ServerException('Tried updating a DataObject with a different class than itself.'); } - $this->_connect(); + // Update non-keys first, if necessary. + $this->update($orig); + $parts = array(); foreach ($this->keys() as $k) { if (strcmp($this->$k, $orig->$k) != 0) { diff --git a/classes/Profile.php b/classes/Profile.php index 8352861fe6..ea99244e31 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -838,7 +838,7 @@ class Profile extends Managed_DataObject common_debug("Updating User ({$this->id}) nickname from {$dataObject->nickname} to {$this->nickname}"); $origuser = clone($local); $local->nickname = $this->nickname; - $result = $local->updateKeys($origuser); + $result = $local->updateWithKeys($origuser); if ($result === false) { common_log_db_error($local, 'UPDATE', __FILE__); // TRANS: Server error thrown when user profile settings could not be updated. diff --git a/plugins/RequireValidatedEmail/actions/confirmfirstemail.php b/plugins/RequireValidatedEmail/actions/confirmfirstemail.php index 0019d1c6be..465814342d 100644 --- a/plugins/RequireValidatedEmail/actions/confirmfirstemail.php +++ b/plugins/RequireValidatedEmail/actions/confirmfirstemail.php @@ -150,7 +150,7 @@ class ConfirmfirstemailAction extends Action $this->user->email = $this->confirm->address; - $this->user->updateKeys($orig); + $this->user->updateWithKeys($orig); $this->user->emailChanged(); diff --git a/scripts/clear_jabber.php b/scripts/clear_jabber.php index a71ccb2d67..4a7de8a3d9 100755 --- a/scripts/clear_jabber.php +++ b/scripts/clear_jabber.php @@ -75,7 +75,7 @@ function clear_jabber($id) } else { $original = clone($user); $user->jabber = null; - $result = $user->updateKeys($original); + $result = $user->updateWithKeys($original); } echo "\n"; } else if (!$user) { diff --git a/scripts/registeruser.php b/scripts/registeruser.php index d2a47b6be9..cc0bd5598d 100644 --- a/scripts/registeruser.php +++ b/scripts/registeruser.php @@ -69,7 +69,7 @@ try { $user->email = $email; - if (!$user->updateKeys($orig)) { + if (!$user->updateWithKeys($orig)) { print "Failed!\n"; throw new Exception("Can't update email address."); }