👾 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
|
@ -62,7 +62,7 @@ function civicrm_api3_twingle_campaign_Create(array $params): array {
|
|||
$params = array_intersect_key($params, $allowed_params);
|
||||
|
||||
// instantiate TwingleCampaign
|
||||
$campaign = new TwingleCampaign($params, $params['id']);
|
||||
$campaign = new TwingleCampaign($params);
|
||||
|
||||
// Try to create the TwingleCampaign
|
||||
try {
|
||||
|
|
|
@ -33,6 +33,13 @@ function _civicrm_api3_twingle_campaign_Get_spec(array &$spec) {
|
|||
'api.required' => 0,
|
||||
'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'] = [
|
||||
'name' => '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
|
||||
$params['parent_id'] = $project['id'];
|
||||
}
|
||||
elseif (isset($params['parent_id'])) {
|
||||
|
||||
// Include campaign type ot TwingleCampaigns in $params
|
||||
$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
|
||||
if (!empty($campaigns)) {
|
||||
if (!empty($campaigns['values'])) {
|
||||
$custom_field_mapping_reverse =
|
||||
array_flip(Cache::getInstance()->getCustomFieldMapping());
|
||||
|
||||
|
@ -171,7 +180,7 @@ function civicrm_api3_twingle_campaign_Get(array $params): array {
|
|||
$returnValues[$campaign['id']][$key] = $value;
|
||||
}
|
||||
}
|
||||
foreach($returnValues[$campaign['id']] as $key => $value) {
|
||||
foreach ($returnValues[$campaign['id']] as $key => $value) {
|
||||
if ($key != 'twingle_campaign_id' && strpos($key, 'twingle_campaign_') === 0) {
|
||||
$returnValues[$campaign['id']][str_replace('twingle_campaign_', '', $key)]
|
||||
= $value;
|
||||
|
|
|
@ -20,12 +20,19 @@ function _civicrm_api3_twingle_campaign_Sync_spec(array &$spec) {
|
|||
'description' => E::ts('The Twingle Campaign ID'),
|
||||
];
|
||||
$spec['project_id'] = [
|
||||
'name' => 'project_id',
|
||||
'name' => 'parent_project_id',
|
||||
'title' => E::ts('Parent Twingle Project ID'),
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'api.required' => 0,
|
||||
'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 = [];
|
||||
$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
|
||||
foreach ($campaigns['values'] as $campaign) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue