diff --git a/CRM/TwingleCampaign/BAO/TwingleEvent.php b/CRM/TwingleCampaign/BAO/TwingleEvent.php index af22ef3..e8aaba8 100644 --- a/CRM/TwingleCampaign/BAO/TwingleEvent.php +++ b/CRM/TwingleCampaign/BAO/TwingleEvent.php @@ -35,93 +35,6 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign { } - /** - * Synchronizes events between Twingle and CiviCRM (only Twingle -> CiviCRM) - * based on the timestamp. - * - * @param array $values - * @param bool $is_test - * If TRUE, don't do any changes - * - * @return array|null - * Returns a response array that contains title, id, event_id, project_id - * and status or NULL if $values is not an array - * - * @throws \Exception - */ - public static function sync( - array $values, - bool $is_test = FALSE - ): ?array { - - // If $values is an array - if (is_array($values)) { - - // Instantiate TwingleEvent - try { - $event = new self($values); - } catch (Exception $e) { - $errorMessage = $e->getMessage(); - Civi::log()->error(E::LONG_NAME . - " failed to instantiate TwingleEvent: $errorMessage" - ); - throw new Exception( - "Failed to instantiate TwingleEvent: $errorMessage" - ); - } - - // Check if the TwingleEvent campaign already exists - if (!$event->exists()) { - - // ... if not, create event - try { - $result = $event->create($is_test); - } catch (Exception $e) { - $errorMessage = $e->getMessage(); - Civi::log()->error(E::LONG_NAME . - " could not create campaign from TwingleEvent: $errorMessage" - ); - throw new Exception( - "Could not create campaign from TwingleEvent: $errorMessage" - ); - } - } - else { - $result = $event->getResponse('TwingleEvent exists'); - - // If Twingle's version of the event is newer than the CiviCRM - // TwingleEvent campaign, update the campaign - if ($values['updated_at'] > $event->lastUpdate()) { - try { - $event->update($values); - $result = $event->create($is_test); - $result['status'] = $result['status'] == 'TwingleEvent created' - ? 'TwingleEvent updated' - : 'TwingleEvent Update failed'; - } catch (Exception $e) { - $errorMessage = $e->getMessage(); - Civi::log()->error(E::LONG_NAME . - " could not update TwingleEvent campaign: $errorMessage" - ); - throw new Exception( - "Could not update TwingleEvent campaign: $errorMessage" - ); - } - } - elseif ($result['status'] == 'TwingleEvent exists') { - $result = $event->getResponse('TwingleEvent up to date'); - } - } - - // Return a response of the synchronization - return $result; - } - else { - return NULL; - } - } - - /** * Create the Event as a campaign in CiviCRM if it does not exist *