diff --git a/lib/Service/SynchronizationService.php b/lib/Service/SynchronizationService.php index 3acc7d7..920ec6e 100644 --- a/lib/Service/SynchronizationService.php +++ b/lib/Service/SynchronizationService.php @@ -83,6 +83,9 @@ public function __construct( */ public function synchronize(Synchronization $synchronization, ?bool $isTest = false): array { + if (empty($synchronization->getSourceId()) === true) { + throw new Exception('sourceId of synchronziation cannot be empty. Canceling synchronization..'); + } $objectList = $this->getAllObjectsFromSource(synchronization: $synchronization, isTest: $isTest); @@ -151,7 +154,7 @@ private function getOriginId(Synchronization $synchronization, array $object): i $sourceConfig = $synchronization->getSourceConfig(); // Check if a custom ID position is defined in the source configuration - if (isset($sourceConfig['idPosition']) === true) { + if (isset($sourceConfig['idPosition']) === true && empty($sourceConfig['idPosition']) === false) { // Override default with custom ID position from config $originIdPosition = $sourceConfig['idPosition']; } @@ -391,19 +394,21 @@ public function getAllObjectsFromApi(Synchronization $synchronization, ?bool $is // Current page is 2 because the first call made above is page 1. $currentPage = 2; - $usedNextEndpoint = false; + $useNextEndpoint = false; + if (array_key_exists('next', $body)) { + $useNextEndpoint = true; + } // Continue making API calls if there are more pages from 'next' the response body or if paginationQuery is set - while($nextEndpoint = $this->getNextEndpoint(body: $body, url: $source->getLocation(), sourceConfig: $sourceConfig, currentPage: $currentPage)) { - $usedNextEndpoint = true; + while($useNextEndpoint === true && $nextEndpoint = $this->getNextEndpoint(body: $body, url: $source->getLocation(), sourceConfig: $sourceConfig, currentPage: $currentPage)) { // Do not pass $config here becuase it overwrites the query attached to nextEndpoint $response = $this->callService->call(source: $source, endpoint: $nextEndpoint)->getResponse(); $body = json_decode($response['body'], true); $objects = array_merge($objects, $this->getAllObjectsFromArray($body, $synchronization)); } - if ($usedNextEndpoint === false) { + if ($useNextEndpoint === false) { do { $config = $this->getNextPage(config: $config, sourceConfig: $sourceConfig, currentPage: $currentPage); $response = $this->callService->call(source: $source, endpoint: $endpoint, method: 'GET', config: $config)->getResponse(); @@ -523,7 +528,6 @@ public function getAllObjectsFromArray(array $array, Synchronization $synchroniz */ public function getNextlinkFromCall(array $body): ?string { - // Check if the 'next' key exists in the response body return $body['next'] ?? null; } } diff --git a/src/services/getValidISOstring.js b/src/services/getValidISOstring.js index 34e937a..231912e 100644 --- a/src/services/getValidISOstring.js +++ b/src/services/getValidISOstring.js @@ -1,6 +1,8 @@ /** * Converts a given date string or Date object to a valid ISO string. * + * this function can double as a validator for ISO / date strings + * * If the dateString is valid it will return the ISO string, * if it is not a valid dateString it will return null. * diff --git a/src/views/Job/JobDetails.vue b/src/views/Job/JobDetails.vue index be8e8dc..8797f68 100644 --- a/src/views/Job/JobDetails.vue +++ b/src/views/Job/JobDetails.vue @@ -90,13 +90,13 @@ import { jobStore, navigationStore, logStore } from '../../store/store.js'
- {{ new Date(jobStore.jobItem.nextRun).toLocaleString() || 'N/A' }} + {{ getValidISOstring(jobStore.jobItem.nextRun) ? new Date(jobStore.jobItem.nextRun).toLocaleString() : 'N/A' }}
- {{ new Date(jobStore.jobItem.lastRun).toLocaleString() || 'N/A' }} + {{ getValidISOstring(jobStore.jobItem.lastRun) ? new Date(jobStore.jobItem.lastRun).toLocaleString() : 'N/A' }}