code cleanup

This commit is contained in:
Marc Michalsky forumZFD 2021-02-11 18:35:35 +01:00
parent 027b7a40cd
commit dc2c26abb4
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
3 changed files with 15 additions and 11 deletions

View file

@ -102,9 +102,11 @@ function civicrm_api3_twingle_event_Getsingle(array $params): array {
_civicrm_api3_twingle_event_Getsingle_spec($allowed_params); _civicrm_api3_twingle_event_Getsingle_spec($allowed_params);
$params = array_intersect_key($params, $allowed_params); $params = array_intersect_key($params, $allowed_params);
// Get TwingleEvent by provided parameters
$returnValues = civicrm_api3('TwingleEvent', 'get', $params); $returnValues = civicrm_api3('TwingleEvent', 'get', $params);
$count = $returnValues['count']; $count = $returnValues['count'];
// Check whether only a single TwingleEvent is found
if ($count != 1) { if ($count != 1) {
return civicrm_api3_create_error("Expected one TwingleEvent but found $count"); return civicrm_api3_create_error("Expected one TwingleEvent but found $count");
} }

View file

@ -92,7 +92,7 @@ function _civicrm_api3_twingle_project_Getsingle_spec(array &$spec) {
} }
/** /**
* TwingleProject.Getsingle API * # TwingleProject.Getsingle API
* *
* @param array $params * @param array $params
* *
@ -109,9 +109,11 @@ function civicrm_api3_twingle_project_Getsingle(array $params): array {
_civicrm_api3_twingle_project_Getsingle_spec($allowed_params); _civicrm_api3_twingle_project_Getsingle_spec($allowed_params);
$params = array_intersect_key($params, $allowed_params); $params = array_intersect_key($params, $allowed_params);
// Get TwingleProject by provided parameters
$returnValues = civicrm_api3('TwingleProject', 'get', $params); $returnValues = civicrm_api3('TwingleProject', 'get', $params);
$count = $returnValues['count']; $count = $returnValues['count'];
// Check whether only a single TwingleProject is found
if ($count != 1) { if ($count != 1) {
return civicrm_api3_create_error( return civicrm_api3_create_error(
"Expected one TwingleProject but found $count" "Expected one TwingleProject but found $count"

View file

@ -174,7 +174,7 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
} }
// Push missing projects to Twingle // Push missing projects to Twingle
$result_values = []; $returnValues = [];
foreach ($projects_from_civicrm['values'] as $project_from_civicrm) { foreach ($projects_from_civicrm['values'] as $project_from_civicrm) {
if (!in_array($project_from_civicrm['project_id'], if (!in_array($project_from_civicrm['project_id'],
array_column($projects_from_twingle, 'id'))) { array_column($projects_from_twingle, 'id'))) {
@ -187,11 +187,11 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
$result = _pushProjectToTwingle($project, $twingleApi, $params); $result = _pushProjectToTwingle($project, $twingleApi, $params);
if ($result['is_error'] != 0) { if ($result['is_error'] != 0) {
$errors_occurred++; $errors_occurred++;
$result_values[$project->getId()] = $returnValues[$project->getId()] =
$project->getResponse($result['error_message']); $project->getResponse($result['error_message']);
} }
else { else {
$result_values[$project->getId()] = $result['values']; $returnValues[$project->getId()] = $result['values'];
} }
} }
} }
@ -210,12 +210,12 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
// If this is a test, do not make db changes // If this is a test, do not make db changes
if ($params['is_test']) { if ($params['is_test']) {
$result_values[$project->getId()] = $returnValues[$project->getId()] =
$project->getResponse('Ready to create TwingleProject'); $project->getResponse('Ready to create TwingleProject');
} }
$project->create(TRUE); $project->create(TRUE);
$result_values[$project->getId()] = $returnValues[$project->getId()] =
$project->getResponse('TwingleProject created'); $project->getResponse('TwingleProject created');
} catch (Exception $e) { } catch (Exception $e) {
$errors_occurred++; $errors_occurred++;
@ -225,7 +225,7 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
$e->getMessage(), $e->getMessage(),
$project->getResponse() $project->getResponse()
); );
$result_values[$project->getId()] = $project->getResponse( $returnValues[$project->getId()] = $project->getResponse(
"TwingleProject could not get created: " . $e->getMessage() "TwingleProject could not get created: " . $e->getMessage()
); );
} }
@ -248,11 +248,11 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
$result = _projectSync($project, $project_from_twingle, $twingleApi, $params); $result = _projectSync($project, $project_from_twingle, $twingleApi, $params);
if ($result['is_error'] != 0) { if ($result['is_error'] != 0) {
$errors_occurred++; $errors_occurred++;
$result_values[$project->getId()] = $returnValues[$project->getId()] =
$project->getResponse($result['error_message']); $project->getResponse($result['error_message']);
} }
else { else {
$result_values[$project->getId()] = $result['values']; $returnValues[$project->getId()] = $result['values'];
} }
break; break;
} }
@ -266,12 +266,12 @@ function civicrm_api3_twingle_project_Sync(array $params): array {
: "1 synchronisation process resulted with an error"; : "1 synchronisation process resulted with an error";
return civicrm_api3_create_error( return civicrm_api3_create_error(
$errorMessage, $errorMessage,
$result_values $returnValues
); );
} }
else { else {
return civicrm_api3_create_success( return civicrm_api3_create_success(
$result_values, $returnValues,
$params, $params,
'TwingleProject', 'TwingleProject',
'Sync' 'Sync'