Fix outdated code
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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