refs #2629. ImageRepository name, ip unique constraint
testing/ogcore-api/pipeline/head There was a failure building this commit Details

pull/47/head
Manuel Aranda Rosales 2025-08-25 12:27:30 +02:00
parent f931a78d9e
commit 17bb13393f
4 changed files with 72 additions and 1 deletions

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 Version20250825085920 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 image DROP FOREIGN KEY FK_C53D045F19EB6921');
$this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F19EB6921 FOREIGN KEY (client_id) REFERENCES client (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 image DROP FOREIGN KEY FK_C53D045F19EB6921');
$this->addSql('ALTER TABLE image ADD CONSTRAINT FK_C53D045F19EB6921 FOREIGN KEY (client_id) REFERENCES client (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 Version20250825095853 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('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_IP ON image_repository (ip)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NAME ON image_repository (name)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_IDENTIFIER_IP ON image_repository');
$this->addSql('DROP INDEX UNIQ_IDENTIFIER_NAME ON image_repository');
}
}

View File

@ -6,8 +6,13 @@ use App\Repository\ImageRepositoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: ImageRepositoryRepository::class)]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_IP', fields: ['ip'])]
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_NAME', fields: ['name'])]
#[UniqueEntity(fields: ['ip'], message: 'This IP address is already in use.')]
#[UniqueEntity(fields: ['name'], message: 'This name is already in use.')]
class ImageRepository extends AbstractEntity
{
const string DEFAULT_USER = 'opengnsys';

View File

@ -100,7 +100,7 @@ readonly class ImageProcessor implements ProcessorInterface
return new JsonResponse($jsonString, Response::HTTP_OK, [], true);
}
return new JsonResponse(data: ['/clients/' . $image->getClient()->getUuid() => ['headers' => []]], status: Response::HTTP_OK);
return new JsonResponse(data: ['/clients/' . $image?->getClient()?->getUuid() => ['headers' => []]], status: Response::HTTP_OK);
} catch (\Exception $e) {
$this->logger->error('Error processing image creation/update', [
'error' => $e->getMessage(),