Adamw has uploaded a new change for review.

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


Change subject: WIP (FR #986) prepare mailing job to apologize for May 2013 
hole.
......................................................................

WIP (FR #986) prepare mailing job to apologize for May 2013 hole.

Change-Id: Ic9ce7d36eeee0f9bbcbbdab65a578dd9f10d6b2c
---
A sites/all/modules/oneoffs/sorry_may2013_paypal_recurring.drush.inc
M sites/all/modules/wmf_common/wmf_communication/Job.php
M sites/all/modules/wmf_common/wmf_communication/tests/Job.test
3 files changed, 86 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/73/74573/1

diff --git a/sites/all/modules/oneoffs/sorry_may2013_paypal_recurring.drush.inc 
b/sites/all/modules/oneoffs/sorry_may2013_paypal_recurring.drush.inc
new file mode 100644
index 0000000..e00eb8b
--- /dev/null
+++ b/sites/all/modules/oneoffs/sorry_may2013_paypal_recurring.drush.inc
@@ -0,0 +1,69 @@
+<?php
+
+use wmf_communication\AbstractMailingTemplate;
+use wmf_communication\Recipient;
+
+/**
+ * Create a mailing job to apologize for the May 2013 Paypal recurring hole.
+ *
+ * See https://mingle.corp.wikimedia.org/projects/fundraiser_2012/cards/986
+ */
+function sorry_may2013_paypal_recurring_drush_command() {
+    $dbs = module_invoke( 'wmf_civicrm', 'get_dbs' );
+
+    $dbs->push( 'civicrm' );
+    $result = db_query( "
+SELECT
+    cc.contact_id,
+    cc.total_amount AS amount,
+    cc.receive_date
+FROM civicrm_contribution cc
+LEFT JOIN civicrm_email ce ON ce.contact_id = cc.contact_id
+LEFT JOIN civicrm_address ca ON ca.contact_id = cc.contact_id
+LEFT JOIN civicrm_country cco ON ca.country_id = cco.id
+    WHERE
+        cc.thankyou_date IS NULL
+        AND cc.trxn_id LIKE 'RECURRING PAYPAL%'
+        AND cco.iso_code = 'US'
+        AND cc.receive_date BETWEEN '2013-02-01' AND '2013-05-01'
+;
+" );
+    $contributions = $result->fetchAllAssoc( 'contribution_id', 
PDO::FETCH_ASSOC );
+
+    $byContact = array();
+    foreach ( $contributions as $row ) {
+        $byContact[$row['contact_id']][] = $row;
+    }
+
+    $dbs->push( 'drupal' );
+
+    $job = Job::create( 'SorryRecurringTemplate' );
+
+    foreach ( $byContact as $contactId => $contributions ) {
+        Recipient::create(
+            $job->id,
+            $contactId,
+            array(
+                'contributions' => $contributions,
+            )
+        );
+    }
+}
+
+class SorryRecurringTemplate extends AbstractMailingTemplate {
+    function getSubject( $recipient ) {
+        return 'Belated Thank-you from the Wikimedia Foundation';
+    }
+
+    function getSubjectKey() {
+        return null;
+    }
+
+    function getTemplateName() {
+        return 'sorry_may2013';
+    }
+
+    function getTemplateDir() {
+        return __DIR__ . "/templates";
+    }
+}
diff --git a/sites/all/modules/wmf_common/wmf_communication/Job.php 
b/sites/all/modules/wmf_common/wmf_communication/Job.php
index 3dd677a..1c88d14 100644
--- a/sites/all/modules/wmf_common/wmf_communication/Job.php
+++ b/sites/all/modules/wmf_common/wmf_communication/Job.php
@@ -38,6 +38,16 @@
         return $job;
     }
 
+    static function create( $templateClass ) {
+        $jobId = db_insert( 'wmf_communication_job' )
+            ->fields( array(
+                'template_class' => $templateClass,
+            ) )
+            ->execute();
+
+        return Job::getJob( $jobId );
+    }
+
     /**
      * Find all queued recipients and send letters.
      */
@@ -83,4 +93,8 @@
                 WATCHDOG_INFO );
         }
     }
+
+    function getId() {
+        return $this->id;
+    }
 }
diff --git a/sites/all/modules/wmf_common/wmf_communication/tests/Job.test 
b/sites/all/modules/wmf_common/wmf_communication/tests/Job.test
index 51d5ee0..31a4d22 100644
--- a/sites/all/modules/wmf_common/wmf_communication/tests/Job.test
+++ b/sites/all/modules/wmf_common/wmf_communication/tests/Job.test
@@ -50,14 +50,10 @@
         $contact = array_pop( $result );
         $this->contactId = $contact->id;
 
-        $this->jobId = db_insert( 'wmf_communication_job' )
-            ->fields( array(
-                'template_class' => 'TestThankyouTemplate',
-            ) )
-            ->execute();
+        $this->job = Job::create( 'TestThankyouTemplate' );
 
         Recipient::create(
-            $this->jobId,
+            $this->job->getId(),
             $this->contactId,
             array(
                 'amount' => 'EUR 22.11',
@@ -67,9 +63,7 @@
     }
 
     public function testRun() {
-        $job = Job::getJob( $this->jobId );
-        $this->assertNotNull( $job, "Got the job" );
-        $job->run();
+        $this->job->run();
 
         $mails = $this->drupalGetMails();
         $this->assertEqual( count( $mails ), 1,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic9ce7d36eeee0f9bbcbbdab65a578dd9f10d6b2c
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>

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

Reply via email to