Skip to content

Commit b9caa42

Browse files
committed
feat: add dedicated method to get id for existing redirect
1 parent b3be123 commit b9caa42

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/Message/TinectRedirectUpdateHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __invoke(TinectRedirectUpdateMessage $message): void
3131
$redirectId = $message->getId();
3232

3333
if ($redirectId === null) {
34-
$redirectId = $this->redirectFinderService->find($message->getSource(), $message->getSalesChannelDomainId())?->getId();
34+
$redirectId = $this->redirectFinderService->findId($message->getSource(), $message->getSalesChannelDomainId());
3535
}
3636

3737
if ($message->canCreateRedirect()) {

src/Services/RedirectFinderService.php

+22-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,28 @@ public function __construct(
2323
public function find(string $path, ?string $salesChannelDomainId): ?RedirectEntity
2424
{
2525
$context = new Context(new SystemSource());
26-
$criteria = (new Criteria())
26+
$criteria = $this->getCriteria($path, $salesChannelDomainId);
27+
28+
$redirect = $this->tinectRedirectsRedirectRepository->search($criteria, $context)->first();
29+
30+
if ($redirect instanceof RedirectEntity) {
31+
return $redirect;
32+
}
33+
34+
return null;
35+
}
36+
37+
public function findId(string $path, ?string $salesChannelDomainId): ?string
38+
{
39+
$context = new Context(new SystemSource());
40+
$criteria = $this->getCriteria($path, $salesChannelDomainId);
41+
42+
return $this->tinectRedirectsRedirectRepository->searchIds($criteria, $context)->firstId();
43+
}
44+
45+
private function getCriteria(string $path, ?string $salesChannelDomainId): Criteria
46+
{
47+
return (new Criteria())
2748
->addFilter(new EqualsFilter('source', $path))
2849
->addFilter(
2950
new MultiFilter(MultiFilter::CONNECTION_OR, [
@@ -33,13 +54,5 @@ public function find(string $path, ?string $salesChannelDomainId): ?RedirectEnti
3354
)
3455
->addSorting(new FieldSorting('salesChannelDomainId', FieldSorting::DESCENDING))
3556
->setLimit(1);
36-
37-
$redirect = $this->tinectRedirectsRedirectRepository->search($criteria, $context)->first();
38-
39-
if ($redirect instanceof RedirectEntity) {
40-
return $redirect;
41-
}
42-
43-
return null;
4457
}
4558
}

0 commit comments

Comments
 (0)