👾 bug fix: project id

This commit is contained in:
Marc Michalsky forumZFD 2021-04-12 11:47:43 +02:00
parent 1954f90f79
commit 4bcc4cf1fb
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
2 changed files with 12 additions and 3 deletions

View file

@ -41,6 +41,15 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
* CiviCRM Campaign id
*/
public function __construct(array $values = [], int $id = NULL) {
// If the $values originally come from the TwingleProject.get API, they
// contain the internal CiviCRM id as 'id' and the external Twingle id as
// 'project_id'. In this case 'id' gets replaced with 'project_id'
if (isset($values['project_id'])) {
$values['id'] = $values['project_id'];
unset($values['project_id']);
}
parent::__construct($values, $id);
$this->prefix = 'twingle_project_';

View file

@ -104,7 +104,6 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
// instantiate project from CiviCRM
$id = $result['id'];
unset($result['id']);
$project = new TwingleProject($result, $id);
// Synchronize projects
@ -232,9 +231,10 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
foreach ($projects_from_twingle as $project_from_twingle) {
if ($project_from_twingle['id'] == $project_from_civicrm['project_id']) {
// store campaign id in $id
// store campaign id in $id and replace it with project_id
$id = $project_from_civicrm['id'];
unset($project_from_civicrm['id']);
$project_from_civicrm['id'] = $project_from_civicrm['project_id'];
unset($project_from_civicrm['project_id']);
// instantiate project with values from TwingleProject.Get
$project = new TwingleProject($project_from_civicrm, $id);