Fix outdated code
This commit is contained in:
@@ -8,11 +8,7 @@ services:
|
||||
tags:
|
||||
- { name: 'console.command', command: 'pcm:search:reindex' }
|
||||
|
||||
pcm_search.searchable_subscriber:
|
||||
class: Pcm\SearchBundle\EventSubscriber\SearchableSubscriber
|
||||
public: true
|
||||
tags:
|
||||
- { name: doctrine.event_subscriber }
|
||||
Pcm\SearchBundle\EventSubscriber\SearchableSubscriber: ~
|
||||
|
||||
pcm_search.search_service:
|
||||
alias: Pcm\SearchBundle\Service\SearchService
|
||||
|
||||
@@ -6,24 +6,20 @@ namespace Pcm\SearchBundle\EventSubscriber;
|
||||
|
||||
use Pcm\SearchBundle\Entity\Interface\SearchableInterface;
|
||||
use Pcm\SearchBundle\Service\SearchService;
|
||||
use Doctrine\Common\EventSubscriber;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
|
||||
use Doctrine\ORM\Event\PostPersistEventArgs;
|
||||
use Doctrine\ORM\Event\PostUpdateEventArgs;
|
||||
use Doctrine\ORM\Event\PreRemoveEventArgs;
|
||||
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 getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
Events::postPersist,
|
||||
Events::postUpdate,
|
||||
Events::preRemove
|
||||
];
|
||||
}
|
||||
|
||||
public function postUpdate(LifecycleEventArgs $args)
|
||||
public function postUpdate(PostUpdateEventArgs $args): void
|
||||
{
|
||||
$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();
|
||||
|
||||
@@ -41,7 +37,7 @@ class SearchableSubscriber implements EventSubscriber
|
||||
}
|
||||
}
|
||||
|
||||
public function preRemove(LifecycleEventArgs $args)
|
||||
public function preRemove(PreRemoveEventArgs $args): void
|
||||
{
|
||||
$entity = $args->getObject();
|
||||
|
||||
|
||||
@@ -6,9 +6,7 @@ namespace Pcm\SearchBundle\Service;
|
||||
|
||||
use Pcm\SearchBundle\Entity\SearchIndex;
|
||||
use Pcm\SearchBundle\Entity\Interface\SearchableInterface;
|
||||
use Doctrine\Common\Util\ClassUtils;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Proxy\Proxy;
|
||||
|
||||
class SearchService
|
||||
{
|
||||
@@ -38,7 +36,7 @@ class SearchService
|
||||
*/
|
||||
public function unIndex(SearchableInterface $entity)
|
||||
{
|
||||
$class = get_class($entity);
|
||||
$class = $this->em->getClassMetadata($entity::class)->getName();
|
||||
|
||||
$search_result = $this
|
||||
->em
|
||||
@@ -69,11 +67,7 @@ class SearchService
|
||||
|
||||
$data = implode(' ', $values);
|
||||
|
||||
$class = get_class($entity);
|
||||
|
||||
if ($entity instanceof Proxy) {
|
||||
$class = ClassUtils::getRealClass($class);
|
||||
}
|
||||
$class = $this->em->getClassMetadata($entity::class)->getName();
|
||||
|
||||
$searchResult = $this
|
||||
->em
|
||||
|
||||
Reference in New Issue
Block a user