Updated ogrepo sync funcionality
testing/ogcore-api/pipeline/head This commit looks good Details

pull/26/head
Manuel Aranda Rosales 2025-03-19 16:04:55 +01:00
parent a2e0ced906
commit 2f813099c5
1 changed files with 20 additions and 3 deletions

View File

@ -25,14 +25,24 @@ class SyncAction extends AbstractOgRepositoryController
*/
public function __invoke(ImageRepository $input): JsonResponse
{
$content = $this->createRequest('GET', 'http://'.$input->getIp(). ':8006/ogrepository/v1/images');
$content = $this->createRequest('GET', 'http://' . $input->getIp() . ':8006/ogrepository/v1/images');
if (!isset($content['output']['REPOSITORY']['images'])) {
return new JsonResponse(data: 'No images found', status: Response::HTTP_NOT_FOUND);
}
$repository = $this->entityManager->getRepository(ImageImageRepository::class);
$existingImages = $repository->findBy(['repository' => $input]);
$newImageFullsums = array_column($content['output']['REPOSITORY']['images'], 'fullsum');
foreach ($content['output']['REPOSITORY']['images'] as $image) {
$imageImageRepositoryEntity = $this->entityManager->getRepository(ImageImageRepository::class)->findOneBy(['imageFullsum' => $image['fullsum'], 'repository' => $input]);
$imageImageRepositoryEntity = $repository->findOneBy([
'imageFullsum' => $image['fullsum'],
'repository' => $input
]);
$imageEntity = $this->entityManager->getRepository(Image::class)->findOneBy(['name' => $image['name']]);
if (!$imageEntity) {
@ -53,10 +63,17 @@ class SyncAction extends AbstractOgRepositoryController
$this->entityManager->persist($imageImageRepositoryEntity);
}
}
foreach ($existingImages as $existingImage) {
if (!in_array($existingImage->getImageFullsum(), $newImageFullsums)) {
$this->entityManager->remove($existingImage);
}
}
$this->entityManager->flush();
return new JsonResponse(data: $content, status: Response::HTTP_OK);
}
}