Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| efc9b17136 | |||
| d3de91ea0b | |||
| f9700e1959 | |||
| 92bd22ad99 | |||
| 5548df12bd | |||
| 6e2c241349 |
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM php:8.1-alpine
|
FROM php:8.4-alpine
|
||||||
|
|
||||||
WORKDIR /code
|
WORKDIR /code
|
||||||
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
PHP = docker compose run php
|
|
||||||
|
|
||||||
.PHONY: composer_install composer_update static_analysis tests
|
|
||||||
|
|
||||||
composer_install:
|
|
||||||
@$(PHP) composer install
|
|
||||||
|
|
||||||
composer_update:
|
|
||||||
@$(PHP) composer update
|
|
||||||
|
|
||||||
static_analysis:
|
|
||||||
@$(PHP) vendor/bin/psalm
|
|
||||||
|
|
||||||
tests:
|
|
||||||
@$(PHP) rm -rf var/cache
|
|
||||||
@$(PHP) vendor/bin/phpunit
|
|
||||||
+9
-8
@@ -3,16 +3,17 @@
|
|||||||
"description": "Provides a search system for Symfony projects",
|
"description": "Provides a search system for Symfony projects",
|
||||||
"type": "symfony-bundle",
|
"type": "symfony-bundle",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.0",
|
"php": ">=8.2",
|
||||||
"beberlei/doctrineextensions": "^1.3",
|
"beberlei/doctrineextensions": "^1.5",
|
||||||
"doctrine/doctrine-bundle": "^2.7",
|
"doctrine/doctrine-bundle": "^2.13",
|
||||||
"doctrine/orm": "^2.12",
|
"doctrine/orm": "^2.20 || ^3.3",
|
||||||
"symfony/framework-bundle": "*"
|
"doctrine/persistence": "^3.3 || ^4.0",
|
||||||
|
"symfony/framework-bundle": "^6.4 || ^7.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"vimeo/psalm": "^4.24",
|
"vimeo/psalm": "^6.0",
|
||||||
"psalm/plugin-symfony": "^3.1",
|
"psalm/plugin-symfony": "^5.2",
|
||||||
"phpunit/phpunit": "^9.5"
|
"phpunit/phpunit": "^11.0 || ^12.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
@@ -8,11 +8,7 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: 'console.command', command: 'pcm:search:reindex' }
|
- { name: 'console.command', command: 'pcm:search:reindex' }
|
||||||
|
|
||||||
pcm_search.searchable_subscriber:
|
Pcm\SearchBundle\EventSubscriber\SearchableSubscriber: ~
|
||||||
class: Pcm\SearchBundle\EventSubscriber\SearchableSubscriber
|
|
||||||
public: true
|
|
||||||
tags:
|
|
||||||
- { name: doctrine.event_subscriber }
|
|
||||||
|
|
||||||
pcm_search.search_service:
|
pcm_search.search_service:
|
||||||
alias: Pcm\SearchBundle\Service\SearchService
|
alias: Pcm\SearchBundle\Service\SearchService
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
php := "docker compose run php"
|
||||||
|
|
||||||
|
composer-install:
|
||||||
|
@{{php}} composer install
|
||||||
|
|
||||||
|
composer-update:
|
||||||
|
@{{php}} composer update
|
||||||
|
|
||||||
|
composer *args:
|
||||||
|
@{{php}} composer {{args}}
|
||||||
|
|
||||||
|
static-analysis:
|
||||||
|
@{{php}} vendor/bin/psalm
|
||||||
|
|
||||||
|
tests:
|
||||||
|
@{{php}} rm -rf var/cache
|
||||||
|
@{{php}} vendor/bin/phpunit
|
||||||
@@ -84,6 +84,7 @@ class SearchIndexCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
$progress_bar->finish();
|
$progress_bar->finish();
|
||||||
|
$io->writeln('');
|
||||||
|
|
||||||
$table = new Table($output);
|
$table = new Table($output);
|
||||||
$table
|
$table
|
||||||
|
|||||||
@@ -6,24 +6,20 @@ namespace Pcm\SearchBundle\EventSubscriber;
|
|||||||
|
|
||||||
use Pcm\SearchBundle\Entity\Interface\SearchableInterface;
|
use Pcm\SearchBundle\Entity\Interface\SearchableInterface;
|
||||||
use Pcm\SearchBundle\Service\SearchService;
|
use Pcm\SearchBundle\Service\SearchService;
|
||||||
use Doctrine\Common\EventSubscriber;
|
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
|
||||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
use Doctrine\ORM\Event\PostPersistEventArgs;
|
||||||
|
use Doctrine\ORM\Event\PostUpdateEventArgs;
|
||||||
|
use Doctrine\ORM\Event\PreRemoveEventArgs;
|
||||||
use Doctrine\ORM\Events;
|
use Doctrine\ORM\Events;
|
||||||
|
|
||||||
class SearchableSubscriber implements EventSubscriber
|
#[AsDoctrineListener(event: Events::postPersist)]
|
||||||
|
#[AsDoctrineListener(event: Events::postUpdate)]
|
||||||
|
#[AsDoctrineListener(event: Events::preRemove)]
|
||||||
|
class SearchableSubscriber
|
||||||
{
|
{
|
||||||
public function __construct(private SearchService $searchService) {}
|
public function __construct(private SearchService $searchService) {}
|
||||||
|
|
||||||
public function getSubscribedEvents(): array
|
public function postUpdate(PostUpdateEventArgs $args): void
|
||||||
{
|
|
||||||
return [
|
|
||||||
Events::postPersist,
|
|
||||||
Events::postUpdate,
|
|
||||||
Events::preRemove
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function postUpdate(LifecycleEventArgs $args)
|
|
||||||
{
|
{
|
||||||
$entity = $args->getObject();
|
$entity = $args->getObject();
|
||||||
|
|
||||||
@@ -32,7 +28,7 @@ class SearchableSubscriber implements EventSubscriber
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postPersist(LifecycleEventArgs $args)
|
public function postPersist(PostPersistEventArgs $args): void
|
||||||
{
|
{
|
||||||
$entity = $args->getObject();
|
$entity = $args->getObject();
|
||||||
|
|
||||||
@@ -41,7 +37,7 @@ class SearchableSubscriber implements EventSubscriber
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function preRemove(LifecycleEventArgs $args)
|
public function preRemove(PreRemoveEventArgs $args): void
|
||||||
{
|
{
|
||||||
$entity = $args->getObject();
|
$entity = $args->getObject();
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ namespace Pcm\SearchBundle\Service;
|
|||||||
|
|
||||||
use Pcm\SearchBundle\Entity\SearchIndex;
|
use Pcm\SearchBundle\Entity\SearchIndex;
|
||||||
use Pcm\SearchBundle\Entity\Interface\SearchableInterface;
|
use Pcm\SearchBundle\Entity\Interface\SearchableInterface;
|
||||||
use Doctrine\Common\Util\ClassUtils;
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Proxy\Proxy;
|
|
||||||
|
|
||||||
class SearchService
|
class SearchService
|
||||||
{
|
{
|
||||||
@@ -38,7 +36,7 @@ class SearchService
|
|||||||
*/
|
*/
|
||||||
public function unIndex(SearchableInterface $entity)
|
public function unIndex(SearchableInterface $entity)
|
||||||
{
|
{
|
||||||
$class = get_class($entity);
|
$class = $this->em->getClassMetadata($entity::class)->getName();
|
||||||
|
|
||||||
$search_result = $this
|
$search_result = $this
|
||||||
->em
|
->em
|
||||||
@@ -69,11 +67,7 @@ class SearchService
|
|||||||
|
|
||||||
$data = implode(' ', $values);
|
$data = implode(' ', $values);
|
||||||
|
|
||||||
$class = get_class($entity);
|
$class = $this->em->getClassMetadata($entity::class)->getName();
|
||||||
|
|
||||||
if ($entity instanceof Proxy) {
|
|
||||||
$class = ClassUtils::getRealClass($class);
|
|
||||||
}
|
|
||||||
|
|
||||||
$searchResult = $this
|
$searchResult = $this
|
||||||
->em
|
->em
|
||||||
|
|||||||
Reference in New Issue
Block a user