@@ -50,7 +50,7 @@ class Document
5050 * With a fresh instance of this document, or a conducted change, this flag gets set to TRUE again.
5151 * When retrieved from the storage, or successfully set to the storage, it's FALSE.
5252 *
53- * @var boolean
53+ * @var bool
5454 */
5555 protected $ dirty = true ;
5656
@@ -60,7 +60,7 @@ class Document
6060 * @param string $id
6161 * @param int $version
6262 */
63- public function __construct (AbstractType $ type , array $ data = null , $ id = null , $ version = null )
63+ public function __construct (AbstractType $ type , ? array $ data = null , ? string $ id = null , ? int $ version = null )
6464 {
6565 $ this ->type = $ type ;
6666 $ this ->data = $ data ;
@@ -84,10 +84,11 @@ public function __clone()
8484 /**
8585 * Stores this document. If ID is given, PUT will be used; else POST
8686 *
87- * @throws ElasticSearchException
8887 * @return void
88+ * @throws \Neos\Flow\Http\Exception
89+ * @throws ElasticSearchException
8990 */
90- public function store ()
91+ public function store (): void
9192 {
9293 if ($ this ->id !== null ) {
9394 $ method = 'PUT ' ;
@@ -96,28 +97,15 @@ public function store()
9697 $ method = 'POST ' ;
9798 $ path = '' ;
9899 }
99- $ response = $ this ->request ($ method , $ path , [], json_encode ($ this ->data ));
100+
101+ $ response = $ this ->request ($ method , $ path , [], json_encode ($ this ->getData ()));
100102 $ treatedContent = $ response ->getTreatedContent ();
101103
102104 $ this ->id = $ treatedContent ['_id ' ];
103105 $ this ->version = $ treatedContent ['_version ' ];
104106 $ this ->dirty = false ;
105107 }
106108
107- /**
108- * @param string $method
109- * @param string $path
110- * @param array $arguments
111- * @param string $content
112- * @return Response
113- * @throws ElasticSearchException
114- * @throws \Neos\Flow\Http\Exception
115- */
116- protected function request (string $ method , ?string $ path = null , array $ arguments = [], ?string $ content = null ): Response
117- {
118- return $ this ->type ->request ($ method , $ path , $ arguments , $ content );
119- }
120-
121109 /**
122110 * @return boolean
123111 */
@@ -126,15 +114,6 @@ public function isDirty(): bool
126114 return $ this ->dirty ;
127115 }
128116
129- /**
130- * @param boolean $dirty
131- * @return void
132- */
133- protected function setDirty (bool $ dirty = true ): void
134- {
135- $ this ->dirty = $ dirty ;
136- }
137-
138117 /**
139118 * @return int
140119 */
@@ -150,6 +129,7 @@ public function getVersion(): int
150129 */
151130 public function getData (): array
152131 {
132+ $ this ->data [Mapping::NEOS_TYPE_FIELD ] = $ this ->type ->getName ();
153133 return $ this ->data ;
154134 }
155135
@@ -179,7 +159,7 @@ public function getId(): string
179159 * @return mixed
180160 * @throws ElasticSearchException
181161 */
182- public function getField (string $ fieldName , $ silent = false )
162+ public function getField (string $ fieldName , bool $ silent = false )
183163 {
184164 if (!array_key_exists ($ fieldName , $ this ->data ) && $ silent === false ) {
185165 throw new ElasticSearchException (sprintf ('The field %s was not present in data of document in %s/%s. ' , $ fieldName , $ this ->type ->getIndex ()->getName (), $ this ->type ->getName ()), 1340274696 );
@@ -195,4 +175,28 @@ public function getType(): AbstractType
195175 {
196176 return $ this ->type ;
197177 }
178+
179+ /**
180+ * @param string $method
181+ * @param string $path
182+ * @param array $arguments
183+ * @param string $content
184+ * @return Response
185+ * @throws ElasticSearchException
186+ * @throws \Neos\Flow\Http\Exception
187+ */
188+ protected function request (string $ method , ?string $ path = null , array $ arguments = [], ?string $ content = null ): Response
189+ {
190+ return $ this ->type ->request ($ method , $ path , $ arguments , $ content );
191+ }
192+
193+ /**
194+ * @param boolean $dirty
195+ * @return void
196+ */
197+ protected function setDirty (bool $ dirty = true ): void
198+ {
199+ $ this ->dirty = $ dirty ;
200+ }
201+
198202}
0 commit comments