code cleanup

This commit is contained in:
Marc Michalsky forumZFD 2021-02-08 14:02:04 +01:00
parent 2a1952313e
commit 034476ab65
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
3 changed files with 34 additions and 20 deletions

View file

@ -11,6 +11,7 @@
"last_update" "last_update"
], ],
"project_embed_data": [ "project_embed_data": [
"page",
"widget", "widget",
"form", "form",
"form-single", "form-single",
@ -49,5 +50,11 @@
"eventall", "eventall",
"eventlist", "eventlist",
"eventeditcreate" "eventeditcreate"
],
"TwingleCampaign": [
"id",
"parent_id",
"name",
"title"
] ]
} }

View file

@ -88,9 +88,6 @@ function _civicrm_api3_twingle_project_Create_spec(array &$spec) {
*/ */
function civicrm_api3_twingle_project_Create($params): array { function civicrm_api3_twingle_project_Create($params): array {
// For logging purpose
$extensionName = E::LONG_NAME;
// instantiate project // instantiate project
$project = new TwingleProject($params, 'TWINGLE'); $project = new TwingleProject($params, 'TWINGLE');
@ -104,13 +101,14 @@ function civicrm_api3_twingle_project_Create($params): array {
'Create' 'Create'
); );
} catch(Exception $e){ } catch(Exception $e){
$errorMessage = $e->getMessage();
Civi::log()->error( Civi::log()->error(
"$extensionName could not create TwingleProject: $errorMessage", E::LONG_NAME .
' could not create TwingleProject: ' .
$e->getMessage(),
$project->getResponse() $project->getResponse()
); );
return civicrm_api3_create_error( return civicrm_api3_create_error(
"Could not create TwingleProject: $errorMessage", 'Could not create TwingleProject: ' . $e->getMessage(),
$project->getResponse() $project->getResponse()
); );
} }

View file

@ -48,20 +48,22 @@ function _civicrm_api3_twingle_project_Sync_spec(array &$spec) {
/** /**
* # TwingleProject.Sync API * # TwingleProject.Sync API
* *
* Synchronize one ore more campaigns of the type TwingleProject between CiviCRM * Synchronize one ore more campaigns of the type TwingleProject between
* CiviCRM
* and Twingle. * and Twingle.
* *
* * If you provide an **id** or **project_id** parameter, *only one project* will * * If you provide an **id** or **project_id** parameter, *only one project*
* be synchronized. * will be synchronized.
* *
* * If you provide no **id** or **project_id** parameter, *all projects* will be * * If you provide no **id** or **project_id** parameter, *all projects* will
* synchronized. * be synchronized.
* *
* @param array $params * @param array $params
* *
* @return array * @return array
* API result descriptor * API result descriptor
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
* @throws \Exception
* @see civicrm_api3_create_success * @see civicrm_api3_create_success
*/ */
function civicrm_api3_twingle_project_Sync(array $params): array { function civicrm_api3_twingle_project_Sync(array $params): array {
@ -195,13 +197,18 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
array_column($projects_from_civicrm['values'], 'project_id'))) { array_column($projects_from_civicrm['values'], 'project_id'))) {
$project = new TwingleProject($project_from_twingle); $project = new TwingleProject($project_from_twingle);
// If this is a test, do not make db changes
if ($params['is_test']) {
$result_values[$project->getId()] =
$project->getResponse('Ready to create TwingleProject');
}
try { try {
// Get embed data
$project->setEmbedData(
$twingleApi->getProjectEmbedData($project->getProjectId())
);
// If this is a test, do not make db changes
if ($params['is_test']) {
$result_values[$project->getId()] =
$project->getResponse('Ready to create TwingleProject');
}
$project->create(TRUE); $project->create(TRUE);
$result_values[$project->getId()] = $result_values[$project->getId()] =
$project->getResponse('TwingleProject created'); $project->getResponse('TwingleProject created');
@ -247,7 +254,7 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
} }
} }
// Give back results // Return results
if ($errors_occurred > 0) { if ($errors_occurred > 0) {
$errorMessage = ($errors_occurred > 1) $errorMessage = ($errors_occurred > 1)
? "$errors_occurred synchronisation processes resulted with an error" ? "$errors_occurred synchronisation processes resulted with an error"
@ -300,8 +307,9 @@ function _updateProjectLocally(array $project_from_twingle,
} }
// ... else, update local TwingleProject campaign // ... else, update local TwingleProject campaign
$project->create(TRUE); $project->create(TRUE);
$response[] = $project->getResponse('TwingleProject updated successfully');
return civicrm_api3_create_success( return civicrm_api3_create_success(
$project->getResponse('TwingleProject updated successfully'), $response,
$params, $params,
'TwingleProject', 'TwingleProject',
'Sync' 'Sync'
@ -371,8 +379,9 @@ function _pushProjectToTwingle(TwingleProject $project,
); );
// Create updated campaign // Create updated campaign
$project->create(TRUE); $project->create(TRUE);
$response[] = $project->getResponse('TwingleProject pushed to Twingle');
return civicrm_api3_create_success( return civicrm_api3_create_success(
$project->getResponse('TwingleProject pushed to Twingle'), $response,
$params, $params,
'TwingleProject', 'TwingleProject',
'Sync' 'Sync'