custom/plugins/RpayPayments/src/Components/Logging/Subscriber/RepositorySubscriber.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * Copyright (c) Ratepay GmbH
  5.  *
  6.  * For the full copyright and license information, please view the LICENSE
  7.  * file that was distributed with this source code.
  8.  */
  9. namespace Ratepay\RpayPayments\Components\Logging\Subscriber;
  10. use Ratepay\RpayPayments\Components\Logging\Model\ApiRequestLogEntity;
  11. use Ratepay\RpayPayments\Components\Logging\Model\Definition\ApiRequestLogDefinition;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntitySearchedEvent;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter;
  14. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class RepositorySubscriber implements EventSubscriberInterface
  17. {
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             EntitySearchedEvent::class => 'addDefaultSortingForLogs',
  22.         ];
  23.     }
  24.     public function addDefaultSortingForLogs(EntitySearchedEvent $event): void
  25.     {
  26.         if ($event->getDefinition()->getEntityName() !== ApiRequestLogDefinition::ENTITY_NAME) {
  27.             return;
  28.         }
  29.         $criteria $event->getCriteria();
  30.         if ($criteria->getTerm()) {
  31.             $criteria->addFilter(new ContainsFilter(ApiRequestLogEntity::FIELD_ADDITIONAL_DATA$criteria->getTerm()));
  32.             $criteria->setTerm(null);
  33.             $criteria->addSorting(new FieldSorting(ApiRequestLogEntity::FIELD_CREATED_ATFieldSorting::DESCENDING));
  34.         }
  35.     }
  36. }