-
Notifications
You must be signed in to change notification settings - Fork 208
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-EZP-27373: Error when edit empty not required date #1996
Fix-EZP-27373: Error when edit empty not required date #1996
Conversation
@@ -29,12 +29,17 @@ class SearchField implements Indexable | |||
*/ | |||
public function getIndexData(Field $field, FieldDefinition $fieldDefinition) | |||
{ | |||
$dateTime = new DateTime("@{$field->value->data['timestamp']}"); | |||
if ($field->value->data['timestamp']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timestamp equal to 0
is still a valid one (1 Jan 1970), though this code would not set it.
I would go for if (isset($field->value->data['timestamp']) && $field->value->data['timestamp'] !== '')
, because:
- AFAICS when not set, it is
null
there, soisset
solves it. timestamp
array key might not be set at all (probably doesn't happen though).- Unfortunately the string
'1495808222'
is also a valid timestamp, but''
is not.
However I've been wrong in such cases, so pinging @andrerom and @Nattfarinn :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alongosz You are definitely right. Thank you. I changed it as you proposed.
$dateTime = new DateTime("@{$field->value->data['timestamp']}"); | ||
$dataValue = $dateTime->format('Y-m-d\\Z'); | ||
} else { | ||
$dataValue = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable named $dataValue
looks weird. Rather $searchFieldValue
or just $value
.
@kmadejski I took a closer look at PRs and it looks like this is related to #1967 and #1992 as a follow-up on #1942. @gggeek You've mentioned in #1942 that you'd prefer here cast to int. |
@kmadejski See the other PR's above, there are some more cases to cover. |
Note: one of the cases involves |
@alongosz, @andrerom Correct me if I'm wrong, but it seems The same situation in case of |
@kmadejski you are right, and it's documented to only support int. |
@andrerom Thanks, I will prepare fix also for |
@kmadejski Ok, then also check Time, and make sure the originally issue fixed in #1942 is solved for all of them. |
@andrerom fixed also for |
@alongosz I changed validation in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Friday I had a feeling I've missed something important while reviewing this PR...
First of all, I wondered why our integration tests don't uncover this case. Well, it turns out we actually test content create with empty values, but not content publish, which triggers getIndexData
.
So here's the test to be added to eZ\Publish\API\Repository\Tests\FieldType\BaseIntegrationTest
:
/**
* Test that publishing (and thus indexing) content with an empty field value does not fail.
*
* @depends testCreateContentWithEmptyFieldValue
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $contentDraft
*/
public function testPublishContentWithEmptyFieldValue(Content $contentDraft)
{
$this->getRepository(false)->getContentService()->publishVersion(
$contentDraft->versionInfo
);
}
Second, I looked into how exactly Field
object is initialized and my change requests add unnecessary complexity, so they're wrong. Below there are correct simplifications with explanation as to why.
(@kmadejski please don't kill me... :-))
@@ -29,12 +29,17 @@ class SearchField implements Indexable | |||
*/ | |||
public function getIndexData(Field $field, FieldDefinition $fieldDefinition) | |||
{ | |||
$dateTime = new DateTime("@{$field->value->data['timestamp']}"); | |||
if (isset($field->value->data['timestamp']) && $field->value->data['timestamp'] !== '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ($field->value->data !== null)
is enough because:
DateConverter
ensures that thedata
property remainsnull
or is an array withtimestamp
key containing actual integer.- Content Mapper properly casts value set to
dataInt
retriveved from the db.
@@ -28,10 +29,17 @@ class SearchField implements Indexable | |||
*/ | |||
public function getIndexData(Field $field, FieldDefinition $fieldDefinition) | |||
{ | |||
if (isset($field->value->data['timestamp']) && $field->value->data['timestamp'] !== '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ($field->value->data !== null)
is enough because DateAndTime Converter ensures the same thing as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we are sure this only comes from storage and not user (via input validation and such)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we are sure this only comes from storage and not user (via input validation and such)?
Yes. getIndexData
is called by eZ\Publish\SPI\Search\Handler::indexContent
which always gets its content from eZ\Publish\SPI\Persistence\Content\Handler::load
@@ -28,10 +29,17 @@ class SearchField implements Indexable | |||
*/ | |||
public function getIndexData(Field $field, FieldDefinition $fieldDefinition) | |||
{ | |||
if ($field->value->data !== null && $field->value->data !== '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ($field->value->data !== null)
is enough because TimeConverter
also ensures data
remains null
if not set.
I've also found another bug related to this line. Not sure if this can be included here or should be a separate PR. @andrerom? Test cases for /**
* @return \eZ\Publish\API\Repository\Values\Content\VersionInfo
*/
public function testCreateContentWithZeroDate()
{
$fieldValue = DateValue::fromTimestamp(0);
$content = $this->createContent($fieldValue);
$loadedContent = $this->getRepository(false)->getContentService()->loadContentByContentInfo($content->contentInfo);
self::assertEquals($content, $loadedContent);
return $loadedContent->versionInfo;
}
/**
* @depends testPublishContentWithZeroDate
*
* @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
*/
public function testPublishContentWithZeroDate(VersionInfo $versionInfo)
{
$this->getRepository(false)->getContentService()->publishVersion($versionInfo);
} |
@alongosz don't worry, your advice are always very helpful, thank you! I'll fix it in few minutes. |
lets make that separate, this is already covering to many things (regression and second look at the original issue). Keep that small and we can fast track it and rebase this on top, if you require it you can temporarily set base branch to the new PR here. |
36ec684
to
1b62c5a
Compare
And we've uncovered two separate issues...
if (!isset($field->value['latitude'], $field->value['longitude'])) {
return null;
} These probably need to be separate PRs. |
Looks good now, but one control question on what we ended up with here:
Was Time and DateAndTime actually affected by the timezone issue solved in #1942? Or could they just have been kept as they where (as in just passing on the timezone, if there is one. aka only fix would be to make sure to check that data is set in DateAndTime). |
@andrerom In Should I implement something from things mentioned by @alongosz here: #1996 (comment)? |
Hmm, well you can, the second one is caused by tour new test, as this is depending on each other I suggest we end up with three commits that can be merged normally (not squashed):
|
It wasn't AFAIR. Anyway, I thought this would be a good improvement, but it's probably a little bit out of scope of PR. One could also argue that it's a BC break, but it's hard for me to imagine someone actually relying on unix timestamps in search index ;) |
1b62c5a
to
d419113
Compare
@kmadejski Almost. 1. you have 6 commits and not 3 :) and 2. while at it rebase on 6.7 which now has fix for symfony 3.3. |
86781e4
to
aa5c035
Compare
2ec906f
to
9712e75
Compare
Is that possible: this I have an This only happens with solr, not with legacy search. So currently ezdate cannot be optional :\ |
@slaci I checked it right now, content can be published without errors when is not |
JIRA issue: https://jira.ez.no/browse/EZP-27373
Description
If
Date
FieldType is used and Searchable setting is checked and also default value is set to Empty then it is impossible to save content without setting the value of this field.API returns an error as described in issue.