r80591 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80590‎ | r80591 | r80592 >
Date:21:53, 19 January 2011
Author:awjrichards
Status:deferred
Tags:
Comment:
Changing how database switcher objects get instantiated, storing in static variable accessible via _queue2civicrm_get_dbs() in quee2civicrm_common.inc to make easily globally available to queue2civicrm-related modules
Modified paths:
  • /civicrm/trunk/sites/all/modules/queue2civicrm/queue2civicrm_common.inc (modified) (history)
  • /civicrm/trunk/sites/all/modules/queue2civicrm/queue2civicrm_db_switcher.inc (modified) (history)
  • /civicrm/trunk/sites/all/modules/queue2civicrm/recurring/recurring.module (modified) (history)

Diff [purge]

Index: civicrm/trunk/sites/all/modules/queue2civicrm/recurring/recurring.module
@@ -206,8 +206,6 @@
207207 * @return int
208208 */
209209 function recurring_import_subscr_payment( $msg ) {
210 - global $queue2civicrm_dbs;
211 -
212210 /**
213211 * if the subscr_id is not set, we can't process it due to an error in the message.
214212 *
@@ -264,6 +262,7 @@
265263 }
266264
267265 // update subscription record with next payment date
 266+ $queue2civicrm_dbs = _queue2civicrm_get_dbs();
268267 $queue2civicrm_dbs->use_civicrm();
269268 $query = "UPDATE {civicrm_contribution_recur} SET next_sched_contribution='%s'";
270269 db_query( $query, date('Y-m-d H:i:s', strtotime( "+" . $msg[ 'frequency_interval' ] . " " . $msg[ 'frequency_unit' ], $msg[ 'payment_date' ] )));
@@ -329,7 +328,6 @@
330329 * @return int
331330 */
332331 function recurring_import_subscr_signup( $msg ) {
333 - global $queue2civicrm_dbs;
334332 // ensure there is not already a record of this account - if so, mark the message as succesfuly processed
335333 if ( $recur_record = recurring_get_recur_record( $msg[ 'subscr_id' ] ) ) {
336334 watchdog( 'recurring', 'Subscription account already exists: %msg', array( '%msg' => print_r( $msg, true )), WATCHDOG_NOTICE );
@@ -358,6 +356,7 @@
359357 next_sched_contribution )
360358 VALUES ( %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s' )";
361359
 360+ $queue2civicrm_dbs = _queue2civicrm_get_dbs();
362361 $queue2civicrm_dbs->use_civicrm();
363362 $result = db_query( $query,
364363 $contact[ 'contact_id' ],
@@ -388,7 +387,6 @@
389388 * @return int
390389 */
391390 function recurring_import_subscr_cancel( $msg ) {
392 - global $queue2civicrm_dbs;
393391 // ensure we have a record of the subscription
394392 if ( !$recur_record = recurring_get_recur_record( $msg[ 'subscr_id' ] ) ) {
395393 watchdog( 'recurring', 'Subscription account does not exist: %msg', array( '%msg' => print_r( $msg, true )), WATCHDOG_NOTICE );
@@ -397,6 +395,7 @@
398396
399397 $query = "UPDATE {civicrm_contribution_recur} SET cancel_date='%s', end_date='%s' WHERE trxn_id='%s'";
400398
 399+ $queue2civicrm_dbs = _queue2civicrm_get_dbs();
401400 $queue2civicrm_dbs->use_civicrm();
402401 $result = db_query(
403402 $query,
@@ -421,8 +420,6 @@
422421 * @return int
423422 */
424423 function recurring_import_subscr_eot( $msg ) {
425 - global $queue2civicrm_dbs;
426 -
427424 // ensure we have a record of the subscription
428425 if ( !$recur_record = recurring_get_recur_record( $msg[ 'subscr_id' ] ) ) {
429426 watchdog( 'recurring', 'Subscription account does not exist: %msg', array( '%msg' => print_r( $msg, true )), WATCHDOG_NOTICE );
@@ -431,6 +428,7 @@
432429
433430 $query = "UPDATE {civicrm_contribution_recur} SET end_date='%s', next_sched_contribution=NULL WHERE trxn_id='%s'";
434431
 432+ $queue2civicrm_dbs = _queue2civicrm_get_dbs();
435433 $queue2civicrm_dbs->use_civicrm();
436434 $result = db_query( $query, date( 'Y-m-d H:i:s' ), $msg[ 'subscr_id' ] );
437435 $queue2civicrm_dbs->use_default();
@@ -454,8 +452,6 @@
455453 * @return int
456454 */
457455 function recurring_import_subscr_modify( $msg ) {
458 - global $queue2civicrm_dbs;
459 -
460456 // ensure we have a record of the subscription
461457 if ( !$recur_record = recurring_get_recur_record( $msg[ 'subscr_id' ] ) ) {
462458 watchdog( 'recurring', 'Subscription account does not exist for subscription id: %subscr_id', array( '%subscr_id' => print_r( $msg, true )), WATCHDOG_NOTICE );
@@ -473,6 +469,7 @@
474470 WHERE
475471 trxn_id='%s'";
476472
 473+ $queue2civicrm_dbs = _queue2civicrm_get_dbs();
477474 $queue2civicrm_dbs->use_civicrm();
478475 $result = db_query( $query,
479476 $msg[ 'amount' ],
@@ -508,8 +505,6 @@
509506 * @return unknown_type
510507 */
511508 function recurring_import_subscr_failed( $msg ) {
512 - global $queue2civicrm_dbs;
513 -
514509 // ensure we have a record of the subscription
515510 if ( !$recur_record = recurring_get_recur_record( $msg[ 'subscr_id' ] ) ) {
516511 watchdog( 'recurring', 'Subscription account does not exist for subscription: %subscription', array( "%subscription" => print_r( $msg, true )), WATCHDOG_NOTICE );
@@ -518,6 +513,7 @@
519514
520515 $query = "UPDATE {civicrm_contribution_recur} SET failure_count=%d, failure_retry_date='%s' WHERE trxn_id='%s'";
521516
 517+ $queue2civicrm_dbs = _queue2civicrm_get_dbs();
522518 $queue2civicrm_dbs->use_civicrm();
523519 $result = db_query( $query, $msg[ 'failure_count' ], date( 'Y-m-d H:i:s', $msg[ 'failure_retry_date' ] ), $msg[ 'subscr_id' ] );
524520 $queue2civicrm_dbs->use_default();
@@ -537,9 +533,9 @@
538534 * @return object
539535 */
540536 function recurring_get_recur_record( $subscr_id ) {
541 - global $queue2civicrm_dbs;
542537 $query = "SELECT * FROM civicrm_contribution_recur WHERE trxn_id = '%s'";
543 -
 538+
 539+ $queue2civicrm_dbs = _queue2civicrm_get_dbs();
544540 $queue2civicrm_dbs->use_civicrm();
545541 $recur_record = db_fetch_object( db_query( $query, $subscr_id ) );
546542 $queue2civicrm_dbs->use_default();
@@ -584,7 +580,6 @@
585581 * @return array
586582 */
587583 function recurring_normalize_paypal_msg( $msg ) {
588 - global $queue2civicrm_dbs;
589584 $msg_normalized = array();
590585
591586 $timestamp = ( !isset( $msg[ 'payment_date' ] ) || !strlen( $msg[ 'payment_date' ] )) ? strtotime( "now" ) : strtotime( $msg[ 'payment_date' ] );
Index: civicrm/trunk/sites/all/modules/queue2civicrm/queue2civicrm_common.inc
@@ -353,4 +353,18 @@
354354 }
355355
356356 return $state;
 357+}
 358+
 359+/**
 360+ * Manage the database switching object
 361+ * @return object
 362+ */
 363+function _queue2civicrm_get_dbs() {
 364+ static $dbs = NULL;
 365+
 366+ if ( !$dbs ) {
 367+ $dbs = new queue2civicrm_db_switcher();
 368+ }
 369+
 370+ return $dbs;
357371 }
\ No newline at end of file
Index: civicrm/trunk/sites/all/modules/queue2civicrm/queue2civicrm_db_switcher.inc
@@ -3,8 +3,6 @@
44 * Class to facilitate swithing of db access between CiviCRM and Drupal
55 */
66
7 -$queue2civicrm_dbs = new queue2civicrm_db_switcher();
8 -
97 class queue2civicrm_db_switcher {
108
119 public function __construct() {

Status & tagging log