X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fsmssettings.php;h=ec8841281d2bf07c544910080002aacd7181e556;hb=b53e1439969bfa2c0b551d8cc2fc8fe15652c62a;hp=6af1872a0ec1d88bcf117ff20ba4ef2cadc57a6b;hpb=7ace3156ca70b908d6d9c359be0e1f9a0414197c;p=quix0rs-gnu-social.git diff --git a/actions/smssettings.php b/actions/smssettings.php index 6af1872a0e..ec8841281d 100644 --- a/actions/smssettings.php +++ b/actions/smssettings.php @@ -31,8 +31,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/lib/connectsettingsaction.php'; - /** * Settings for SMS * @@ -45,14 +43,13 @@ require_once INSTALLDIR.'/lib/connectsettingsaction.php'; * @see SettingsAction */ -class SmssettingsAction extends ConnectSettingsAction +class SmssettingsAction extends SettingsAction { /** * Title of the page * * @return string Title of the page */ - function title() { // TRANS: Title for SMS settings. @@ -64,7 +61,6 @@ class SmssettingsAction extends ConnectSettingsAction * * @return instructions for use */ - function getInstructions() { // XXX: For consistency of parameters in messages, this should be a @@ -88,7 +84,6 @@ class SmssettingsAction extends ConnectSettingsAction * * @return void */ - function showContent() { if (!common_config('sms', 'enabled')) { @@ -125,7 +120,7 @@ class SmssettingsAction extends ConnectSettingsAction } else { $confirm = $this->getConfirmation(); if ($confirm) { - $carrier = Sms_carrier::staticGet($confirm->address_extra); + $carrier = Sms_carrier::getKV($confirm->address_extra); $this->element('p', 'form_unconfirmed', $confirm->address . ' (' . $carrier->name . ')'); $this->element('p', 'form_guide', @@ -154,7 +149,7 @@ class SmssettingsAction extends ConnectSettingsAction ($this->arg('sms')) ? $this->arg('sms') : null, // TRANS: SMS phone number input field instructions in SMS settings form. _('Phone number, no punctuation or spaces, '. - 'with area code')); + 'with area code.')); $this->elementEnd('li'); $this->elementEnd('ul'); $this->carrierSelect(); @@ -219,7 +214,6 @@ class SmssettingsAction extends ConnectSettingsAction * * @todo very similar to EmailsettingsAction::getConfirmation(); refactor? */ - function getConfirmation() { $user = common_current_user(); @@ -246,13 +240,13 @@ class SmssettingsAction extends ConnectSettingsAction * * @return void */ - function handlePost() { // CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { + // TRANS: Client error displayed when the session token does not match or is not given. $this->showForm(_('There was a problem with your session token. '. 'Try again, please.')); return; @@ -285,7 +279,6 @@ class SmssettingsAction extends ConnectSettingsAction * * @return void */ - function savePreferences() { $smsnotify = $this->boolean('smsnotify'); @@ -305,8 +298,7 @@ class SmssettingsAction extends ConnectSettingsAction if ($result === false) { common_log_db_error($user, 'UPDATE', __FILE__); // TRANS: Server error thrown on database error updating SMS preferences. - $this->serverError(_('Couldn\'t update user.')); - return; + $this->serverError(_('Could not update user.')); } $user->query('COMMIT'); @@ -323,7 +315,6 @@ class SmssettingsAction extends ConnectSettingsAction * * @return void */ - function addAddress() { $user = common_current_user(); @@ -370,11 +361,10 @@ class SmssettingsAction extends ConnectSettingsAction if ($result === false) { common_log_db_error($confirm, 'INSERT', __FILE__); // TRANS: Server error thrown on database error adding SMS confirmation code. - $this->serverError(_('Couldn\'t insert confirmation code.')); - return; + $this->serverError(_('Could not insert confirmation code.')); } - $carrier = Sms_carrier::staticGet($carrier_id); + $carrier = Sms_carrier::getKV($carrier_id); mail_confirm_sms($confirm->code, $user->nickname, @@ -395,7 +385,6 @@ class SmssettingsAction extends ConnectSettingsAction * * @return void */ - function cancelConfirmation() { $sms = $this->trimmed('sms'); @@ -419,8 +408,7 @@ class SmssettingsAction extends ConnectSettingsAction if (!$result) { common_log_db_error($confirm, 'DELETE', __FILE__); // TRANS: Server error thrown on database error canceling SMS phone number confirmation. - $this->serverError(_('Couldn\'t delete email confirmation.')); - return; + $this->serverError(_('Could not delete SMS confirmation.')); } // TRANS: Message given after successfully canceling SMS phone number confirmation. @@ -432,7 +420,6 @@ class SmssettingsAction extends ConnectSettingsAction * * @return void */ - function removeAddress() { $user = common_current_user(); @@ -449,22 +436,14 @@ class SmssettingsAction extends ConnectSettingsAction return; } - $user->query('BEGIN'); - $original = clone($user); $user->sms = null; $user->carrier = null; $user->smsemail = null; - $result = $user->updateKeys($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(_('Couldn\'t update user.')); - return; - } - $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); @@ -479,12 +458,11 @@ class SmssettingsAction extends ConnectSettingsAction * * @return boolean does the number exist */ - function smsExists($sms) { $user = common_current_user(); - $other = User::staticGet('sms', $sms); + $other = User::getKV('sms', $sms); if (!$other) { return false; @@ -498,7 +476,6 @@ class SmssettingsAction extends ConnectSettingsAction * * @return void */ - function carrierSelect() { $carrier = new Sms_carrier(); @@ -538,14 +515,13 @@ class SmssettingsAction extends ConnectSettingsAction * * @return void */ - function confirmCode() { $code = $this->trimmed('code'); if (!$code) { // TRANS: Message given saving SMS phone number confirmation code without having provided one. - $this->showForm(_('No code entered')); + $this->showForm(_('No code entered.')); return; } @@ -559,12 +535,12 @@ class SmssettingsAction extends ConnectSettingsAction * * @return void */ - function removeIncoming() { $user = common_current_user(); if (!$user->incomingemail) { + // TRANS: Form validation error displayed when trying to remove an incoming e-mail address while no address has been set. $this->showForm(_('No incoming email address.')); return; } @@ -573,11 +549,10 @@ class SmssettingsAction extends ConnectSettingsAction $user->incomingemail = null; - if (!$user->updateKeys($orig)) { - common_log_db_error($user, 'UPDATE', __FILE__); - $this->serverError(_("Couldn't 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); } @@ -588,7 +563,6 @@ class SmssettingsAction extends ConnectSettingsAction * * @see Emailsettings::newIncoming */ - function newIncoming() { $user = common_current_user(); @@ -597,11 +571,10 @@ class SmssettingsAction extends ConnectSettingsAction $user->incomingemail = mail_new_incoming_address(); - if (!$user->updateKeys($orig)) { - common_log_db_error($user, 'UPDATE', __FILE__); - $this->serverError(_("Couldn't 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); } }