r80283 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80282‎ | r80283 | r80284 >
Date:17:59, 14 January 2011
Author:awjrichards
Status:deferred
Tags:
Comment:
Updating how location inserts/updates are handled, following new formatting for civicrm v3 api - added location preparation function to build params for both insertion and update
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
@@ -171,21 +171,8 @@
172172 */
173173 function _queue2civicrm_location_insert( $msg, $contact ) {
174174 require_once 'api/v2/Location.php';
175 -
176 - $address = array(
177 - 'contact_id' => $contact[ 'contact_id' ],
178 - 'location_type' => 'Home',
179 - 'street_address' => $msg['street_address'],
180 - 'supplemental_address_1' => $msg['supplemental_address_1'],
181 - 'city' => $msg['city'],
182 - 'state_province' => _queue2civicrm_get_state( $msg[ 'country' ], $msg['state_province'] ),
183 - 'postal_code' => $msg['postal_code'],
184 - 'country' => $msg['country'],
185 - 'is_primary' => 1,
186 - 'is_billing' => 1,
187 - 'email' => $msg['email']
188 - );
189 - $location_result = &civicrm_location_add( $address );
 175+ $params = _queue2civicrm_location_prepare_params( $msg, $contact );
 176+ $location_result = &civicrm_location_add( $params );
190177 watchdog( 'queue2civicrm', 'Result for adding location: %location', array( '%location' => print_r( $location_result, true )), WATCHDOG_DEBUG );
191178 return $location_result;
192179 }
@@ -202,21 +189,49 @@
203190 */
204191 function _queue2civicrm_location_update( $msg, $contact ) {
205192 require_once 'api/v2/Location.php';
 193+ $params = _queue2civicrm_location_prepare_params( $msg, $contact );
 194+ $location_result = &civicrm_location_update( $params );
 195+ watchdog( 'queue2civicrm', 'Result for updating location: %location', array( '%location' => print_r( $location_result, true )), WATCHDOG_DEBUG );
 196+ return $location_result;
 197+}
 198+
 199+/**
 200+ * Prepare the parameters for location adding/updating
 201+ *
 202+ * @param $msg
 203+ * @param $contact
 204+ * @return array
 205+ */
 206+function _queue2civicrm_location_prepare_params( $msg, $contact ) {
 207+ $emails = array(
 208+ array(
 209+ 'email' => $msg[ 'email' ],
 210+ 'location_type_id' => 1,
 211+ )
 212+ );
206213
207214 $address = array(
208 - 'contact_id' => $contact[ 'contact_id' ],
209 - 'street_address' => $msg['street_address'],
210 - 'supplemental_address_1' => $msg['supplemental_address_1'],
211 - 'city' => $msg['city'],
212 - 'state_province' => _queue2civicrm_get_state( $msg[ 'country' ], $msg['state_province'] ),
213 - 'postal_code' => $msg['postal_code'],
214 - 'country' => $msg['country'],
215 - 'email' => $msg['email'],
216 - 'location_type_id' => '1',
 215+ 1 => array(
 216+ 'location_type_id' => 1, //Home
 217+ 'is_primary' => 1,
 218+ 'street_address' => $msg['street_address'],
 219+ 'supplemental_address_1' => $msg['supplemental_address_1'],
 220+ 'city' => $msg['city'],
 221+ 'state_province' => _queue2civicrm_get_state( $msg[ 'country' ], $msg['state_province'] ),
 222+ 'postal_code' => $msg['postal_code'],
 223+ 'country' => $msg['country'],
 224+ 'is_billing' => 1,
 225+ )
217226 );
218 - $location_result = &civicrm_location_update( $address );
219 - watchdog( 'queue2civicrm', 'Result for updating location: %location', array( '%location' => print_r( $location_result, true )), WATCHDOG_DEBUG );
220 - return $location_result;
 227+
 228+ $params = array(
 229+ 'version' => '3.0',
 230+ 'contact_id' => $contact[ 'contact_id' ],
 231+ 'address' => $address,
 232+ 'email' => $emails
 233+ );
 234+
 235+ return $params;
221236 }
222237
223238 /**

Status & tagging log