feat(documents) : add migration for type column with data classification
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Submodule Inventory_frontend updated: ac860d3165...2e82e854bf
31
migrations/Version20260323141052.php
Normal file
31
migrations/Version20260323141052.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?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 Version20260323141052 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add type column to documents table and classify existing documents by mimeType';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql("DO \$\$ BEGIN IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'documents' AND column_name = 'type') THEN ALTER TABLE documents ADD COLUMN type VARCHAR(20) NOT NULL DEFAULT 'documentation'; END IF; END \$\$");
|
||||||
|
$this->addSql("UPDATE documents SET type = 'photo' WHERE mimetype LIKE 'image/%'");
|
||||||
|
$this->addSql("UPDATE documents SET type = 'autre' WHERE type = 'documentation' AND mimetype NOT LIKE 'application/pdf' AND mimetype NOT LIKE 'image/%'");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE documents DROP COLUMN IF EXISTS type');
|
||||||
|
}
|
||||||
|
}
|
||||||
61
src/Doctrine/SearchByNameOrReferenceExtension.php
Normal file
61
src/Doctrine/SearchByNameOrReferenceExtension.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Doctrine;
|
||||||
|
|
||||||
|
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
|
||||||
|
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
|
||||||
|
use ApiPlatform\Metadata\Operation;
|
||||||
|
use App\Entity\Composant;
|
||||||
|
use App\Entity\Piece;
|
||||||
|
use App\Entity\Product;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
|
|
||||||
|
use function in_array;
|
||||||
|
use function is_string;
|
||||||
|
|
||||||
|
final class SearchByNameOrReferenceExtension implements QueryCollectionExtensionInterface
|
||||||
|
{
|
||||||
|
private const SUPPORTED_CLASSES = [
|
||||||
|
Piece::class,
|
||||||
|
Composant::class,
|
||||||
|
Product::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly RequestStack $requestStack,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function applyToCollection(
|
||||||
|
QueryBuilder $queryBuilder,
|
||||||
|
QueryNameGeneratorInterface $queryNameGenerator,
|
||||||
|
string $resourceClass,
|
||||||
|
?Operation $operation = null,
|
||||||
|
array $context = [],
|
||||||
|
): void {
|
||||||
|
if (!in_array($resourceClass, self::SUPPORTED_CLASSES, true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request = $this->requestStack->getCurrentRequest();
|
||||||
|
if (null === $request) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$q = $request->query->get('q', '');
|
||||||
|
if (!is_string($q) || '' === trim($q)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$escaped = addcslashes(trim($q), '%_');
|
||||||
|
$paramName = $queryNameGenerator->generateParameterName('searchQ');
|
||||||
|
$alias = $queryBuilder->getRootAliases()[0];
|
||||||
|
|
||||||
|
$queryBuilder
|
||||||
|
->andWhere(sprintf('LOWER(%s.name) LIKE :%s OR LOWER(%s.reference) LIKE :%s', $alias, $paramName, $alias, $paramName))
|
||||||
|
->setParameter($paramName, '%'.strtolower($escaped).'%')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -290,10 +290,13 @@ abstract class AbstractApiTestCase extends ApiTestCase
|
|||||||
return $machine;
|
return $machine;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createComposant(string $name = 'Composant Test', ?ModelType $type = null): Composant
|
protected function createComposant(string $name = 'Composant Test', ?string $reference = null, ?ModelType $type = null): Composant
|
||||||
{
|
{
|
||||||
$c = new Composant();
|
$c = new Composant();
|
||||||
$c->setName($name);
|
$c->setName($name);
|
||||||
|
if (null !== $reference) {
|
||||||
|
$c->setReference($reference);
|
||||||
|
}
|
||||||
if (null !== $type) {
|
if (null !== $type) {
|
||||||
$c->setTypeComposant($type);
|
$c->setTypeComposant($type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class ModelTypeSyncControllerTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$this->createComposant('C1', $mt);
|
$this->createComposant('C1', null, $mt);
|
||||||
|
|
||||||
$client = $this->createGestionnaireClient();
|
$client = $this->createGestionnaireClient();
|
||||||
$client->request('POST', '/api/model_types/'.$mt->getId().'/sync-preview', [
|
$client->request('POST', '/api/model_types/'.$mt->getId().'/sync-preview', [
|
||||||
@@ -102,7 +102,7 @@ class ModelTypeSyncControllerTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$this->createComposant('C1', $mt);
|
$this->createComposant('C1', null, $mt);
|
||||||
|
|
||||||
// Add a skeleton requirement (simulates a PATCH that already happened)
|
// Add a skeleton requirement (simulates a PATCH that already happened)
|
||||||
$em = $this->getEntityManager();
|
$em = $this->getEntityManager();
|
||||||
@@ -131,7 +131,7 @@ class ModelTypeSyncControllerTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$composant = $this->createComposant('C1', $mt);
|
$composant = $this->createComposant('C1', null, $mt);
|
||||||
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
|
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
|
||||||
|
|
||||||
// No skeleton requirements → slot is orphaned
|
// No skeleton requirements → slot is orphaned
|
||||||
@@ -152,7 +152,7 @@ class ModelTypeSyncControllerTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$composant = $this->createComposant('C1', $mt);
|
$composant = $this->createComposant('C1', null, $mt);
|
||||||
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
|
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
|
||||||
|
|
||||||
$client = $this->createGestionnaireClient();
|
$client = $this->createGestionnaireClient();
|
||||||
@@ -194,7 +194,7 @@ class ModelTypeSyncControllerTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$this->createComposant('C1', $mt);
|
$this->createComposant('C1', null, $mt);
|
||||||
|
|
||||||
$em = $this->getEntityManager();
|
$em = $this->getEntityManager();
|
||||||
$req = new SkeletonPieceRequirement();
|
$req = new SkeletonPieceRequirement();
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ class MachineTest extends AbstractApiTestCase
|
|||||||
$productType = $this->createModelType('Huile', 'HUILE-SLOT', ModelCategory::PRODUCT);
|
$productType = $this->createModelType('Huile', 'HUILE-SLOT', ModelCategory::PRODUCT);
|
||||||
$compType = $this->createModelType('Pompe', 'POMPE-SLOT', ModelCategory::COMPONENT);
|
$compType = $this->createModelType('Pompe', 'POMPE-SLOT', ModelCategory::COMPONENT);
|
||||||
|
|
||||||
$composant = $this->createComposant('Composant avec slots', $compType);
|
$composant = $this->createComposant('Composant avec slots', null, $compType);
|
||||||
$piece = $this->createPiece('Joint sélectionné', 'REF-JS', $pieceType);
|
$piece = $this->createPiece('Joint sélectionné', 'REF-JS', $pieceType);
|
||||||
$product = $this->createProduct('Huile sélectionnée', 'REF-HS', $productType);
|
$product = $this->createProduct('Huile sélectionnée', 'REF-HS', $productType);
|
||||||
|
|
||||||
|
|||||||
@@ -109,4 +109,66 @@ class FilterTest extends AbstractApiTestCase
|
|||||||
$this->assertResponseIsSuccessful();
|
$this->assertResponseIsSuccessful();
|
||||||
$this->assertJsonContains(['totalItems' => 1]);
|
$this->assertJsonContains(['totalItems' => 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testOrSearchByNameOnPieces(): void
|
||||||
|
{
|
||||||
|
$this->createPiece('Joint torique', 'REF-JT-001');
|
||||||
|
$this->createPiece('Roulement', 'REF-RL-002');
|
||||||
|
|
||||||
|
$client = $this->createViewerClient();
|
||||||
|
$client->request('GET', '/api/pieces?q=joint');
|
||||||
|
|
||||||
|
$this->assertResponseIsSuccessful();
|
||||||
|
$this->assertJsonContains(['totalItems' => 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrSearchByReferenceOnPieces(): void
|
||||||
|
{
|
||||||
|
$this->createPiece('Joint torique', 'REF-JT-001');
|
||||||
|
$this->createPiece('Roulement', 'REF-RL-002');
|
||||||
|
|
||||||
|
$client = $this->createViewerClient();
|
||||||
|
$client->request('GET', '/api/pieces?q=RL-002');
|
||||||
|
|
||||||
|
$this->assertResponseIsSuccessful();
|
||||||
|
$this->assertJsonContains(['totalItems' => 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrSearchMatchesBothNameAndReference(): void
|
||||||
|
{
|
||||||
|
$this->createComposant('Pompe REF-X', 'REF-POMPE-01');
|
||||||
|
$this->createComposant('Vanne', 'REF-VANNE-01');
|
||||||
|
$this->createComposant('Moteur', 'POMPE-MOTEUR');
|
||||||
|
|
||||||
|
$client = $this->createViewerClient();
|
||||||
|
$client->request('GET', '/api/composants?q=pompe');
|
||||||
|
|
||||||
|
$this->assertResponseIsSuccessful();
|
||||||
|
$this->assertJsonContains(['totalItems' => 2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrSearchEmptyQueryReturnsAll(): void
|
||||||
|
{
|
||||||
|
$this->createProduct('Produit A', 'REF-A');
|
||||||
|
$this->createProduct('Produit B', 'REF-B');
|
||||||
|
|
||||||
|
$client = $this->createViewerClient();
|
||||||
|
$client->request('GET', '/api/products?q=');
|
||||||
|
|
||||||
|
$this->assertResponseIsSuccessful();
|
||||||
|
$data = $client->getResponse()->toArray();
|
||||||
|
$this->assertGreaterThanOrEqual(2, $data['totalItems']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOrSearchOnProducts(): void
|
||||||
|
{
|
||||||
|
$this->createProduct('Huile moteur', 'HM-500');
|
||||||
|
$this->createProduct('Graisse', 'GR-100');
|
||||||
|
|
||||||
|
$client = $this->createViewerClient();
|
||||||
|
$client->request('GET', '/api/products?q=HM-500');
|
||||||
|
|
||||||
|
$this->assertResponseIsSuccessful();
|
||||||
|
$this->assertJsonContains(['totalItems' => 1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$this->createComposant('C1', $mt);
|
$this->createComposant('C1', null, $mt);
|
||||||
|
|
||||||
$result = $this->strategy->preview($mt, [
|
$result = $this->strategy->preview($mt, [
|
||||||
'pieces' => [['typePieceId' => $pieceType->getId(), 'position' => 0]],
|
'pieces' => [['typePieceId' => $pieceType->getId(), 'position' => 0]],
|
||||||
@@ -58,7 +58,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$composant = $this->createComposant('C1', $mt);
|
$composant = $this->createComposant('C1', null, $mt);
|
||||||
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
|
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
|
||||||
|
|
||||||
$result = $this->strategy->preview($mt, [
|
$result = $this->strategy->preview($mt, [
|
||||||
@@ -75,7 +75,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$composant = $this->createComposant('C1', $mt);
|
$composant = $this->createComposant('C1', null, $mt);
|
||||||
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
|
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
|
||||||
|
|
||||||
$result = $this->strategy->preview($mt, [
|
$result = $this->strategy->preview($mt, [
|
||||||
@@ -92,7 +92,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$composant = $this->createComposant('C1', $mt);
|
$composant = $this->createComposant('C1', null, $mt);
|
||||||
|
|
||||||
$em = $this->getEntityManager();
|
$em = $this->getEntityManager();
|
||||||
$req = new SkeletonPieceRequirement();
|
$req = new SkeletonPieceRequirement();
|
||||||
@@ -115,7 +115,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$composant = $this->createComposant('C1', $mt);
|
$composant = $this->createComposant('C1', null, $mt);
|
||||||
$piece = $this->createPiece('P1', 'P1-REF', $pieceType);
|
$piece = $this->createPiece('P1', 'P1-REF', $pieceType);
|
||||||
$slot = $this->createComposantPieceSlot($composant, $pieceType, $piece, 5, 0);
|
$slot = $this->createComposantPieceSlot($composant, $pieceType, $piece, 5, 0);
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$composant = $this->createComposant('C1', $mt);
|
$composant = $this->createComposant('C1', null, $mt);
|
||||||
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
|
$this->createComposantPieceSlot($composant, $pieceType, null, 1, 0);
|
||||||
|
|
||||||
// No skeleton requirements -> slot should be deleted
|
// No skeleton requirements -> slot should be deleted
|
||||||
@@ -158,7 +158,7 @@ class ComposantSyncStrategyTest extends AbstractApiTestCase
|
|||||||
{
|
{
|
||||||
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
$mt = $this->createModelType('Comp Cat', 'CC-001', ModelCategory::COMPONENT);
|
||||||
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
$pieceType = $this->createModelType('Piece Type', 'PT-001', ModelCategory::PIECE);
|
||||||
$composant = $this->createComposant('C1', $mt);
|
$composant = $this->createComposant('C1', null, $mt);
|
||||||
|
|
||||||
$em = $this->getEntityManager();
|
$em = $this->getEntityManager();
|
||||||
$req = new SkeletonPieceRequirement();
|
$req = new SkeletonPieceRequirement();
|
||||||
|
|||||||
Reference in New Issue
Block a user