diff --git a/api/v3/TwingleEvent/Sync.php b/api/v3/TwingleEvent/Sync.php index 1b163c6..55c3e57 100644 --- a/api/v3/TwingleEvent/Sync.php +++ b/api/v3/TwingleEvent/Sync.php @@ -111,7 +111,7 @@ function civicrm_api3_twingle_event_Sync(array $params): array { Civi::cache('long')->set('twinglecampaign_twingle_api', $twingleApi); } - // If an id or a project_id is given, synchronize only this one campaign + // If an id or a event_id is provided, synchronize only this one campaign if ($params['id'] || $params['event_id']) { // Get project from db via API @@ -166,7 +166,7 @@ function civicrm_api3_twingle_event_Sync(array $params): array { } } - // If no id but an event_id and/or a project_id is given, synchronize all + // If no id but an event_id and/or a project_id is provided, synchronize all // all events or just the events of the given project $result_values = []; @@ -285,7 +285,7 @@ function civicrm_api3_twingle_event_Sync(array $params): array { } } - // Give back results + // Return results if ($errors_occurred > 0) { $errorMessage = ($errors_occurred > 1) ? "$errors_occurred synchronisation processes resulted with an error" diff --git a/api/v3/TwingleProject/Sync.php b/api/v3/TwingleProject/Sync.php index d078169..b313684 100644 --- a/api/v3/TwingleProject/Sync.php +++ b/api/v3/TwingleProject/Sync.php @@ -184,7 +184,7 @@ function civicrm_api3_twingle_project_Sync(array $params): array { // instantiate project with values from TwingleProject.Get $project = new TwingleProject($project_from_civicrm, $id); // push project to Twingle - $result = pushToTwingle($project, $twingleApi, $params); + $result = _pushProjectToTwingle($project, $twingleApi, $params); if ($result['is_error'] != 0) { $errors_occurred++; $result_values[$project->getId()] = @@ -451,7 +451,7 @@ function _projectSync(TwingleProject $project, // If both versions are still synchronized else { - $response[] = $project->getResponse('TwingleProject up to date'); + $response = $project->getResponse('TwingleProject up to date'); return civicrm_api3_create_success( $response, $params, diff --git a/api/v3/TwingleSync/Sync.php b/api/v3/TwingleSync/Sync.php index 2f12e3e..5c6340d 100644 --- a/api/v3/TwingleSync/Sync.php +++ b/api/v3/TwingleSync/Sync.php @@ -67,18 +67,23 @@ function civicrm_api3_twingle_sync_Sync(array $params): array { // Synchronize all TwingleEvent campaigns foreach ($projects as $project) { - if (is_array($project)) { + // If the project is of type 'event', synchronize all its events + if (is_array($project) && $project['project_type'] == 'event') { $_params = $params; $_params['project_id'] = $project['project_id']; + $events = civicrm_api3( + 'TwingleEvent', + 'sync', + $_params + )['values']; $result_values[] = [ 'project' => $project, - 'events' => array_values( - civicrm_api3( - 'TwingleEvent', - 'sync', - $_params - )['values'] - ), + 'events' => array_values($events), + ]; + } + else { + $result_values[] = [ + 'project' => $project ]; } }