change createProject() to syncProject() and handle existin projects

This commit is contained in:
Marc Michalsky forumZFD 2020-09-29 08:41:02 +02:00
parent b920185005
commit 8ee0079b37
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9

View file

@ -106,10 +106,23 @@ class TwingleApiCall {
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
* @throws \Exception * @throws \Exception
*/ */
return $project->create(); public function syncProject($values) {
if (is_array($values)) {
$project = new TwingleProject($values);
$result = $project->create();
if (
$result['state'] == 'exists' &&
$values['last_update'] > $project->getTimestamp()
) {
$result = $project->update();
} }
} catch (\Exception $e) {
// TODO: Handle Exception return $result;
} else {
return null;
} }
} }