Skip to content

Fix logging endpoint of synchronizations, fix setting last synced #401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Controller/SynchronizationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ public function contracts(int $id): JSONResponse
public function logs(string $uuid): JSONResponse
{
try {
$logs = $this->synchronizationLogMapper->findAll(null, null, ['synchronization_id' => $uuid]);
$synchronization = $this->synchronizationMapper->find($uuid);
$logs = $this->synchronizationLogMapper->findAll(null, null, ['synchronization_id' => $synchronization->getUuid()]);
return new JSONResponse($logs);
} catch (DoesNotExistException $e) {
return new JSONResponse(['error' => 'Logs not found'], 404);
Expand Down
33 changes: 18 additions & 15 deletions lib/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ public function synchronize(
force: $force,
log: $log
);

$result = $processResult['result'];

if ($processResult['targetId'] !== null) {
$synchronizedTargetIds[] = $processResult['targetId'];
}
Expand Down Expand Up @@ -222,6 +222,9 @@ public function synchronize(
);
}

$synchronization->setTargetLastSynced(new DateTime());
$this->synchronizationMapper->update($synchronization);

// Calculate execution time in milliseconds
$executionTime = round((microtime(true) - $startTime) * 1000);
$log->setExecutionTime($executionTime);
Expand Down Expand Up @@ -2056,23 +2059,23 @@ private function xmlToArray(\SimpleXMLElement $xml): array
* @param bool $isTest Whether this is a test run
* @param bool $force Whether to force synchronization regardless of changes
* @param SynchronizationLog $log The synchronization log
*
*
* @return array Contains updated result data and the targetId ['result' => array, 'targetId' => string|null]
*/
private function processSynchronizationObject(
Synchronization $synchronization,
array $object,
array $result,
bool $isTest,
bool $force,
Synchronization $synchronization,
array $object,
array $result,
bool $isTest,
bool $force,
SynchronizationLog $log
): array {
// We can only deal with arrays (based on the source empty values or string might be returned)
if (is_array($object) === false) {
$result['objects']['invalid']++;
return ['result' => $result, 'targetId' => null];
}

$conditionsObject = $this->encodeArrayKeys($object, '.', '.');

// Check if object adheres to conditions.
Expand All @@ -2088,7 +2091,7 @@ private function processSynchronizationObject(

// Get the synchronization contract for this object
$synchronizationContract = $this->synchronizationContractMapper->findSyncContractByOriginId(
synchronizationId: $synchronization->id,
synchronizationId: $synchronization->id,
originId: $originId
);

Expand All @@ -2108,9 +2111,9 @@ private function processSynchronizationObject(
);

$synchronizationContract = $synchronizationContractResult['contract'];
$result['contracts'][] = isset($synchronizationContractResult['contract']['uuid']) ?
$result['contracts'][] = isset($synchronizationContractResult['contract']['uuid']) ?
$synchronizationContractResult['contract']['uuid'] : null;
$result['logs'][] = isset($synchronizationContractResult['log']['uuid']) ?
$result['logs'][] = isset($synchronizationContractResult['log']['uuid']) ?
$synchronizationContractResult['log']['uuid'] : null;
$result['objects']['created']++;
} else {
Expand All @@ -2125,15 +2128,15 @@ private function processSynchronizationObject(
);

$synchronizationContract = $synchronizationContractResult['contract'];
$result['contracts'][] = isset($synchronizationContractResult['contract']['uuid']) === true ?
$result['contracts'][] = isset($synchronizationContractResult['contract']['uuid']) === true ?
$synchronizationContractResult['contract']['uuid'] : null;
$result['logs'][] = isset($synchronizationContractResult['log']['uuid']) === true ?
$result['logs'][] = isset($synchronizationContractResult['log']['uuid']) === true ?
$synchronizationContractResult['log']['uuid'] : null;
$result['objects']['updated']++;
}

$targetId = $synchronizationContract['targetId'] ?? null;

return ['result' => $result, 'targetId' => $targetId];
}

Expand Down
Loading