👾 bug fix: wrong parent TwingleProject id's
This commit is contained in:
parent
e23e0d7e8d
commit
f059abf5a8
3 changed files with 20 additions and 18 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
use CRM_TwingleCampaign_Utils_ExtensionCache as ExtensionCache;
|
||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||
use CRM_TwingleCampaign_Exceptions_TwingleCampaignException as TwingleCampaignException;
|
||||
|
||||
class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
||||
|
||||
|
@ -23,6 +24,7 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
|||
* @param array $values
|
||||
*
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
* @throws \CRM_TwingleCampaign_Exceptions_TwingleCampaignException
|
||||
*/
|
||||
public function __construct(array $values = []) {
|
||||
|
||||
|
@ -86,6 +88,7 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
|||
* deleted.
|
||||
*
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
* @throws \CRM_TwingleCampaign_Exceptions_TwingleCampaignException
|
||||
*/
|
||||
private function getParentProject(): void {
|
||||
|
||||
|
@ -96,8 +99,7 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
|||
|
||||
// Determine the parent project id by looping through the campaign tree
|
||||
// until the parent campaign type is a TwingleProject
|
||||
$parent_id = $this->values['parent_id'];
|
||||
$parent_id = $parent_id ?? civicrm_api3(
|
||||
$parent_id = $this->values['parent_id'] ?? civicrm_api3(
|
||||
'TwingleCampaign',
|
||||
'getsingle',
|
||||
['id' => $this->id]
|
||||
|
@ -117,7 +119,7 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
|||
}
|
||||
|
||||
$parent_campaign_type_id = $parent_campaign['campaign_type_id'];
|
||||
if (isset($parent_campaign['parent_id'])) {
|
||||
if ($parent_campaign_type_id != $twingle_project_campaign_type_id && isset($parent_campaign['parent_id'])) {
|
||||
$parent_id = $parent_campaign['parent_id'];
|
||||
}
|
||||
else {
|
||||
|
@ -167,7 +169,7 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
|||
' could not determine parent TwingleProject URL.',
|
||||
$this->getResponse()
|
||||
);
|
||||
$this->delete();
|
||||
throw new TwingleCampaignException('Parent project URL missing');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +182,7 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
|||
ts('No parent TwingleProject found'),
|
||||
'alert'
|
||||
);
|
||||
$this->delete();
|
||||
throw new TwingleCampaignException('No parent TwingleProject found');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,7 +290,7 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
|
|||
} catch (CiviCRM_API3_Exception $e) {
|
||||
Civi::log()->error(
|
||||
E::LONG_NAME .
|
||||
' could delete TwingleCampaign: ' .
|
||||
' could not delete TwingleCampaign: ' .
|
||||
$e->getMessage(),
|
||||
$this->getResponse()
|
||||
);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* A simple custom exception that indicates a problem with the TwingleCampaign class
|
||||
*/
|
||||
class CRM_TwingleCampaign_Exceptions_TwingleCampaignException extends Exception {
|
||||
|
||||
}
|
|
@ -61,11 +61,10 @@ function civicrm_api3_twingle_campaign_Create(array $params): array {
|
|||
_civicrm_api3_twingle_campaign_Create_spec($allowed_params);
|
||||
$params = array_intersect_key($params, $allowed_params);
|
||||
|
||||
try {
|
||||
// instantiate TwingleCampaign
|
||||
$campaign = new TwingleCampaign($params);
|
||||
|
||||
// Try to create the TwingleCampaign
|
||||
try {
|
||||
// try to create the TwingleCampaign
|
||||
$campaign->create(TRUE);
|
||||
return civicrm_api3_create_success(
|
||||
$campaign->getResponse('TwingleCampaign created'),
|
||||
|
@ -74,15 +73,8 @@ function civicrm_api3_twingle_campaign_Create(array $params): array {
|
|||
'Create'
|
||||
);
|
||||
} catch(Exception $e){
|
||||
Civi::log()->error(
|
||||
E::LONG_NAME .
|
||||
' could not create TwingleCampaign: ' .
|
||||
$e->getMessage(),
|
||||
$campaign->getResponse()
|
||||
);
|
||||
return civicrm_api3_create_error(
|
||||
'Could not create TwingleCampaign: ' . $e->getMessage(),
|
||||
$campaign->getResponse()
|
||||
'Could not create TwingleCampaign: ' . $e->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue