• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

heimrichhannot / contao-utils-bundle / 38411311194

13 Oct 2026 02:11PM UTC coverage: 83.697% (+3.9%) from 79.825%
38411311194

Pull #108

github

koertho
apply rector

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pull Request #108: add search vector field

339 of 352 new or added lines in 16 files covered. (96.31%)

1535 of 1834 relevant lines covered (83.7%)

8.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.36
/src/EventListener/DcaField/SearchVectorFieldListener.php
1
<?php
2

3
namespace HeimrichHannot\UtilsBundle\EventListener\DcaField;
4

5
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
6
use Contao\DataContainer;
7
use HeimrichHannot\UtilsBundle\Dca\SearchVectorField;
8
use HeimrichHannot\UtilsBundle\SearchVector\SearchVectorIndexer;
9

10
class SearchVectorFieldListener extends AbstractDcaFieldListener
11
{
12
    #[AsHook('loadDataContainer')]
13
    public function onLoadDataContainer(string $table): void
14
    {
15
        if (!$configuration = SearchVectorField::getRegistrations()[$table] ?? null) {
2 ✔
16
            return;
1 ✔
17
        }
18

19
        // Machine-written, so it is part of no palette and hidden from the "show" view and the version diff
20
        $field = [
2 ✔
21
            'eval' => ['doNotShow' => true],
2 ✔
22
            'sql' => ['type' => 'text', 'notnull' => false],
2 ✔
23
        ];
2 ✔
24

25
        $this->applyDefaultFieldAdjustments($field, $configuration);
2 ✔
26

27
        $GLOBALS['TL_DCA'][$table]['fields'][$configuration->getFieldName()] = $field;
2 ✔
28

29
        // The table is only known at runtime, so the callbacks cannot be registered with attributes
30
        $GLOBALS['TL_DCA'][$table]['config']['onsubmit_callback'][] = [self::class, 'onSubmitCallback'];
2 ✔
31
        $GLOBALS['TL_DCA'][$table]['config']['oncopy_callback'][] = [self::class, 'onCopyCallback'];
2 ✔
32
        $GLOBALS['TL_DCA'][$table]['config']['onrestore_version_callback'][] = [self::class, 'onRestoreVersionCallback'];
2 ✔
33
    }
34

35
    public function onSubmitCallback(DataContainer $dc): void
36
    {
37
        if ($dc->id) {
3 ✔
38
            $this->rebuild($dc->table, (int) $dc->id, $dc);
2 ✔
39
        }
40
    }
41

42
    public function onCopyCallback(int|string $insertId, DataContainer $dc): void
43
    {
44
        $this->rebuild($dc->table, (int) $insertId);
2 ✔
45
    }
46

47
    public function onRestoreVersionCallback(string $table, int|string $id, int|string $version, array $data): void
48
    {
49
        $this->rebuild($table, (int) $id);
2 ✔
50
    }
51

52
    private function rebuild(string $table, int $id, ?DataContainer $dc = null): void
53
    {
54
        $indexer = $this->container->get(SearchVectorIndexer::class);
2 ✔
55

56
        if ((SearchVectorField::getRegistrations()[$table] ?? null)?->isAsync()) {
2 ✔
57
            $indexer->queue($table, $id);
1 ✔
58
        } else {
59
            $indexer->index($table, $id, $dc);
1 ✔
60
        }
61
    }
62

63
    public static function getSubscribedServices(): array
64
    {
NEW
65
        $services = parent::getSubscribedServices();
×
NEW
66
        $services[] = SearchVectorIndexer::class;
×
67

NEW
68
        return $services;
×
69
    }
70
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc