Skip to content

Commit f112f20

Browse files
authored
Merge pull request #401 from ConductionNL/hotfix/synchronization-logs
Fix logging endpoint of synchronizations, fix setting last synced
2 parents c8dcc39 + 20a35be commit f112f20

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

lib/Controller/SynchronizationsController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ public function contracts(int $id): JSONResponse
209209
public function logs(string $uuid): JSONResponse
210210
{
211211
try {
212-
$logs = $this->synchronizationLogMapper->findAll(null, null, ['synchronization_id' => $uuid]);
212+
$synchronization = $this->synchronizationMapper->find($uuid);
213+
$logs = $this->synchronizationLogMapper->findAll(null, null, ['synchronization_id' => $synchronization->getUuid()]);
213214
return new JSONResponse($logs);
214215
} catch (DoesNotExistException $e) {
215216
return new JSONResponse(['error' => 'Logs not found'], 404);

lib/Service/SynchronizationService.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ public function synchronize(
188188
force: $force,
189189
log: $log
190190
);
191-
191+
192192
$result = $processResult['result'];
193-
193+
194194
if ($processResult['targetId'] !== null) {
195195
$synchronizedTargetIds[] = $processResult['targetId'];
196196
}
@@ -222,6 +222,9 @@ public function synchronize(
222222
);
223223
}
224224

225+
$synchronization->setTargetLastSynced(new DateTime());
226+
$this->synchronizationMapper->update($synchronization);
227+
225228
// Calculate execution time in milliseconds
226229
$executionTime = round((microtime(true) - $startTime) * 1000);
227230
$log->setExecutionTime($executionTime);
@@ -2056,23 +2059,23 @@ private function xmlToArray(\SimpleXMLElement $xml): array
20562059
* @param bool $isTest Whether this is a test run
20572060
* @param bool $force Whether to force synchronization regardless of changes
20582061
* @param SynchronizationLog $log The synchronization log
2059-
*
2062+
*
20602063
* @return array Contains updated result data and the targetId ['result' => array, 'targetId' => string|null]
20612064
*/
20622065
private function processSynchronizationObject(
2063-
Synchronization $synchronization,
2064-
array $object,
2065-
array $result,
2066-
bool $isTest,
2067-
bool $force,
2066+
Synchronization $synchronization,
2067+
array $object,
2068+
array $result,
2069+
bool $isTest,
2070+
bool $force,
20682071
SynchronizationLog $log
20692072
): array {
20702073
// We can only deal with arrays (based on the source empty values or string might be returned)
20712074
if (is_array($object) === false) {
20722075
$result['objects']['invalid']++;
20732076
return ['result' => $result, 'targetId' => null];
20742077
}
2075-
2078+
20762079
$conditionsObject = $this->encodeArrayKeys($object, '.', '.');
20772080

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

20892092
// Get the synchronization contract for this object
20902093
$synchronizationContract = $this->synchronizationContractMapper->findSyncContractByOriginId(
2091-
synchronizationId: $synchronization->id,
2094+
synchronizationId: $synchronization->id,
20922095
originId: $originId
20932096
);
20942097

@@ -2108,9 +2111,9 @@ private function processSynchronizationObject(
21082111
);
21092112

21102113
$synchronizationContract = $synchronizationContractResult['contract'];
2111-
$result['contracts'][] = isset($synchronizationContractResult['contract']['uuid']) ?
2114+
$result['contracts'][] = isset($synchronizationContractResult['contract']['uuid']) ?
21122115
$synchronizationContractResult['contract']['uuid'] : null;
2113-
$result['logs'][] = isset($synchronizationContractResult['log']['uuid']) ?
2116+
$result['logs'][] = isset($synchronizationContractResult['log']['uuid']) ?
21142117
$synchronizationContractResult['log']['uuid'] : null;
21152118
$result['objects']['created']++;
21162119
} else {
@@ -2125,15 +2128,15 @@ private function processSynchronizationObject(
21252128
);
21262129

21272130
$synchronizationContract = $synchronizationContractResult['contract'];
2128-
$result['contracts'][] = isset($synchronizationContractResult['contract']['uuid']) === true ?
2131+
$result['contracts'][] = isset($synchronizationContractResult['contract']['uuid']) === true ?
21292132
$synchronizationContractResult['contract']['uuid'] : null;
2130-
$result['logs'][] = isset($synchronizationContractResult['log']['uuid']) === true ?
2133+
$result['logs'][] = isset($synchronizationContractResult['log']['uuid']) === true ?
21312134
$synchronizationContractResult['log']['uuid'] : null;
21322135
$result['objects']['updated']++;
21332136
}
21342137

21352138
$targetId = $synchronizationContract['targetId'] ?? null;
2136-
2139+
21372140
return ['result' => $result, 'targetId' => $targetId];
21382141
}
21392142

0 commit comments

Comments
 (0)