mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Review] Change ReviewChangeListener doctrine event from postRemove to preRemove
This commit is contained in:
parent
87de9289f0
commit
1e216bf099
5 changed files with 17 additions and 12 deletions
|
|
@ -1,3 +1,8 @@
|
|||
# UPGRADING FROM `v1.13.6` TO `v1.13.7`
|
||||
|
||||
1. The `sylius.product_review.average_rating_updater` has changed its `doctrine.event_listener` event
|
||||
from `postRemove` to `preRemove`.
|
||||
|
||||
# UPGRADING FROM `v1.13.1` TO `v1.13.2`
|
||||
|
||||
1. Due to a bug that was causing wrong calculation of available stock during completing a payment [REF](https://github.com/Sylius/Sylius/issues/16160),
|
||||
|
|
|
|||
|
|
@ -4906,12 +4906,12 @@ parameters:
|
|||
path: src/Sylius/Bundle/ReviewBundle/EventListener/ReviewChangeListener.php
|
||||
|
||||
-
|
||||
message: "#^Method Sylius\\\\Bundle\\\\ReviewBundle\\\\EventListener\\\\ReviewChangeListener\\:\\:postRemove\\(\\) has no return type specified\\.$#"
|
||||
message: "#^Method Sylius\\\\Bundle\\\\ReviewBundle\\\\EventListener\\\\ReviewChangeListener\\:\\:preRemove\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/Sylius/Bundle/ReviewBundle/EventListener/ReviewChangeListener.php
|
||||
|
||||
-
|
||||
message: "#^Method Sylius\\\\Bundle\\\\ReviewBundle\\\\EventListener\\\\ReviewChangeListener\\:\\:postRemove\\(\\) has parameter \\$args with generic class Doctrine\\\\Persistence\\\\Event\\\\LifecycleEventArgs but does not specify its types\\: TObjectManager$#"
|
||||
message: "#^Method Sylius\\\\Bundle\\\\ReviewBundle\\\\EventListener\\\\ReviewChangeListener\\:\\:preRemove\\(\\) has parameter \\$args with generic class Doctrine\\\\Persistence\\\\Event\\\\LifecycleEventArgs but does not specify its types\\: TObjectManager$#"
|
||||
count: 1
|
||||
path: src/Sylius/Bundle/ReviewBundle/EventListener/ReviewChangeListener.php
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ final class SyliusReviewExtension extends AbstractResourceExtension
|
|||
'lazy' => true,
|
||||
])
|
||||
->addTag('doctrine.event_listener', [
|
||||
'event' => 'postRemove',
|
||||
'event' => 'preRemove',
|
||||
'lazy' => true,
|
||||
])
|
||||
;
|
||||
|
|
|
|||
|
|
@ -13,28 +13,28 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Bundle\ReviewBundle\EventListener;
|
||||
|
||||
use Doctrine\ORM\Event\PostRemoveEventArgs;
|
||||
use Doctrine\ORM\Event\PreRemoveEventArgs;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
use Sylius\Bundle\ReviewBundle\Updater\ReviewableRatingUpdaterInterface;
|
||||
use Sylius\Component\Review\Model\ReviewInterface;
|
||||
|
||||
final class ReviewChangeListener
|
||||
{
|
||||
public function __construct(private ReviewableRatingUpdaterInterface $averageRatingUpdater)
|
||||
public function __construct(private readonly ReviewableRatingUpdaterInterface $averageRatingUpdater)
|
||||
{
|
||||
}
|
||||
|
||||
public function postPersist(LifecycleEventArgs $args)
|
||||
public function postPersist(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->recalculateSubjectRating($args);
|
||||
}
|
||||
|
||||
public function postUpdate(LifecycleEventArgs $args)
|
||||
public function postUpdate(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->recalculateSubjectRating($args);
|
||||
}
|
||||
|
||||
public function postRemove(LifecycleEventArgs $args)
|
||||
public function preRemove(LifecycleEventArgs $args): void
|
||||
{
|
||||
$this->recalculateSubjectRating($args);
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ final class ReviewChangeListener
|
|||
|
||||
$reviewSubject = $subject->getReviewSubject();
|
||||
|
||||
if ($args instanceof PostRemoveEventArgs) {
|
||||
if ($args instanceof PreRemoveEventArgs) {
|
||||
$reviewSubject->removeReview($subject);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace spec\Sylius\Bundle\ReviewBundle\EventListener;
|
|||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use Doctrine\ORM\Event\PostRemoveEventArgs;
|
||||
use Doctrine\ORM\Event\PreRemoveEventArgs;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Bundle\ReviewBundle\Updater\ReviewableRatingUpdaterInterface;
|
||||
|
|
@ -43,13 +43,13 @@ final class ReviewChangeListenerSpec extends ObjectBehavior
|
|||
$this->recalculateSubjectRating($event);
|
||||
}
|
||||
|
||||
function it_removes_a_review_from_a_review_subject_on_the_post_remove_event(
|
||||
function it_removes_a_review_from_a_review_subject_on_the_pre_remove_event(
|
||||
ReviewableRatingUpdaterInterface $averageRatingUpdater,
|
||||
ReviewInterface $review,
|
||||
ReviewableInterface $reviewSubject,
|
||||
EntityManagerInterface $entityManager,
|
||||
): void {
|
||||
$event = new PostRemoveEventArgs($review->getWrappedObject(), $entityManager->getWrappedObject());
|
||||
$event = new PreRemoveEventArgs($review->getWrappedObject(), $entityManager->getWrappedObject());
|
||||
$review->getReviewSubject()->willReturn($reviewSubject);
|
||||
|
||||
$reviewSubject->removeReview($review)->shouldBeCalled();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue