Ejegg has uploaded a new change for review.

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

Change subject: Expire old pending messages
......................................................................

Expire old pending messages

Change-Id: I96e2881b31146b328282321e5650b719b3c91668
---
M Core/DataStores/PendingDatabase.php
A Maintenance/DeleteExpiredPendingMessages.php
M SmashPig.yaml
3 files changed, 63 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig 
refs/changes/94/322294/1

diff --git a/Core/DataStores/PendingDatabase.php 
b/Core/DataStores/PendingDatabase.php
index 4d9bcfc..c54e4b3 100644
--- a/Core/DataStores/PendingDatabase.php
+++ b/Core/DataStores/PendingDatabase.php
@@ -159,6 +159,26 @@
        }
 
        /**
+        * Delete expired messages, optionally by gateway
+        *
+        * @param int $originalDate Oldest date to keep
+        * @param string|null $gateway
+        * @return int Number of rows deleted
+        */
+       public function deleteOldMessages( $originalDate, $gateway = null ) {
+               $sql = 'DELETE FROM pending WHERE date < :date';
+               $params = array(
+                       'date' => UtcDate::getUtcDatabaseString( $originalDate 
),
+               );
+               if ( $gateway ) {
+                       $sql .= ' AND gateway = :gateway';
+                       $params['gateway'] = $gateway;
+               }
+               $executed = $this->prepareAndExecute( $sql, $params );
+               return $executed->rowCount();
+       }
+
+       /**
         * Parse a database row and return the normalized message.
         */
        protected function messageFromDbRow( $row ) {
diff --git a/Maintenance/DeleteExpiredPendingMessages.php 
b/Maintenance/DeleteExpiredPendingMessages.php
new file mode 100644
index 0000000..98e05b2
--- /dev/null
+++ b/Maintenance/DeleteExpiredPendingMessages.php
@@ -0,0 +1,42 @@
+<?php
+namespace SmashPig\Maintenance;
+
+require ( 'MaintenanceBase.php' );
+
+use SmashPig\Core\Logging\Logger;
+use SmashPig\Core\DataStores\PendingDatabase;
+use SmashPig\Core\UtcDate;
+
+$maintClass = '\SmashPig\Maintenance\DeleteExpiredPendingMessage';
+
+/**
+ * Deletes old messages from the pending table
+ */
+class DeleteExpiredPendingMessage extends MaintenanceBase {
+
+       public function __construct() {
+               parent::__construct();
+               $this->addOption( 'gateway', 'gateway to delete messages for' );
+               $this->addOption( 'days', 'age in days of oldest messages to 
keep', 30 );
+       }
+
+       /**
+        * Do the actual work of the script.
+        */
+       public function execute() {
+               $pendingDatabase = PendingDatabase::get();
+               $gateway = $this->getOption( 'gateway' );
+               $days = $this->getOption( 'days' );
+               $deleteBefore = UtcDate::getUtcTimestamp( "-$days days" );
+
+               $startTime = time();
+               $deleted = $pendingDatabase->deleteOldMessages( $deleteBefore, 
$gateway );
+
+               $elapsedTime = time() - $startTime;
+               Logger::info(
+                       "Deleted $deleted pending messages in $elapsedTime 
seconds."
+               );
+       }
+}
+
+require ( RUN_MAINTENANCE_IF_MAIN );
diff --git a/SmashPig.yaml b/SmashPig.yaml
index eab2a66..067694f 100644
--- a/SmashPig.yaml
+++ b/SmashPig.yaml
@@ -335,8 +335,7 @@
         region: ''
         sandbox: false
 
-    # Override these to mock the Amazon SDK classes
-    payments-client:
+    # Override these
         class: PayWithAmazon\PaymentsClient
         constructor-parameters:
             - <<: *CREDENTIALS

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I96e2881b31146b328282321e5650b719b3c91668
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>

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

Reply via email to