implement test mode for TwingleSync

This commit is contained in:
Marc Michalsky forumZFD 2020-09-30 15:27:55 +02:00
parent 50b0ff7da8
commit f9cbe9db6c
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
3 changed files with 27 additions and 13 deletions

View file

@ -92,15 +92,18 @@ class TwingleProject {
// Create project if it does not exist yet and give back the result
if (!$this->exists()) {
$result = civicrm_api3('Campaign', 'create', $translatedValues);
if (!$is_test) {
$result = civicrm_api3('Campaign', 'create', $translatedValues);
$this->id = $result['id'];
$this->timestamp = $result['last_update'];
return [
'title' => $this->values['title'],
'id' => $this->id,
'project_id' => $this->values['id'],
}
// If this is a test, do not create campaign
else {
'state' => 'created',
];
}
}
else {
}
// Give information back if project already exists
return [
@ -114,14 +117,20 @@ class TwingleProject {
/**
* Update an existing project
*
* If true: don't do any changes
*
* @param bool $is_test
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
public function update() {
public function update(bool $is_test = FALSE) {
// Translate $value keys to custom field names
$translatedValues = $this->translateValues();
$result = civicrm_api3('Campaign', 'create', $translatedValues);
if (!$is_test) {
$result = civicrm_api3('Campaign', 'create', $translatedValues);
return [
'title' => $this->values['title'],
'id' => $this->id,