provide TwingleEvent campaign id for instantiation
This commit is contained in:
Marc Michalsky forumZFD 2021-02-04 09:36:26 +01:00
parent d031c82f31
commit aef0297daf
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
3 changed files with 11 additions and 7 deletions

View file

@ -62,9 +62,6 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign {
self::IN self::IN
); );
// Set id
$values_prepared_for_import['id'] = $this->id;
// Create campaign // Create campaign
$result = civicrm_api3('Campaign', 'create', $values_prepared_for_import); $result = civicrm_api3('Campaign', 'create', $values_prepared_for_import);

View file

@ -96,11 +96,17 @@ function _civicrm_api3_twingle_event_Getsingle_spec(array &$spec) {
* @see civicrm_api3_create_success * @see civicrm_api3_create_success
*/ */
function civicrm_api3_twingle_event_Getsingle(array $params): array { function civicrm_api3_twingle_event_Getsingle(array $params): array {
$returnValues = civicrm_api3('TwingleEvent', 'get', $params); $returnValues = civicrm_api3('TwingleEvent', 'get', $params);
$count = $returnValues['count']; $count = $returnValues['count'];
if ($count != 1) { if ($count != 1) {
return civicrm_api3_create_error("Expected one TwingleEvent but found $count"); return civicrm_api3_create_error("Expected one TwingleEvent but found $count");
} }
return civicrm_api3_create_success($returnValues['values'], $params, 'TwingleEvent', 'Getsingle'); return civicrm_api3_create_success(
$returnValues['values'][$returnValues['id']],
$params,
'TwingleEvent',
'Getsingle'
);
} }

View file

@ -256,7 +256,7 @@ function civicrm_api3_twingle_event_Sync(array $params): array {
if ($event_from_twingle['id'] == $event_from_civicrm['event_id']) { if ($event_from_twingle['id'] == $event_from_civicrm['event_id']) {
// instantiate project with values from TwingleEvent.Get // instantiate project with values from TwingleEvent.Get
$event = _instantiateEvent($event_from_civicrm); $event = _instantiateEvent($event_from_civicrm, $event_from_civicrm['id']);
// sync event // sync event
$result = _eventSync($event, $event_from_twingle, $twingleApi, $params); $result = _eventSync($event, $event_from_twingle, $twingleApi, $params);
@ -298,13 +298,14 @@ function civicrm_api3_twingle_event_Sync(array $params): array {
* # Instantiates a TwingleEvent * # Instantiates a TwingleEvent
* *
* @param $values * @param $values
* @param null $id
* *
* @return \CRM_TwingleCampaign_BAO_TwingleEvent * @return \CRM_TwingleCampaign_BAO_TwingleEvent
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
*/ */
function _instantiateEvent($values): CRM_TwingleCampaign_BAO_TwingleEvent { function _instantiateEvent($values, $id = NULL): CRM_TwingleCampaign_BAO_TwingleEvent {
try { try {
return new TwingleEvent($values, $values['id']); return new TwingleEvent($values, $id);
} catch (Exception $e) { } catch (Exception $e) {
throw new CiviCRM_API3_Exception( throw new CiviCRM_API3_Exception(
$e->getMessage(), $e->getMessage(),