Skip to content

IBX-11818: added fallback to null value when key 'timestamp' not exists in $value->data array#757

Open
papcio122 wants to merge 5 commits into
5.0from
IBX-11818_empty_ibexa_datetime-field-causing-error
Open

IBX-11818: added fallback to null value when key 'timestamp' not exists in $value->data array#757
papcio122 wants to merge 5 commits into
5.0from
IBX-11818_empty_ibexa_datetime-field-causing-error

Conversation

@papcio122

Copy link
Copy Markdown
Contributor
🎫 Issue IBX-11818

Description:

\Ibexa\Core\Persistence\Legacy\Content\FieldValue\Converter\DateAndTimeConverter:toStorageValue()
throws an error of a missing array key when the content was created before the field was added to the content type.
Added fallback to null when the data array has no 'timestamp' key

@papcio122 papcio122 marked this pull request as draft May 29, 2026 08:06
@papcio122 papcio122 marked this pull request as ready for review June 3, 2026 08:14
@papcio122 papcio122 added Bug Something isn't working Ready for review labels Jun 3, 2026
@papcio122 papcio122 requested a review from a team June 3, 2026 08:15
Comment thread src/lib/Persistence/Legacy/Content/FieldValue/Converter/DateAndTimeConverter.php Outdated
@papcio122 papcio122 force-pushed the IBX-11818_empty_ibexa_datetime-field-causing-error branch from 22e8d03 to f08a3f5 Compare June 9, 2026 07:37
@papcio122 papcio122 requested a review from konradoboza June 9, 2026 08:17
* @group fieldType
* @group dateTime
*/
public function testToStorageValueNoTimestampKey(): void

@konradoboza konradoboza Jun 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also test if dataInt is properly populated with the timestamp if it exists.

@papcio122 papcio122 Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I referred to the actual usage of timestamp key which is in the condition in question. How is it covered?

@@ -32,7 +32,7 @@ public function toStorageValue(FieldValue $value, StorageFieldValue $storageFiel
{
// @todo: One should additionally store the timezone here. This could

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are SO CLOSE to this. Can we drop that comment? ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just remove it?
Or somehow store the timezone here? 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it.

Comment on lines +87 to +122
/**
* @group fieldType
* @group dateTime
*/
public function testToStorageValueNoTimestampKey(): void
{
$value = new FieldValue();
$value->data = [
'current_time' => $this->date->getTimestamp(),
'rfc850' => $this->date->format(DateTime::RFC850),
];
$value->sortKey = $this->date->getTimestamp();
$storageFieldValue = new StorageFieldValue();

$this->converter->toStorageValue($value, $storageFieldValue);
self::assertNull($storageFieldValue->dataInt);
self::assertSame($value->sortKey, $storageFieldValue->sortKeyInt);
self::assertSame('', $storageFieldValue->sortKeyString);
}

/**
* @group fieldType
* @group dateTime
*/
public function testToStorageValueValueDataNull(): void
{
$value = new FieldValue();
$value->data = null;
$value->sortKey = $this->date->getTimestamp();
$storageFieldValue = new StorageFieldValue();

$this->converter->toStorageValue($value, $storageFieldValue);
self::assertNull($storageFieldValue->dataInt);
self::assertSame($value->sortKey, $storageFieldValue->sortKeyInt);
self::assertSame('', $storageFieldValue->sortKeyString);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I see it right, the only difference for these tests is an assignment of $value->data. Can this be a data provider?

self::assertSame($storageFieldValue->sortKeyInt, $fieldValue->sortKey);
}

public function providerForTestToStorageValueMissingData()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a proper return type and PHPStan array shape.

Comment on lines +91 to +94
[
'current_time' => 1048633200,
'rfc850' => 'Thu, 01 Jan 2003 00:00:00 GMT',
],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to wrap it in several arrays?

@papcio122 papcio122 force-pushed the IBX-11818_empty_ibexa_datetime-field-causing-error branch from b96fb48 to b95c1c6 Compare June 9, 2026 14:30
@sonarqubecloud

sonarqubecloud Bot commented Jun 9, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants