Skip to content

Commit

Permalink
NEXT-22926 - Rework ProductReviewCountService
Browse files Browse the repository at this point in the history
  • Loading branch information
King-of-Babylon committed Apr 26, 2023
1 parent 86f36bf commit 3074e16
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\DataAbstractionLayer\Doctrine\RetryableQuery;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Uuid\Uuid;

#[Package('business-ops')]
/**
Expand All @@ -25,6 +26,8 @@ public function __construct(private readonly Connection $connection)
*/
public function updateReviewCount(array $reviewIds, bool $isDelete = false): void
{
$reviewIds = \array_map(fn ($id) => Uuid::fromHexToBytes($id), $reviewIds);

$results = $this->connection->executeQuery(
'SELECT * FROM product_review WHERE id IN (:ids)',
['ids' => $reviewIds],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Shopware\Core\Framework\DataAbstractionLayer\Event\BeforeDeleteEvent;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Uuid\Uuid;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand Down Expand Up @@ -40,7 +39,6 @@ public function deleteReview(BeforeDeleteEvent $event): void
return;
}

$ids = \array_map(fn ($id) => Uuid::fromHexToBytes($id), $ids);
$this->productReviewCountService->updateReviewCount($ids, true);
}

Expand All @@ -53,7 +51,6 @@ public function createReview(EntityWrittenEvent $reviewEvent): void
return;
}

$ids = \array_map(fn ($id) => Uuid::fromHexToBytes($id), $reviewEvent->getIds());
$this->productReviewCountService->updateReviewCount($ids);
$this->productReviewCountService->updateReviewCount($reviewEvent->getIds());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public function testDeleteReviews(): void
Uuid::randomHex(),
Uuid::randomHex(),
];
$binaryIds = \array_map(fn ($id) => Uuid::fromHexToBytes($id), $ids);
$this->productReviewCountService->expects(static::once())->method('updateReviewCount')->with($binaryIds, true);
$this->productReviewCountService->expects(static::once())->method('updateReviewCount')->with($ids, true);

$this->productReviewSubscriber->deleteReview($this->getBeforeDeleteEvent($ids));
}
Expand All @@ -80,8 +79,7 @@ public function testCreateReview(): void
Uuid::randomHex(),
Uuid::randomHex(),
];
$binaryIds = \array_map(fn ($id) => Uuid::fromHexToBytes($id), $ids);
$this->productReviewCountService->expects(static::once())->method('updateReviewCount')->with($binaryIds, false);
$this->productReviewCountService->expects(static::once())->method('updateReviewCount')->with($ids, false);

$this->productReviewSubscriber->createReview($this->getEntityWrittenEvent($ids));
}
Expand Down

0 comments on commit 3074e16

Please sign in to comment.