remove sync() method from TwingleEvent
the sync now takes place in the TwingleEvent.sync api
This commit is contained in:
parent
dc3c1aba5b
commit
68f187c03a
1 changed files with 0 additions and 87 deletions
|
@ -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
|
* Create the Event as a campaign in CiviCRM if it does not exist
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue