Skip to content

Commit

Permalink
EZP-24270: index value as date (instead of integer)
Browse files Browse the repository at this point in the history
  • Loading branch information
pspanja committed May 4, 2015
1 parent 1b8aa4b commit 402bf2d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
30 changes: 26 additions & 4 deletions eZ/Publish/API/Repository/Tests/FieldType/DateIntegrationTest.php
Expand Up @@ -342,13 +342,35 @@ public function providerForTestIsNotEmptyValue()

protected function getValidSearchValueOne()
{
$date = new DateTime();
return $date->setTimestamp( 123456 )->setTime( 0, 0, 0 )->getTimestamp();
$date = new DateTime( "1970-01-02" );
return $date->getTimestamp();
}

protected function getValidSearchValueTwo()
{
$date = new DateTime();
return $date->setTimestamp( 234567 )->setTime( 0, 0, 0 )->getTimestamp();
$date = new DateTime( "1970-01-03" );
return $date->getTimestamp();
}

protected function getSearchTargetValueOne()
{
// Handling Legacy Search Engine, which stores Checkbox value as integer
if ( ltrim( get_class( $this->getSetupFactory() ), '\\' ) === 'eZ\Publish\API\Repository\Tests\SetupFactory\Legacy' )
{
return $this->getValidSearchValueOne();
}

return "1970-01-02";
}

protected function getSearchTargetValueTwo()
{
// Handling Legacy Search Engine, which stores Checkbox value as integer
if ( ltrim( get_class( $this->getSetupFactory() ), '\\' ) === 'eZ\Publish\API\Repository\Tests\SetupFactory\Legacy' )
{
return $this->getValidSearchValueTwo();
}

return "1970-01-03";
}
}
13 changes: 10 additions & 3 deletions eZ/Publish/Core/FieldType/Date/SearchField.php
Expand Up @@ -12,6 +12,7 @@
use eZ\Publish\SPI\Persistence\Content\Field;
use eZ\Publish\SPI\FieldType\Indexable;
use eZ\Publish\SPI\Search;
use DateTime;

/**
* Indexable definition for Date field type
Expand All @@ -27,11 +28,17 @@ class SearchField implements Indexable
*/
public function getIndexData( Field $field )
{
// The field type stores date value as a timestamp of the start of the day in the
// environment's timezone.
// We format this as Y-m-d and add Z to signify UTC (zero offset).
$dateTime = new DateTime();
$dateTime->setTimestamp( $field->value->data["timestamp"] );

return array(
new Search\Field(
'value',
$field->value->data["timestamp"],
new Search\FieldType\IntegerField()
$dateTime->format( "Y-m-d\\Z" ),
new Search\FieldType\DateField()
),
);
}
Expand All @@ -44,7 +51,7 @@ public function getIndexData( Field $field )
public function getIndexDefinition()
{
return array(
'value' => new Search\FieldType\IntegerField(),
'value' => new Search\FieldType\DateField(),
);
}

Expand Down

0 comments on commit 402bf2d

Please sign in to comment.