jenkins-bot has submitted this change and it was merged.

Change subject: Simulate 1000 emails
......................................................................


Simulate 1000 emails

Just the database bits, no actual email sending.

This WILL update the thankyou_date column and add activities
according to CiviMail record configuration.

It also needs 1000 rows in the contribution table with
thankyou_date = null and contacts with email that isn't
nob...@wikimedia.org

FIXME: some stupid manipulation of the thank_you_days parameter.

Change-Id: Icc7bb5bc2a1fdc6091579a13ebda9d010a5fdc3a
---
M sites/all/modules/thank_you/thank_you.drush.inc
M sites/all/modules/thank_you/thank_you.module
2 files changed, 90 insertions(+), 0 deletions(-)

Approvals:
  Awight: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/sites/all/modules/thank_you/thank_you.drush.inc 
b/sites/all/modules/thank_you/thank_you.drush.inc
index bfe12c8..6dbdc0d 100644
--- a/sites/all/modules/thank_you/thank_you.drush.inc
+++ b/sites/all/modules/thank_you/thank_you.drush.inc
@@ -13,6 +13,11 @@
     'aliases' => array( 'ty' ),
   );
 
+  $items['thank-you-test'] = array(
+    'description' =>
+      'Simulates sending 1000 thank you emails for donations, to test DB 
performance',
+    'aliases' => array( 'tyt' ),
+  );
   return $items;
 }
 
@@ -47,3 +52,14 @@
          exit(drush_get_error());
   }
 }
+
+
+/**
+ * Fires the 'batch_process' method in the thank_you module.
+ *
+ * This simply executes the code necessary to run the thank you modules.
+ * All configuration happens in the module.
+ */
+function drush_thank_you_test() {
+       module_invoke( 'thank_you', 'batch_test' );
+}
diff --git a/sites/all/modules/thank_you/thank_you.module 
b/sites/all/modules/thank_you/thank_you.module
index 12f7404..abd2562 100644
--- a/sites/all/modules/thank_you/thank_you.module
+++ b/sites/all/modules/thank_you/thank_you.module
@@ -15,6 +15,9 @@
 // * reconsider need for twig extensions, we already do calculated values
 // * give template fragments a named key rather than using integers
 
+// FIXME: this constant is for test code
+const DUMB_BIG_TY_DAYS = 100000;
+
 /**
  * Implements hook_permission
  */
@@ -718,6 +721,15 @@
         return;
        }
 
+       // FIXME: refactor this whole module to be more object oriented, so we 
can
+       // just set these properties and override during the test.
+       // This code resets the thank_you_days variable in case it's been left 
in
+       // a bad state by an aborted simulation run
+       if ( $days == DUMB_BIG_TY_DAYS ) {
+               $days = variable_get( 'old_thank_you_days', false );
+               variable_set( 'thank_you_days', $days );
+       }
+
        watchdog( "thank_you", "Attempting to send $batch thank you mails for 
contributions from the last $days days.", array(), WATCHDOG_INFO );
 
        $dbs = wmf_civicrm_get_dbs();
@@ -843,5 +855,67 @@
        return variable_get( 'thank_you_unsubscribe_url', '' ) . '?' . 
http_build_query( $unsub_params, '', '&' );
 }
 
+function thank_you_batch_test() {
+       if ( !defined( 'WMF_UNSUB_SALT' ) ) {
+               define( 'WMF_UNSUB_SALT', 'aslkdhaslkdjasd' );
+       }
+       civicrm_initialize();
+
+       $create_civi_mail = variable_get( 'thank_you_add_civimail_records', 
'false' );
+       $rate = variable_get( 'thank_you_civimail_rate', 1.0 );
+
+       // Don't actually send any emails
+       wmf_communication\Mailer::$defaultSystem = 'test';
+
+       // Don't want to skip anything due to age
+       $oldTyDays = variable_get('thank_you_days', 14);
+       variable_set('old_thank_you_days', $oldTyDays);
+       variable_set('thank_you_days', DUMB_BIG_TY_DAYS);
+
+       watchdog( "thank_you", "Simulating up to 1000 thank you mails.", 
array(), WATCHDOG_INFO );
+       watchdog( "thank_you", "Civimail creation: $create_civi_mail. Sample 
rate: $rate", array(), WATCHDOG_INFO );
+
+       $start = time();
+       $sent = 0;
+       
+       $dbs = wmf_civicrm_get_dbs();
+       $dbs->push( 'civicrm' );
+       try {
+
+               $ty_query = <<<EOT
+               SELECT civicrm_contribution.id, trxn_id
+               FROM civicrm_contribution
+               JOIN wmf_contribution_extra
+                       ON wmf_contribution_extra.entity_id = 
civicrm_contribution.id
+               JOIN civicrm_email
+                       ON civicrm_email.contact_id = 
civicrm_contribution.contact_id
+               WHERE trxn_id IS NOT NULL
+               AND civicrm_email.email <> 'nob...@wikimedia.org'
+               AND thankyou_date IS NULL
+               AND no_thank_you IS NULL
+               ORDER BY id DESC LIMIT 1000;
+EOT;
+
+               $result = db_query( $ty_query );
+               foreach ( $result as $contribution ) {
+                       watchdog(
+                               "thank_you",
+                               "Pretending to send thank you mail for 
contribution ID [{$contribution->id}], trxn_id [{$contribution->trxn_id}]",
+                               array(),
+                               WATCHDOG_INFO
+                       );
+                       if ( thank_you_for_contribution( $contribution->id ) ) {
+                               $sent++;
+                       }
+               }
+       } catch ( Exception $ex ) {
+               // Just need to make sure we reset the TY days
+       }
+       $dbs->pop();
+       $elapsed = time() - $start;
+       variable_set('thank_you_days', $oldTyDays);
+       watchdog( "thank_you", "Simulated sending $sent emails in $elapsed 
seconds.", array(), WATCHDOG_INFO );
+}
+
 class ThankYouException extends Exception {}
 class TemplateInfoMissingException extends Exception {}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Icc7bb5bc2a1fdc6091579a13ebda9d010a5fdc3a
Gerrit-PatchSet: 5
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>
Gerrit-Reviewer: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to