From 7c37bd418a4e4675c9c23ba8e4db4ff1a1fe5fd8 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 11 Mar 2025 17:37:44 +0100 Subject: [PATCH] refs #1692. Import Image. Changes --- .../OgRepository/Image/ImportAction.php | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/Controller/OgRepository/Image/ImportAction.php b/src/Controller/OgRepository/Image/ImportAction.php index f83f363..79ea5ad 100644 --- a/src/Controller/OgRepository/Image/ImportAction.php +++ b/src/Controller/OgRepository/Image/ImportAction.php @@ -33,26 +33,6 @@ class ImportAction extends AbstractOgRepositoryController { $image = $input->name; - $params = [ - 'json' => [ - 'image' => $image.'.img' - ] - ]; - - $this->logger->info('Creating aux files', ['image' => $image]); - - $content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/torrentsum', $params); - - if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) { - throw new ValidatorException('Error importing image'); - } - - $inputData = [ - 'imageName' => $image - ]; - - $this->createService->__invoke(null, CommandTypes::CREATE_IMAGE_AUX_FILE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); - $imageEntity = $this->entityManager->getRepository(Image::class)->findOneBy(['name' => $image]); if (!$imageEntity){ @@ -70,6 +50,27 @@ class ImportAction extends AbstractOgRepositoryController throw new ValidatorException('This image already exists in this repository'); } + $params = [ + 'json' => [ + 'image' => $image.'.img' + ] + ]; + + $this->logger->info('Creating aux files', ['image' => $image]); + + $content = $this->createRequest('POST', 'http://'.$repository->getIp().':8006/ogrepository/v1/images/torrentsum', $params); + + if (isset($content['error']) && $content['code'] === Response::HTTP_INTERNAL_SERVER_ERROR ) { + throw new ValidatorException('Error importing image'); + } + + $inputData = [ + 'imageName' => $image, + 'imageUuid' => $imageImageRepositoryEntity->getUuid(), + ]; + + $this->createService->__invoke(null, CommandTypes::CREATE_IMAGE_AUX_FILE, TraceStatus::IN_PROGRESS, $content['job_id'], $inputData); + $imageImageRepositoryEntity = new ImageImageRepository(); $imageImageRepositoryEntity->setStatus(ImageStatus::AUX_FILES_PENDING); $imageImageRepositoryEntity->setImage($imageEntity);