Reedy has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/170338

Change subject: Stylistic tweaks
......................................................................

Stylistic tweaks

Combine duplicate schema update hooks

Change-Id: I0b77a6084b38e3bc61ba660e099ae3623dea9614
---
M BounceHandler.php
M BounceHandlerHooks.php
M includes/BounceHandlerActions.php
M includes/ProcessBounceEmails.php
M tests/UnSubscribeUserTest.php
M tests/VERPEncodeDecodeTest.php
6 files changed, 43 insertions(+), 52 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BounceHandler 
refs/changes/38/170338/1

diff --git a/BounceHandler.php b/BounceHandler.php
index e2114d1..48b412c 100644
--- a/BounceHandler.php
+++ b/BounceHandler.php
@@ -6,10 +6,10 @@
        'path' => __FILE__,
        'name' => 'BounceHandler',
        'author' => array(
-                       'Tony Thomas',
-                       'Kunal Mehta',
-                       'Jeff Green',
-               ),
+               'Tony Thomas',
+               'Kunal Mehta',
+               'Jeff Green',
+       ),
        'url' => "https://www.mediawiki.org/wiki/Extension:BounceHandler";,
        'descriptionmsg' => 'bouncehandler-desc',
        'version'  => '1.0',
@@ -45,8 +45,7 @@
 $wgMessagesDirs['BounceHandler'] = $dir. '/i18n';
 
 # Schema updates for update.php
-$wgHooks['LoadExtensionSchemaUpdates'][] = 
'BounceHandlerHooks::addBounceRecordsTable';
-$wgHooks['LoadExtensionSchemaUpdates'][] = 
'BounceHandlerHooks::alterBounceRecordsUserColumn';
+$wgHooks['LoadExtensionSchemaUpdates'][] = 
'BounceHandlerHooks::loadExtensionSchemaUpdates';
 
 /**
  * VERP Configurations
diff --git a/BounceHandlerHooks.php b/BounceHandlerHooks.php
index 51397ce..c08bb15 100644
--- a/BounceHandlerHooks.php
+++ b/BounceHandlerHooks.php
@@ -42,6 +42,7 @@
                }
                $verpAddress = new VerpAddressGenerator( $wgVERPprefix, 
$wgVERPalgorithm, $wgVERPsecret, $wgServer, $wgSMTP );
                $returnPath = $verpAddress->generateVERP( $uid );
+
                return true;
        }
 
@@ -68,6 +69,7 @@
                }
 
                $files = array_merge( $files, $ourFiles );
+
                return true;
                // @codeCoverageIgnoreEnd
        }
@@ -78,26 +80,10 @@
         * @param DatabaseUpdater $updater
         * @return bool
         */
-       public static function addBounceRecordsTable( DatabaseUpdater $updater 
) {
-               $updater->addExtensionTable(
-                       'bounce_records',
-                       __DIR__. '/sql/bounce_records.sql', true
-               );
-               return true;
-       }
+       public static function LoadExtensionSchemaUpdates( DatabaseUpdater 
$updater ) {
+               $updater->addExtensionTable( 'bounce_records', __DIR__ . 
'/sql/bounce_records.sql', true );
+               $updater->modifyExtensionField( 'bounce_records', 'br_user', 
__DIR__ . '/sql/alter_user_column.sql' );
 
-       /**
-        * Rename 'br_user' column in bounce_records to 'br_user_email'
-        *
-        * @param DatabaseUpdater $updater
-        * @return bool
-        */
-       public static function alterBounceRecordsUserColumn( DatabaseUpdater 
$updater ) {
-               $updater->modifyExtensionField(
-                       'bounce_records',
-                       'br_user',
-                       __DIR__. '/sql/alter_user_column.sql'
-               );
                return true;
        }
 }
diff --git a/includes/BounceHandlerActions.php 
b/includes/BounceHandlerActions.php
index f2d19ed..f627711 100644
--- a/includes/BounceHandlerActions.php
+++ b/includes/BounceHandlerActions.php
@@ -51,7 +51,7 @@
                $res = $dbr->selectRow( 'bounce_records',
                        array( 'total_count' => 'COUNT(*)' ),
                        array(
-                               'br_user_email'=> $originalEmail,
+                               'br_user_email' => $originalEmail,
                                'br_timestamp >= ' . $dbr->addQuotes( 
wfTimestamp( $bounceValidPeriod ) )
                        ),
                        __METHOD__
@@ -83,14 +83,13 @@
                        if ( $caUser->isAttached( $this->wikiId ) ) {
                                $caUser->setEmailAuthenticationTimestamp( null 
);
                                $caUser->saveSettings();
-                               wfDebugLog( 'BounceHandler', " Un-subscribed 
global user $originalEmail for exceeding Bounce
-                               Limit $this->bounceRecordLimit" );
-                       } else {
-                               $this->unConfirmUserEmail( $user );
+                               wfDebugLog( 'BounceHandler',
+                                       "Un-subscribed global user 
$originalEmail for exceeding Bounce Limit $this->bounceRecordLimit"
+                               );
+                               return;
                        }
-               } else {
-                       $this->unConfirmUserEmail( $user );
                }
+               $this->unConfirmUserEmail( $user );
        }
 
        /**
@@ -103,7 +102,9 @@
                $res = $user->invalidateEmail();
                $user->saveSettings();
                if ( $res ) {
-                       wfDebugLog( 'BounceHandler', "Un-subscribed $userEmail 
for exceeding Bounce limit $this->bounceRecordLimit" );
+                       wfDebugLog( 'BounceHandler',
+                               "Un-subscribed $userEmail for exceeding Bounce 
limit $this->bounceRecordLimit"
+                       );
                } else {
                        wfDebugLog( 'BounceHandler', "Failed to un-subscribe 
the failing recipient $userEmail" );
                }
diff --git a/includes/ProcessBounceEmails.php b/includes/ProcessBounceEmails.php
index a554631..6feb948 100644
--- a/includes/ProcessBounceEmails.php
+++ b/includes/ProcessBounceEmails.php
@@ -51,7 +51,8 @@
                // Get original failed user email and wiki details
                $failedUser = $this->getUserDetails( $to );
                if( is_array( $failedUser ) && isset( $failedUser['wikiId'] ) 
&& isset( $failedUser['rawEmail'] )
-               && isset( $failedUser[ 'bounceTime' ] ) ) {
+                       && isset( $failedUser[ 'bounceTime' ] )
+               ) {
                        $wikiId = $failedUser['wikiId'];
                        $originalEmail = $failedUser['rawEmail'];
                        $bounceTimestamp= $failedUser['bounceTime'];
@@ -90,8 +91,10 @@
                $hashedVERPPart = explode( '-', $hashedPart[1] );
                $hashedData = $hashedVERPPart[0]. '-'. $hashedVERPPart[1]. '-'. 
$hashedVERPPart[2]. '-'. $hashedVERPPart[3];
                $bounceTime = base_convert( $hashedVERPPart[3], 36, 10 );
+
                if ( base64_encode( substr( hash_hmac( $wgVERPalgorithm, 
$hashedData, $wgVERPsecret, true ), 0, 12 ) ) === $hashedVERPPart[4]
-               && $currentTime - $bounceTime < $wgVERPAcceptTime ) {
+                       && $currentTime - $bounceTime < $wgVERPAcceptTime
+               ) {
                        $failedUser['wikiId'] = str_replace( '.', '-', 
$hashedVERPPart[1] );
                        $failedUser['rawUserId'] = base_convert( 
$hashedVERPPart[2], 36, 10 );
                        $failedEmail = self::getOriginalEmail( $failedUser );
@@ -99,7 +102,8 @@
                        $failedUser['bounceTime'] = $bounceTime;
                } else {
                        wfDebugLog( 'BounceHandler',
-                       "Error: Hash validation failed. Expected hash of 
$hashedData, got $hashedVERPPart[3]." );
+                               "Error: Hash validation failed. Expected hash 
of $hashedData, got $hashedVERPPart[3]."
+                       );
                }
                return $failedUser;
        }
diff --git a/tests/UnSubscribeUserTest.php b/tests/UnSubscribeUserTest.php
index e82baab..9a57dcf 100644
--- a/tests/UnSubscribeUserTest.php
+++ b/tests/UnSubscribeUserTest.php
@@ -27,16 +27,16 @@
                $bounceRecordPeriod = 604800;
                $bounceRecordLimit = 3;
 
-
-               $this->setMwGlobals( array(
-                       'wgVERPprefix' => $prefix,
-                       'wgVERPalgorithm' => $algorithm,
-                       'wgVERPsecret' => $secretKey,
-                       'wgServer' => $server,
-                       'wgSMTP' => $smtp,
-                       'wgBounceHandlerUnconfirmUsers' => true,
-                       'wgBounceRecordPeriod' => $bounceRecordPeriod,
-                       'wgBounceRecordLimit' => $bounceRecordLimit
+               $this->setMwGlobals(
+                       array(
+                               'wgVERPprefix' => $prefix,
+                               'wgVERPalgorithm' => $algorithm,
+                               'wgVERPsecret' => $secretKey,
+                               'wgServer' => $server,
+                               'wgSMTP' => $smtp,
+                               'wgBounceHandlerUnconfirmUsers' => true,
+                               'wgBounceRecordPeriod' => $bounceRecordPeriod,
+                               'wgBounceRecordLimit' => $bounceRecordLimit
                        )
                );
 
diff --git a/tests/VERPEncodeDecodeTest.php b/tests/VERPEncodeDecodeTest.php
index ea5299b..cdbf8ca 100644
--- a/tests/VERPEncodeDecodeTest.php
+++ b/tests/VERPEncodeDecodeTest.php
@@ -24,12 +24,13 @@
                $server = 'http://testwiki.org';
                $smtp = array();
 
-               $this->setMwGlobals( array(
-                       'wgVERPprefix' => $prefix,
-                       'wgVERPalgorithm' => $algorithm,
-                       'wgVERPsecret' => $secretKey,
-                       'wgServer' => $server,
-                       'wgSMTP' => $smtp
+               $this->setMwGlobals(
+                       array(
+                               'wgVERPprefix' => $prefix,
+                               'wgVERPalgorithm' => $algorithm,
+                               'wgVERPsecret' => $secretKey,
+                               'wgServer' => $server,
+                               'wgSMTP' => $smtp
                        )
                );
                $this->setMwGlobals( 'wgVERPAcceptTime', 259200 );

-- 
To view, visit https://gerrit.wikimedia.org/r/170338
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0b77a6084b38e3bc61ba660e099ae3623dea9614
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BounceHandler
Gerrit-Branch: master
Gerrit-Owner: Reedy <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to