From b996c48656d9038ae56af6ff3a36765e15c7d253 Mon Sep 17 00:00:00 2001 From: Mihai Lucian Neagu Date: Thu, 15 Dec 2016 11:03:31 +0200 Subject: [PATCH] Added version as metadata field. (#715) * Added version as metadata field. * Added proper annotations and fixed PSR2 style issues. * Changed the line ending character from CRLF to LF --- Annotation/Version.php | 37 +++++++++++++++++++++++++++++++++++++ Mapping/DocumentParser.php | 3 +++ 2 files changed, 40 insertions(+) create mode 100644 Annotation/Version.php diff --git a/Annotation/Version.php b/Annotation/Version.php new file mode 100644 index 00000000..60d00c3a --- /dev/null +++ b/Annotation/Version.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Annotation; + +/** + * Associates document property with _version meta-field. + * + * @Annotation + * @Target("PROPERTY") + */ +final class Version implements MetaField +{ + /** + * {@inheritdoc} + */ + public function getName() + { + return '_version'; + } + + /** + * {@inheritdoc} + */ + public function getSettings() + { + return []; + } +} diff --git a/Mapping/DocumentParser.php b/Mapping/DocumentParser.php index d73bae70..d80f5e6b 100644 --- a/Mapping/DocumentParser.php +++ b/Mapping/DocumentParser.php @@ -37,6 +37,7 @@ class DocumentParser const PARENT_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\ParentDocument'; const TTL_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Ttl'; const ROUTING_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Routing'; + const VERSION_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Version'; /** * @var Reader Used to read document annotations. @@ -177,6 +178,7 @@ private function getMetaFieldAnnotationData($property) $annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::PARENT_ANNOTATION); $annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::TTL_ANNOTATION); $annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::ROUTING_ANNOTATION); + $annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::VERSION_ANNOTATION); if ($annotation === null) { return null; @@ -358,6 +360,7 @@ private function registerAnnotations() 'ParentDocument', 'Ttl', 'Routing', + 'Version', ]; foreach ($annotations as $annotation) {