Skip to content

Commit 0451469

Browse files
committed
Merge branch '2026.1' into 2026.2
2 parents b1f459c + 3068558 commit 0451469

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

src/Entity/IndexQueue.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#[ORM\Table(name: self::TABLE)]
2121
#[ORM\Index(columns: ['dispatched'], name: self::TABLE . '_dispatched')]
2222
#[ORM\Index(columns: ['operationTime'], name: self::TABLE . '_operation_time')]
23+
#[ORM\UniqueConstraint(name: self::TABLE . '_element_id_type', columns: ['elementId', 'elementType'])]
2324

2425
/**
2526
* @internal
@@ -29,6 +30,7 @@ class IndexQueue
2930
public const TABLE = 'generic_data_index_queue';
3031

3132
#[ORM\Id]
33+
#[ORM\GeneratedValue]
3234
#[ORM\Column(type: 'bigint')]
3335
private int $id;
3436

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\GenericDataIndexBundle\Tests\Unit\Entity;
15+
16+
use Codeception\Test\Unit;
17+
use Doctrine\ORM\Mapping\ClassMetadata;
18+
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
19+
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
20+
use Pimcore\Bundle\GenericDataIndexBundle\Entity\IndexQueue;
21+
22+
/**
23+
* The ORM metadata must match the schema created by the Installer, otherwise a
24+
* doctrine schema update regenerates the queue table without the auto increment
25+
* on `id` (every row is inserted with id 0, so `INSERT IGNORE` keeps only one
26+
* row) and without the unique index the queue deduplication relies on.
27+
*
28+
* @see https://github.com/pimcore/generic-data-index-bundle/issues/432
29+
*
30+
* @internal
31+
*/
32+
final class IndexQueueTest extends Unit
33+
{
34+
public function testIdUsesGeneratedValue(): void
35+
{
36+
$metadata = $this->loadClassMetadata();
37+
38+
$this->assertNotSame(
39+
ClassMetadata::GENERATOR_TYPE_NONE,
40+
$metadata->generatorType,
41+
'IndexQueue::$id must declare #[ORM\GeneratedValue] so schema updates keep the auto increment'
42+
);
43+
}
44+
45+
public function testElementIdTypeUniqueConstraintIsDeclared(): void
46+
{
47+
$metadata = $this->loadClassMetadata();
48+
49+
$uniqueConstraints = $metadata->table['uniqueConstraints'] ?? [];
50+
$constraintName = IndexQueue::TABLE . '_element_id_type';
51+
52+
$this->assertArrayHasKey(
53+
$constraintName,
54+
$uniqueConstraints,
55+
'IndexQueue must declare the unique constraint on (elementId, elementType) the queue deduplication relies on'
56+
);
57+
$this->assertSame(
58+
['elementId', 'elementType'],
59+
$uniqueConstraints[$constraintName]['columns']
60+
);
61+
}
62+
63+
private function loadClassMetadata(): ClassMetadata
64+
{
65+
$metadata = new ClassMetadata(IndexQueue::class);
66+
$metadata->initializeReflection(new RuntimeReflectionService());
67+
68+
(new AttributeDriver([]))->loadMetadataForClass(IndexQueue::class, $metadata);
69+
70+
return $metadata;
71+
}
72+
}

0 commit comments

Comments
 (0)