r80668 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80667‎ | r80668 | r80669 >
Date:00:46, 21 January 2011
Author:awjrichards
Status:deferred
Tags:
Comment:
Updating contribution insert function with a hack to insert custom data for contributions
Modified paths:
  • /civicrm/trunk/sites/all/modules/queue2civicrm/queue2civicrm_common.inc (modified) (history)

Diff [purge]

Index: civicrm/trunk/sites/all/modules/queue2civicrm/queue2civicrm_common.inc
@@ -271,6 +271,12 @@
272272 'contribution_recur_id' => $recur_id
273273 );
274274
 275+ watchdog( 'queue2civicrm', 'Contribution array for civicrm_contribution_add(): ' . print_r($contribution, TRUE));
 276+
 277+ $contribution_result = civicrm_contribution_add( $contribution );
 278+
 279+ watchdog( 'queue2civicrm', 'Contribution result from civicrm_contribution_add(): ' . print_r($contribution_result, TRUE));
 280+
275281 /**
276282 * Apply custom field defaults.
277283 *
@@ -281,23 +287,22 @@
282288 *
283289 * At the moment, all custom fields get default values for online contribution EXCEPT for 'Donor Comment'.
284290 */
285 - $query = "SELECT id, custom_group_id, label, default_value FROM civicrm_custom_field WHERE custom_group_id IN (SELECT id FROM civicrm_custom_group WHERE extends='Contribution' && is_active='1');";
 291+ $dbs = _queue2civicrm_get_dbs();
 292+ $dbs->use_civicrm();
 293+ $query = "SELECT id, custom_group_id, label, default_value, table_name FROM civicrm_custom_field WHERE custom_group_id IN (SELECT id FROM civicrm_custom_group WHERE extends='Contribution' && is_active='1');";
286294 $dao = CRM_Core_DAO::executeQuery( $query ); // Execute's query using CiviCRM data object stuff
287295 while ( $dao->fetch() ) {
288296 if ( $dao->label == 'Donor Comment' ) {
289297 $comment = ( $msg[ 'comment' ] ) ? $msg[ 'comment'] : '';
290 - $contribution[ 'custom_' . $dao->id ] = $comment;
 298+ $query = "INSERT INTO {" . $dao->table_name . "} (entity_id, donor_comment) VALUES ( %d, '%s' )";
 299+ db_query( $query, $contribution[ 'id' ], $comment );
291300 } elseif ( $dao->default_value ) { // if we dont make sure $dao->default_value has some value, Civi breaks when we try to insert
292 - $contribution[ 'custom_' . $dao->id ] = $dao->default_value;
 301+ $query = "INSERT INTO {" . $dao->table_name . "} (entity_id) VALUES (%d)";
 302+ db_query( $query, $contribution[ 'id' ] );
293303 }
294304 }
295 -
296 - watchdog( 'queue2civicrm', 'Contribution array for civicrm_contribution_add(): ' . print_r($contribution, TRUE));
 305+ $dbs->use_default();
297306
298 - $contribution_result = civicrm_contribution_add( $contribution );
299 -
300 - watchdog( 'queue2civicrm', 'Contribution result from civicrm_contribution_add(): ' . print_r($contribution_result, TRUE));
301 -
302307 return $contribution_result;
303308 }
304309

Status & tagging log