Adamw has uploaded a new change for review.

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


Change subject: Clean up may2013 job, by marking thank-youed contributions
......................................................................

Clean up may2013 job, by marking thank-youed contributions

Change-Id: I45175ba9426cd132b7ad02a31d0bf05f4f567476
---
M 
sites/all/modules/oneoffs/201305_paypal_recurring/sorry_may2013_paypal_recurring.php
M sites/all/modules/oneoffs/oneoffs.drush.inc
2 files changed, 35 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/84/80484/1

diff --git 
a/sites/all/modules/oneoffs/201305_paypal_recurring/sorry_may2013_paypal_recurring.php
 
b/sites/all/modules/oneoffs/201305_paypal_recurring/sorry_may2013_paypal_recurring.php
index d738dec..2e5cca3 100644
--- 
a/sites/all/modules/oneoffs/201305_paypal_recurring/sorry_may2013_paypal_recurring.php
+++ 
b/sites/all/modules/oneoffs/201305_paypal_recurring/sorry_may2013_paypal_recurring.php
@@ -63,3 +63,30 @@
 
     drush_print( "Built mailing job. Run using 'drush wmf-send-letters 
{$job->getId()}'" );
 }
+
+function sorry_may2013_paypal_recurring_mark_thanked() {
+    $job_ran_date = '2013-08-14 00:00:00';
+
+    $query = db_select( 'wmf_communication_recipient', 'r' );
+    $query->join( 'wmf_communication_job', 'j', 'r.job_id = j.id' );
+    $query->addField( 'r', 'vars' );
+    $query->condition( 'j.template_class', 'SorryRecurringTemplate' )
+        ->condition( 'r.status', 'successful' );
+    $result = $query->execute();
+
+    $civi = civicrm_api_classapi();
+
+    while ( $vars = json_decode( $result->fetchField() ) ) {
+        foreach ( $vars->contributions as $contribution ) {
+            $success = $civi->Contribution->Create( array(
+                'id' => $contribution->contribution_id,
+                'thankyou_date' => $job_ran_date,
+
+                'version' => '3',
+            ) );
+            if ( !$success ) {
+                throw new Exception( "Failed to update contribution: " . 
$civi->errorMsg() );
+            }
+        }
+    }
+}
diff --git a/sites/all/modules/oneoffs/oneoffs.drush.inc 
b/sites/all/modules/oneoffs/oneoffs.drush.inc
index 3b0170f..4397527 100644
--- a/sites/all/modules/oneoffs/oneoffs.drush.inc
+++ b/sites/all/modules/oneoffs/oneoffs.drush.inc
@@ -10,6 +10,9 @@
         'oneoffs-sorry-may2013-build-job' => array(
             'description' => 'Compile a list of people affected',
         ),
+        'oneoffs-sorry-may2013-mark-thanked' => array(
+            'description' => 'Mark all email recipients as thank-you\'ed',
+        ),
     );
 
     return $items;
@@ -19,3 +22,8 @@
     require_once '201305_paypal_recurring/sorry_may2013_paypal_recurring.php';
     sorry_may2013_paypal_recurring_build_job();
 }
+
+function drush_oneoffs_sorry_may2013_mark_thanked() {
+    require_once '201305_paypal_recurring/sorry_may2013_paypal_recurring.php';
+    sorry_may2013_paypal_recurring_mark_thanked();
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I45175ba9426cd132b7ad02a31d0bf05f4f567476
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Adamw <awi...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to