Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set null for searchitem #166

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/Services/Indexer/SearchItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ final class SearchItem

private bool $inSitemap = true;

private ?DateTime $publicationDate;
private ?DateTime $publicationDate = null;

private ?DateTime $lastUpdated;
private ?DateTime $lastUpdated = null;

private int $priority = 1;

Expand Down Expand Up @@ -146,12 +146,7 @@ public function content(): ?string
*/
public function publicationDate(): ?string
{
$time = $this->publicationDate ?? $this->lastUpdated;
if ($time === null) {
return null;
}

return $time->format(DateTime::ATOM);
return $this->toDateString($this->publicationDate ?? $this->lastUpdated);
}

/**
Expand All @@ -162,12 +157,7 @@ public function publicationDate(): ?string
*/
public function lastUpdated(): ?string
{
$time = $this->lastUpdated ?? $this->publicationDate;
if ($time === null) {
return null;
}

return $time->format(DateTime::ATOM);
return $this->toDateString($this->lastUpdated ?? $this->publicationDate);
}

public function customValues(): ?array
Expand All @@ -189,4 +179,13 @@ public function sitemap(): bool
{
return $this->inSitemap;
}

private function toDateString(?DateTime $date): ?string
{
if ($date === null) {
return null;
}

return $date->format(DateTime::ATOM);
}
}
Loading