Index: civicrm/trunk/sites/all/modules/queue2civicrm/recurring/recurring.module |
— | — | @@ -206,8 +206,6 @@ |
207 | 207 | * @return int |
208 | 208 | */ |
209 | 209 | function recurring_import_subscr_payment( $msg ) { |
210 | | - global $queue2civicrm_dbs; |
211 | | - |
212 | 210 | /** |
213 | 211 | * if the subscr_id is not set, we can't process it due to an error in the message. |
214 | 212 | * |
— | — | @@ -264,6 +262,7 @@ |
265 | 263 | } |
266 | 264 | |
267 | 265 | // update subscription record with next payment date |
| 266 | + $queue2civicrm_dbs = _queue2civicrm_get_dbs(); |
268 | 267 | $queue2civicrm_dbs->use_civicrm(); |
269 | 268 | $query = "UPDATE {civicrm_contribution_recur} SET next_sched_contribution='%s'"; |
270 | 269 | db_query( $query, date('Y-m-d H:i:s', strtotime( "+" . $msg[ 'frequency_interval' ] . " " . $msg[ 'frequency_unit' ], $msg[ 'payment_date' ] ))); |
— | — | @@ -329,7 +328,6 @@ |
330 | 329 | * @return int |
331 | 330 | */ |
332 | 331 | function recurring_import_subscr_signup( $msg ) { |
333 | | - global $queue2civicrm_dbs; |
334 | 332 | // ensure there is not already a record of this account - if so, mark the message as succesfuly processed |
335 | 333 | if ( $recur_record = recurring_get_recur_record( $msg[ 'subscr_id' ] ) ) { |
336 | 334 | watchdog( 'recurring', 'Subscription account already exists: %msg', array( '%msg' => print_r( $msg, true )), WATCHDOG_NOTICE ); |
— | — | @@ -358,6 +356,7 @@ |
359 | 357 | next_sched_contribution ) |
360 | 358 | VALUES ( %d, %d, '%s', %d, '%s', '%s', '%s', '%s', '%s' )"; |
361 | 359 | |
| 360 | + $queue2civicrm_dbs = _queue2civicrm_get_dbs(); |
362 | 361 | $queue2civicrm_dbs->use_civicrm(); |
363 | 362 | $result = db_query( $query, |
364 | 363 | $contact[ 'contact_id' ], |
— | — | @@ -388,7 +387,6 @@ |
389 | 388 | * @return int |
390 | 389 | */ |
391 | 390 | function recurring_import_subscr_cancel( $msg ) { |
392 | | - global $queue2civicrm_dbs; |
393 | 391 | // ensure we have a record of the subscription |
394 | 392 | if ( !$recur_record = recurring_get_recur_record( $msg[ 'subscr_id' ] ) ) { |
395 | 393 | watchdog( 'recurring', 'Subscription account does not exist: %msg', array( '%msg' => print_r( $msg, true )), WATCHDOG_NOTICE ); |
— | — | @@ -397,6 +395,7 @@ |
398 | 396 | |
399 | 397 | $query = "UPDATE {civicrm_contribution_recur} SET cancel_date='%s', end_date='%s' WHERE trxn_id='%s'"; |
400 | 398 | |
| 399 | + $queue2civicrm_dbs = _queue2civicrm_get_dbs(); |
401 | 400 | $queue2civicrm_dbs->use_civicrm(); |
402 | 401 | $result = db_query( |
403 | 402 | $query, |
— | — | @@ -421,8 +420,6 @@ |
422 | 421 | * @return int |
423 | 422 | */ |
424 | 423 | function recurring_import_subscr_eot( $msg ) { |
425 | | - global $queue2civicrm_dbs; |
426 | | - |
427 | 424 | // ensure we have a record of the subscription |
428 | 425 | if ( !$recur_record = recurring_get_recur_record( $msg[ 'subscr_id' ] ) ) { |
429 | 426 | watchdog( 'recurring', 'Subscription account does not exist: %msg', array( '%msg' => print_r( $msg, true )), WATCHDOG_NOTICE ); |
— | — | @@ -431,6 +428,7 @@ |
432 | 429 | |
433 | 430 | $query = "UPDATE {civicrm_contribution_recur} SET end_date='%s', next_sched_contribution=NULL WHERE trxn_id='%s'"; |
434 | 431 | |
| 432 | + $queue2civicrm_dbs = _queue2civicrm_get_dbs(); |
435 | 433 | $queue2civicrm_dbs->use_civicrm(); |
436 | 434 | $result = db_query( $query, date( 'Y-m-d H:i:s' ), $msg[ 'subscr_id' ] ); |
437 | 435 | $queue2civicrm_dbs->use_default(); |
— | — | @@ -454,8 +452,6 @@ |
455 | 453 | * @return int |
456 | 454 | */ |
457 | 455 | function recurring_import_subscr_modify( $msg ) { |
458 | | - global $queue2civicrm_dbs; |
459 | | - |
460 | 456 | // ensure we have a record of the subscription |
461 | 457 | if ( !$recur_record = recurring_get_recur_record( $msg[ 'subscr_id' ] ) ) { |
462 | 458 | 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 @@ |
474 | 470 | WHERE |
475 | 471 | trxn_id='%s'"; |
476 | 472 | |
| 473 | + $queue2civicrm_dbs = _queue2civicrm_get_dbs(); |
477 | 474 | $queue2civicrm_dbs->use_civicrm(); |
478 | 475 | $result = db_query( $query, |
479 | 476 | $msg[ 'amount' ], |
— | — | @@ -508,8 +505,6 @@ |
509 | 506 | * @return unknown_type |
510 | 507 | */ |
511 | 508 | function recurring_import_subscr_failed( $msg ) { |
512 | | - global $queue2civicrm_dbs; |
513 | | - |
514 | 509 | // ensure we have a record of the subscription |
515 | 510 | if ( !$recur_record = recurring_get_recur_record( $msg[ 'subscr_id' ] ) ) { |
516 | 511 | watchdog( 'recurring', 'Subscription account does not exist for subscription: %subscription', array( "%subscription" => print_r( $msg, true )), WATCHDOG_NOTICE ); |
— | — | @@ -518,6 +513,7 @@ |
519 | 514 | |
520 | 515 | $query = "UPDATE {civicrm_contribution_recur} SET failure_count=%d, failure_retry_date='%s' WHERE trxn_id='%s'"; |
521 | 516 | |
| 517 | + $queue2civicrm_dbs = _queue2civicrm_get_dbs(); |
522 | 518 | $queue2civicrm_dbs->use_civicrm(); |
523 | 519 | $result = db_query( $query, $msg[ 'failure_count' ], date( 'Y-m-d H:i:s', $msg[ 'failure_retry_date' ] ), $msg[ 'subscr_id' ] ); |
524 | 520 | $queue2civicrm_dbs->use_default(); |
— | — | @@ -537,9 +533,9 @@ |
538 | 534 | * @return object |
539 | 535 | */ |
540 | 536 | function recurring_get_recur_record( $subscr_id ) { |
541 | | - global $queue2civicrm_dbs; |
542 | 537 | $query = "SELECT * FROM civicrm_contribution_recur WHERE trxn_id = '%s'"; |
543 | | - |
| 538 | + |
| 539 | + $queue2civicrm_dbs = _queue2civicrm_get_dbs(); |
544 | 540 | $queue2civicrm_dbs->use_civicrm(); |
545 | 541 | $recur_record = db_fetch_object( db_query( $query, $subscr_id ) ); |
546 | 542 | $queue2civicrm_dbs->use_default(); |
— | — | @@ -584,7 +580,6 @@ |
585 | 581 | * @return array |
586 | 582 | */ |
587 | 583 | function recurring_normalize_paypal_msg( $msg ) { |
588 | | - global $queue2civicrm_dbs; |
589 | 584 | $msg_normalized = array(); |
590 | 585 | |
591 | 586 | $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 @@ |
354 | 354 | } |
355 | 355 | |
356 | 356 | 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; |
357 | 371 | } |
\ No newline at end of file |
Index: civicrm/trunk/sites/all/modules/queue2civicrm/queue2civicrm_db_switcher.inc |
— | — | @@ -3,8 +3,6 @@ |
4 | 4 | * Class to facilitate swithing of db access between CiviCRM and Drupal |
5 | 5 | */ |
6 | 6 | |
7 | | -$queue2civicrm_dbs = new queue2civicrm_db_switcher(); |
8 | | - |
9 | 7 | class queue2civicrm_db_switcher { |
10 | 8 | |
11 | 9 | public function __construct() { |