👾 bug fix: TwingleCampaign cannot find parent campaign
This commit is contained in:
parent
a658190a68
commit
cc6777e206
5 changed files with 36 additions and 9 deletions
|
@ -32,7 +32,7 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
||||||
$this->id = $id ?? NULL;
|
$this->id = $id ?? NULL;
|
||||||
$this->values['campaign_type_id'] = 'twingle_campaign';
|
$this->values['campaign_type_id'] = 'twingle_campaign';
|
||||||
|
|
||||||
if ($this->id) {
|
if (!isset($this->id)) {
|
||||||
$this->update($values);
|
$this->update($values);
|
||||||
$this->getParentProject();
|
$this->getParentProject();
|
||||||
$this->createCid();
|
$this->createCid();
|
||||||
|
@ -341,10 +341,11 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
||||||
*/
|
*/
|
||||||
private
|
private
|
||||||
function update(array $values) {
|
function update(array $values) {
|
||||||
$filter = ExtensionCache::getInstance()->getTemplates()['TwingleCampaign'];
|
$filter = ExtensionCache::getInstance()
|
||||||
|
->getTemplates()['TwingleCampaign']['campaign_data'];
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
if (in_array($key, $filter)) {
|
if (in_array($key, $filter)) {
|
||||||
$this->values[$key] = $values[$key];
|
$this->values[$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign {
|
||||||
$this->id_custom_field = Cache::getInstance()
|
$this->id_custom_field = Cache::getInstance()
|
||||||
->getCustomFieldMapping()['twingle_event_id'];
|
->getCustomFieldMapping()['twingle_event_id'];
|
||||||
|
|
||||||
if (isset($this->values['parent_id'])) {
|
if (!isset($this->values['parent_id'])) {
|
||||||
try {
|
try {
|
||||||
$this->values['parent_id'] = $this->getParentCampaignId();
|
$this->values['parent_id'] = $this->getParentCampaignId();
|
||||||
} catch (CiviCRM_API3_Exception $e) {
|
} catch (CiviCRM_API3_Exception $e) {
|
||||||
|
|
|
@ -62,7 +62,7 @@ function civicrm_api3_twingle_campaign_Create(array $params): array {
|
||||||
$params = array_intersect_key($params, $allowed_params);
|
$params = array_intersect_key($params, $allowed_params);
|
||||||
|
|
||||||
// instantiate TwingleCampaign
|
// instantiate TwingleCampaign
|
||||||
$campaign = new TwingleCampaign($params, $params['id']);
|
$campaign = new TwingleCampaign($params);
|
||||||
|
|
||||||
// Try to create the TwingleCampaign
|
// Try to create the TwingleCampaign
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -33,6 +33,13 @@ function _civicrm_api3_twingle_campaign_Get_spec(array &$spec) {
|
||||||
'api.required' => 0,
|
'api.required' => 0,
|
||||||
'description' => E::ts('Twingle ID of the parent TwingleProject'),
|
'description' => E::ts('Twingle ID of the parent TwingleProject'),
|
||||||
];
|
];
|
||||||
|
$spec['parent_id'] = [
|
||||||
|
'name' => 'parent_id',
|
||||||
|
'title' => E::ts('Parent Project ID'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('ID of the parent TwingleProject'),
|
||||||
|
];
|
||||||
$spec['name'] = [
|
$spec['name'] = [
|
||||||
'name' => 'name',
|
'name' => 'name',
|
||||||
'title' => E::ts('Campaign Name'),
|
'title' => E::ts('Campaign Name'),
|
||||||
|
@ -122,6 +129,8 @@ function civicrm_api3_twingle_campaign_Get(array $params): array {
|
||||||
|
|
||||||
// Include parent TwingleProject id in $params
|
// Include parent TwingleProject id in $params
|
||||||
$params['parent_id'] = $project['id'];
|
$params['parent_id'] = $project['id'];
|
||||||
|
}
|
||||||
|
elseif (isset($params['parent_id'])) {
|
||||||
|
|
||||||
// Include campaign type ot TwingleCampaigns in $params
|
// Include campaign type ot TwingleCampaigns in $params
|
||||||
$params['campaign_type_id'] = $twingle_campaign_campaign_type_id;
|
$params['campaign_type_id'] = $twingle_campaign_campaign_type_id;
|
||||||
|
@ -157,7 +166,7 @@ function civicrm_api3_twingle_campaign_Get(array $params): array {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate custom fields
|
// Translate custom fields
|
||||||
if (!empty($campaigns)) {
|
if (!empty($campaigns['values'])) {
|
||||||
$custom_field_mapping_reverse =
|
$custom_field_mapping_reverse =
|
||||||
array_flip(Cache::getInstance()->getCustomFieldMapping());
|
array_flip(Cache::getInstance()->getCustomFieldMapping());
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,19 @@ function _civicrm_api3_twingle_campaign_Sync_spec(array &$spec) {
|
||||||
'description' => E::ts('The Twingle Campaign ID'),
|
'description' => E::ts('The Twingle Campaign ID'),
|
||||||
];
|
];
|
||||||
$spec['project_id'] = [
|
$spec['project_id'] = [
|
||||||
'name' => 'project_id',
|
'name' => 'parent_project_id',
|
||||||
'title' => E::ts('Parent Twingle Project ID'),
|
'title' => E::ts('Parent Twingle Project ID'),
|
||||||
'type' => CRM_Utils_Type::T_INT,
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
'api.required' => 0,
|
'api.required' => 0,
|
||||||
'description' => E::ts('Twingle ID of the parent TwingleProject'),
|
'description' => E::ts('Twingle ID of the parent TwingleProject'),
|
||||||
];
|
];
|
||||||
|
$spec['parent_id'] = [
|
||||||
|
'name' => 'parent_id',
|
||||||
|
'title' => E::ts('Parent Project ID'),
|
||||||
|
'type' => CRM_Utils_Type::T_INT,
|
||||||
|
'api.required' => 0,
|
||||||
|
'description' => E::ts('ID of the parent TwingleProject'),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,7 +59,17 @@ function civicrm_api3_twingle_campaign_Sync(array $params): array {
|
||||||
$returnValues = [];
|
$returnValues = [];
|
||||||
$errors_occurred = 0;
|
$errors_occurred = 0;
|
||||||
|
|
||||||
if ($campaigns['is_error'] == 0 && $campaigns['count'] > 0) {
|
// Abort if TwingleProject does not have TingleCampaign children
|
||||||
|
if ($campaigns['count'] == 0) {
|
||||||
|
return civicrm_api3_create_success(
|
||||||
|
$returnValues,
|
||||||
|
$params,
|
||||||
|
'TwingleCampaign',
|
||||||
|
'Sync'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($campaigns['is_error'] == 0) {
|
||||||
|
|
||||||
// Instantiate and re-create TwingleCampaigns
|
// Instantiate and re-create TwingleCampaigns
|
||||||
foreach ($campaigns['values'] as $campaign) {
|
foreach ($campaigns['values'] as $campaign) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue