several fixes

This commit is contained in:
Marc Michalsky forumZFD 2020-10-29 11:29:53 +01:00
parent 636929214d
commit 52a3a1e978
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
5 changed files with 15 additions and 57 deletions

View file

@ -222,31 +222,12 @@ class TwingleProject {
* @param array $values * @param array $values
* Array with values to update * Array with values to update
* *
* @param string|null $origin
* Origin of the array. It can be one of two constants:
* TwingleProject::TWINGLE|CIVICRM
*
* @throws Exception * @throws Exception
*/ */
public function update(array $values, string $origin = NULL) { public function update(array $values) {
if ($origin == self::CIVICRM) {
// Set project id
$this->id = $values['id'];
// Translate custom field names
self::translateCustomFields($values, self::OUT);
// Format project values
self::formatValues($values, self::OUT);
// Separate options from project values
self::separateOptions($values);
}
// Update project options // Update project options
$this->options->update($values['options'], $origin); $this->options->update($values['options']);
// Unset options array in project values // Unset options array in project values
unset($values['options']); unset($values['options']);
@ -344,6 +325,7 @@ class TwingleProject {
]); ]);
if ($result['count'] > 1) { if ($result['count'] > 1) {
// TODO: abort loop if function fails
TwingleProject::handleDuplicates($result); TwingleProject::handleDuplicates($result);
} }
else { else {
@ -370,12 +352,9 @@ class TwingleProject {
// Separate options from project values // Separate options from project values
self::separateOptions($values); self::separateOptions($values);
// Translate keys from Twingle format to CiviCRM format
self::translateKeys($values, self::IN);
// Set attributes to the values of the existing TwingleProject campaign // Set attributes to the values of the existing TwingleProject campaign
// to reflect the state of the actual campaign in the database // to reflect the state of the actual campaign in the database
$this->update($values, self::TWINGLE); $this->update($values);
return TRUE; return TRUE;
} }
@ -605,6 +584,7 @@ class TwingleProject {
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
if (key_exists($key, $options_template)) { if (key_exists($key, $options_template)) {
$options[$key] = $value; $options[$key] = $value;
unset($values[$key]);
} }
} }
@ -750,7 +730,7 @@ class TwingleProject {
* @return int|null * @return int|null
*/ */
public function lastUpdate() { public function lastUpdate() {
$lastProjectUpdate = self::getTimestamp($this->values['last_modified_date']); $lastProjectUpdate = self::getTimestamp($this->values['last_update']);
$lastOptionsUpdate = self::getTimestamp($this->options->lastUpdate()); $lastOptionsUpdate = self::getTimestamp($this->options->lastUpdate());
$lastUpdate = $lastProjectUpdate > $lastOptionsUpdate $lastUpdate = $lastProjectUpdate > $lastOptionsUpdate
? $lastProjectUpdate ? $lastProjectUpdate

View file

@ -55,20 +55,9 @@ class TwingleProjectOptions {
* @param array $options * @param array $options
* Array with values to update * Array with values to update
* *
* @param string|null $origin
* Origin of the array. It can be one of two constants:
* TwingleProject::TWINGLE|CIVICRM
*
* @throws Exception * @throws Exception
*/ */
public function update(array $options, string $origin = NULL) { public function update(array $options) {
if ($origin == TwingleProject::CIVICRM) {
self::formatValues($options, TwingleProject::OUT);
}
// Unset project options id
unset($options['id']);
// Update values // Update values
$this->values = array_merge($this->values, $options); $this->values = array_merge($this->values, $options);
@ -248,7 +237,7 @@ class TwingleProjectOptions {
} }
public function lastUpdate() { public function lastUpdate() {
return $this->values['last_modified_date']; return $this->values['last_update'];
} }
} }

View file

@ -165,19 +165,6 @@
"is_view": 0, "is_view": 0,
"weight": 5 "weight": 5
}, },
"twingle_project_last_update": {
"custom_group_id": "Twingle_Project_Information",
"label": "Twingle Project Last update",
"name": "twingle_project_last_update",
"is_required": 0,
"is_searchable": 1,
"data_type": "String",
"html_type": "Text",
"text_length": 32,
"is_active": 1,
"is_view": 1,
"weight": 5
},
"twingle_project_widget": { "twingle_project_widget": {
"custom_group_id": "Twingle_Project_Embed_Codes", "custom_group_id": "Twingle_Project_Embed_Codes",
"label": "Twingle Project Widget", "label": "Twingle Project Widget",

View file

@ -13,7 +13,6 @@
"event": [ "event": [
], ],
"project_options": { "project_options": {
"id": 2237,
"has_confirmation_mail": false, "has_confirmation_mail": false,
"has_confirmation_mail_api": false, "has_confirmation_mail_api": false,
"has_donation_receipt": true, "has_donation_receipt": true,
@ -34,7 +33,7 @@
"design_button_font_color": "", "design_button_font_color": "",
"design_button_font_color_light": "", "design_button_font_color_light": "",
"image": "", "image": "",
"bcc_email_address": "demo-zfd@twingle.de", "bcc_email_address": "",
"donation_value_min": 5, "donation_value_min": 5,
"donation_value_max": 500, "donation_value_max": 500,
"donation_value_default": 50, "donation_value_default": 50,

View file

@ -206,9 +206,12 @@ class TwingleApiCall {
// If Twingle's version of the project is newer than the CiviCRM // If Twingle's version of the project is newer than the CiviCRM
// TwingleProject campaign update the campaign // TwingleProject campaign update the campaign
if ($values['last_update'] > $project->lastUpdate()) { $lastUpdate = $values['last_update'] > $values['options']['last_update']
? $values['last_update']
: $values['options']['last_update'];
if ($lastUpdate > $project->lastUpdate()) {
try { try {
$project->update($values, TwingleProject::TWINGLE); $project->update($values);
$result = $project->create(); $result = $project->create();
$result['status'] = $result['status'] == 'TwingleProject created' $result['status'] = $result['status'] == 'TwingleProject created'
? 'TwingleProject updated' ? 'TwingleProject updated'
@ -226,7 +229,7 @@ class TwingleApiCall {
} }
// If the CiviCRM TwingleProject campaign was changed, update the project // If the CiviCRM TwingleProject campaign was changed, update the project
// on Twingle's side // on Twingle's side
elseif ($values['last_update'] < $project->lastUpdate()) { elseif ($lastUpdate < $project->lastUpdate()) {
// If this is a test do not make database changes // If this is a test do not make database changes
if ($is_test) { if ($is_test) {
$result = $project->getResponse( $result = $project->getResponse(