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

fix: allow null in archive timestamp #1318

Merged
merged 1 commit into from
Feb 6, 2025
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
2 changes: 1 addition & 1 deletion library/PostObject/Date/CachedTimestampResolver.php
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ public function __construct(
*
* @return int
*/
public function resolve(): int
public function resolve(): ?int
{
$cacheKey = "{$this->postObject->getBlogId()}_{$this->postObject->getId()}";

10 changes: 7 additions & 3 deletions library/PostObject/Date/TimestampResolver.php
Original file line number Diff line number Diff line change
@@ -31,29 +31,33 @@ public function __construct(
*
* @return int
*/
public function resolve(): int
public function resolve(): ?int
{
$archiveDateSetting = $this->archiveDateSetting->resolve();

if (in_array($archiveDateSetting, $this->defaultTimestamps)) {
return $this->getDefaultTimestamp($archiveDateSetting);
}

if ($archiveDateSetting === 'none') {
return null;
}

return $this->getDateMetaValue($archiveDateSetting);
}

/**
* Get the date meta value.
*/
private function getDateMetaValue(string $archiveDateSetting): int
private function getDateMetaValue(string $archiveDateSetting): ?int
{
$metaValue = $this->wpService->getPostMeta($this->postObject->getId(), $archiveDateSetting, true);

if ($metaValue) {
return strtotime($metaValue);
}

return 0;
return null;
}

/**
2 changes: 1 addition & 1 deletion library/PostObject/Date/TimestampResolverInterface.php
Original file line number Diff line number Diff line change
@@ -9,5 +9,5 @@ interface TimestampResolverInterface
*
* @return int
*/
public function resolve(): int;
public function resolve(): ?int;
}
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
2 changes: 1 addition & 1 deletion library/PostObject/Decorators/IconResolvingPostObject.php
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->timestampResolver->resolve();
}
2 changes: 1 addition & 1 deletion library/PostObject/Decorators/PostObjectFromOtherBlog.php
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
2 changes: 1 addition & 1 deletion library/PostObject/Decorators/PostObjectFromWpPost.php
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
4 changes: 2 additions & 2 deletions library/PostObject/PostObject.php
Original file line number Diff line number Diff line change
@@ -93,9 +93,9 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return 0;
return null;
}

/**
4 changes: 2 additions & 2 deletions library/PostObject/PostObject.test.php
Original file line number Diff line number Diff line change
@@ -79,9 +79,9 @@ public function testGetBlogIdReturns1()
/**
* @testdox getArchiveDateTimestamp() returns 0
*/
public function testGetArchiveDateTimestampReturns0()
public function testGetArchiveDateTimestampReturnsNull()
{
$this->assertEquals(0, $this->instance->getArchiveDateTimestamp());
$this->assertEquals(null, $this->instance->getArchiveDateTimestamp());
}

/**
2 changes: 1 addition & 1 deletion library/PostObject/PostObjectInterface.php
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ public function getModifiedTime(bool $gmt = false): int;
*
* @return int
*/
public function getArchiveDateTimestamp(): int;
public function getArchiveDateTimestamp(): ?int;

/**
* Get the post object date format.