Compare commits

...

3 Commits

Author SHA1 Message Date
Manuel Aranda Rosales e447f75544 Merge pull request 'develop' (#62) from develop into main
testing/ogcore-api/pipeline/head There was a failure building this commit Details
ogcore-debian-package/pipeline/head This commit looks good Details
ogcore-debian-package/pipeline/tag This commit looks good Details
Reviewed-on: #62
2025-09-16 12:10:41 +02:00
Manuel Aranda Rosales 54cbcef6cb refs #2812. Fixed bug in delete repository. Added constraints
testing/ogcore-api/pipeline/pr-main Build queued... Details
testing/ogcore-api/pipeline/head This commit looks good Details
2025-09-16 12:10:05 +02:00
Manuel Aranda Rosales edd85e5d99 refs #2812. Fixed bug in delete repository. Added constraints
testing/ogcore-api/pipeline/head This commit looks good Details
2025-09-15 18:37:04 +02:00
9 changed files with 125 additions and 5 deletions

View File

@ -1,4 +1,9 @@
# Changelog
## [0.24.3] - 2025-09-16
### Fixed
- Se ha corregido un error a la hora de borrar un repositorio el cual tuviera imagenes.
---
## [0.24.2] - 2025-09-10
### Improved
- Se han realizado mejoras varias sobre la funcionalidad de tareas programadas.

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250915162242 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE git_repository DROP FOREIGN KEY FK_C2B3204A50C9D4F7');
$this->addSql('ALTER TABLE git_repository ADD CONSTRAINT FK_C2B3204A50C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id) ON DELETE CASCADE');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE git_repository DROP FOREIGN KEY FK_C2B3204A50C9D4F7');
$this->addSql('ALTER TABLE git_repository ADD CONSTRAINT FK_C2B3204A50C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)');
}
}

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250915162434 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B5450C9D4F7');
$this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B5450C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE network_settings DROP FOREIGN KEY FK_48869B5450C9D4F7');
$this->addSql('ALTER TABLE network_settings ADD CONSTRAINT FK_48869B5450C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)');
}
}

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250915162508 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C744045550C9D4F7');
$this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C744045550C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE client DROP FOREIGN KEY FK_C744045550C9D4F7');
$this->addSql('ALTER TABLE client ADD CONSTRAINT FK_C744045550C9D4F7 FOREIGN KEY (repository_id) REFERENCES image_repository (id)');
}
}

View File

@ -68,6 +68,7 @@ class Client extends AbstractEntity
private ?PxeTemplate $template = null;
#[ORM\ManyToOne()]
#[ORM\JoinColumn(onDelete: 'SET NULL')]
private ?ImageRepository $repository = null;
#[ORM\ManyToOne(inversedBy: 'clients')]

View File

@ -17,6 +17,7 @@ class GitRepository extends AbstractEntity
private ?string $description = null;
#[ORM\ManyToOne(inversedBy: 'gitRepositories')]
#[ORM\JoinColumn(onDelete: 'CASCADE')]
private ?ImageRepository $repository = null;
public function __construct()

View File

@ -28,7 +28,7 @@ class ImageRepository extends AbstractEntity
/**
* @var Collection<int, ImageImageRepository>
*/
#[ORM\OneToMany(mappedBy: 'repository', targetEntity: ImageImageRepository::class)]
#[ORM\OneToMany(mappedBy: 'repository', targetEntity: ImageImageRepository::class, cascade: ['remove'], orphanRemoval: true)]
private Collection $imageImageRepositories;
#[ORM\Column(length: 255, nullable: true)]

View File

@ -67,6 +67,7 @@ class NetworkSettings extends AbstractEntity
private ?HardwareProfile $hardwareProfile = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(onDelete: 'SET NULL')]
private ?ImageRepository $repository = null;
#[ORM\ManyToOne]

View File

@ -12,13 +12,17 @@ use ApiPlatform\Validator\ValidatorInterface;
use App\Dto\Input\ImageRepositoryInput;
use App\Dto\Output\ImageRepositoryOutput;
use App\Repository\ImageRepositoryRepository;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Client;
readonly class ImageRepositoryProcessor implements ProcessorInterface
{
public function __construct(
private ImageRepositoryRepository $imageRepository,
private ValidatorInterface $validator
)
private ValidatorInterface $validator,
private EntityManagerInterface $entityManager
)
{
}
@ -60,8 +64,17 @@ readonly class ImageRepositoryProcessor implements ProcessorInterface
private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null
{
$user = $this->imageRepository->findOneByUuid($uriVariables['uuid']);
$this->imageRepository->delete($user);
$repository = $this->imageRepository->findOneByUuid($uriVariables['uuid']);
$clients = $this->entityManager->getRepository(Client::class)->findBy(['repository' => $repository]);
foreach ($clients as $client) {
$client->setRepository($client->getOrganizationalUnit()?->getNetworkSettings()?->getRepository());
$this->entityManager->persist($client);
$this->entityManager->flush();
}
$this->imageRepository->delete($repository);
return null;
}