$cur->smsemail = $carrier->toEmailAddress($cur->sms);
}
- $result = $cur->updateWithKeys($orig_user);
-
- if (!$result) {
- common_log_db_error($cur, 'UPDATE', __FILE__);
- // TRANS: Server error displayed when confirming an e-mail address or IM address fails.
- $this->serverError(_('Could not update user.'));
- }
+ // Throws exception on failure.
+ $cur->updateWithKeys($orig_user);
if ($type == 'email') {
$cur->emailChanged();
return;
}
- $user->query('BEGIN');
-
$original = clone($user);
$user->email = null;
- $result = $user->updateWithKeys($original);
-
- if (!$result) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- // TRANS: Server error thrown on database error removing a registered e-mail address.
- $this->serverError(_('Could not update user.'));
- }
- $user->query('COMMIT');
+ // Throws exception on failure. Also performs it within a transaction.
+ $user->updateWithKeys($original);
// TRANS: Message given after successfully removing a registered e-mail address.
$this->showForm(_('The email address was removed.'), true);
$user->incomingemail = null;
$user->emailpost = 0;
- 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.'));
- }
+ // Throws exception on failure. Also performs it within a transaction.
+ $user->updateWithKeys($orig);
// TRANS: Message given after successfully removing an incoming e-mail address.
$this->showForm(_('Incoming email address removed.'), true);
$user->incomingemail = mail_new_incoming_address();
$user->emailpost = 1;
- 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.'));
- }
+ // Throws exception on failure. Also performs it within a transaction.
+ $user->updateWithKeys($orig);
// TRANS: Message given after successfully adding an incoming e-mail address.
$this->showForm(_('New incoming email address added.'), true);
if (!$user->email) {
$orig = clone($user);
$user->email = $email;
- $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.
- $this->serverError(_('Could not update user with confirmed email address.'));
- }
+ // Throws exception on failure.
+ $user->updateWithKeys($orig);
}
// Success!
return;
}
- $user->query('BEGIN');
-
$original = clone($user);
$user->sms = null;
$user->carrier = null;
$user->smsemail = null;
- $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.
- $this->serverError(_('Could not update user.'));
- }
- $user->query('COMMIT');
+ // Throws exception on failure. Also performs it within a transaction.
+ $user->updateWithKeys($original);
// TRANS: Message given after successfully removing a registered SMS phone number.
$this->showForm(_('The SMS phone number was removed.'), true);
$user->incomingemail = null;
- 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.'));
- }
+ // Throws exception on failure. Also performs it within a transaction.
+ $user->updateWithKeys($orig);
// TRANS: Confirmation text after updating SMS settings.
$this->showForm(_('Incoming email address removed.'), true);
$user->incomingemail = mail_new_incoming_address();
- 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.'));
- }
+ // Throws exception on failure. Also performs it within a transaction.
+ $user->updateWithKeys($orig);
// TRANS: Confirmation text after updating SMS settings.
$this->showForm(_('New incoming email address added.'), true);
}
}
if (count($parts) == 0) {
- // No changes, unless made in the ->update call
+ // No changes to keys, it's safe to run ->update(...)
+ if ($this->update($orig) === false) {
+ common_log_db_error($this, 'UPDATE', __FILE__);
+ // rollback as something bad occurred
+ $this->query('ROLLBACK');
+ throw new ServerException("Could not UPDATE non-keys for {$this->__table}");
+ }
return true;
}
$toupdate = implode(', ', $parts);
}
// Update non-keys too, if the previous endeavour worked.
+ // The ->update call uses "$this" values for keys, that's why we can't do this until
+ // the keys are updated (because they might differ from $orig and update the wrong entries).
if ($this->update($orig) === false) {
common_log_db_error($this, 'UPDATE', __FILE__);
// rollback as something bad occurred
common_debug("Updating User ({$this->id}) nickname from {$dataObject->nickname} to {$this->nickname}");
$origuser = clone($local);
$local->nickname = $this->nickname;
- $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.
- throw new ServerException(_('Could not update user nickname.'));
- }
+ // updateWithKeys throws exception on failure.
+ $local->updateWithKeys($origuser);
// Clear the site owner, in case nickname changed
if ($local->hasRole(Profile_role::OWNER)) {
$thumbnail->filename = $filename;
$thumbnail->width = $info[0]; // array indexes documented on php.net:
$thumbnail->height = $info[1]; // https://php.net/manual/en/function.getimagesize.php
- if (!$thumbnail->update($orig)) {
- unlink($fullpath); // delete the file if database failed to write
- throw new ServerException(_('Failed to update remotely downloaded file info in database.'));
- }
+ // Throws exception on failure.
+ $thumbnail->updateWithKeys($orig);
}
public function onPluginVersion(array &$versions)
$this->user->email = $this->confirm->address;
+ // Throws exception on failure.
$this->user->updateWithKeys($orig);
$this->user->emailChanged();
} else {
$original = clone($user);
$user->jabber = null;
- $result = $user->updateWithKeys($original);
+ try {
+ $user->updateWithKeys($original);
+ } catch (Exception $e) {
+ echo "WARNING: user update failed (setting jabber to null): ".$e->getMessage()."\n";
+ }
}
echo "\n";
} else if (!$user) {
$user->email = $email;
- if (!$user->updateWithKeys($orig)) {
- print "Failed!\n";
- throw new Exception("Can't update email address.");
- }
+ // Throws exception on failure.
+ $user->updateWithKeys($orig);
}
} catch (Exception $e) {