Skip to content

Commit

Permalink
Fixed resolving of cookie suggestions that are not already created by…
Browse files Browse the repository at this point in the history
… crawler
  • Loading branch information
tg666 committed Jan 19, 2024
1 parent ab37597 commit e78323d
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use App\Domain\CookieSuggestion\Command\DoNotIgnoreCookieSuggestionCommand;
use App\Domain\CookieSuggestion\Command\IgnoreCookieSuggestionPermanentlyCommand;
use App\Domain\CookieSuggestion\Command\IgnoreCookieSuggestionUntilNextOccurrenceCommand;
use App\Domain\CookieSuggestion\ValueObject\CookieSuggestionId;
use App\Domain\Project\Command\AddCookieProvidersToProjectCommand;
use App\Domain\Project\ValueObject\ProjectId;
use App\ReadModel\Cookie\CookieView;
Expand Down Expand Up @@ -453,8 +454,12 @@ private function resolveIgnore(
bool $uiActionsAllowed,
bool $virtualSuggestion,
): bool {
if ($virtualSuggestion && !$this->createCookieSuggestionFromVirtualId($cookieSuggestionId, $uiActionsAllowed)) {
return false;
if ($virtualSuggestion) {
$cookieSuggestionId = $this->createVirtualCookieSuggestion($cookieSuggestionId, $uiActionsAllowed);

if (null === $cookieSuggestionId) {
return false;
}
}

try {
Expand Down Expand Up @@ -667,11 +672,11 @@ private function resolveCookieForm(
/**
* @throws AbortException
*/
private function createCookieSuggestionFromVirtualId(
string $virtualId,
private function createVirtualCookieSuggestion(
string $cookieId,
bool $uiActionsAllowed,
): bool {
$cookieView = $this->queryBus->dispatch(GetCookieByIdQuery::create($virtualId));
): ?string {
$cookieView = $this->queryBus->dispatch(GetCookieByIdQuery::create($cookieId));

if (!$cookieView instanceof CookieView) {
if ($uiActionsAllowed) {
Expand All @@ -680,19 +685,21 @@ private function createCookieSuggestionFromVirtualId(
$this->redirectIfNotAjax();
}

return false;
return null;
}

try {
$cookieSuggestionId = CookieSuggestionId::new()->toString();

$this->commandBus->dispatch(CreateCookieSuggestionCommand::create(
$this->projectView->id->toString(),
$cookieView->name->value(),
$cookieView->domain->value() ?: $this->projectView->domain->value(),
[],
$virtualId,
$cookieSuggestionId,
));

return true;
return $cookieSuggestionId;
} catch (Throwable $e) {
if (!$e instanceof DomainException) {
$this->logger->error((string) $e);
Expand All @@ -704,7 +711,7 @@ private function createCookieSuggestionFromVirtualId(
$this->redirectIfNotAjax();
}

return false;
return null;
}
}
}

0 comments on commit e78323d

Please sign in to comment.