-
Notifications
You must be signed in to change notification settings - Fork 737
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
Version option deprecation fix and replacements #1803
Changes from 5 commits
cc5d010
f1fc761
0fae95e
955d3ed
d15845e
edccc89
ac3f4ad
df38de8
2254853
d794d2b
8863cee
af0b1d5
1497fff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -65,6 +65,71 @@ public function getIndex() | |||||
} | ||||||
|
||||||
/** | ||||||
* Sets the sequence number of a document for use with optimistic concurrency control. | ||||||
* | ||||||
* @param int $number Sequence Number | ||||||
* | ||||||
* @return $this | ||||||
* | ||||||
* @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/optimistic-concurrency-control.html | ||||||
*/ | ||||||
public function setSequenceNumber($number) | ||||||
{ | ||||||
return $this->setParam('if_seq_no', $number); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Returns document version. | ||||||
* | ||||||
* @return int|string Document version | ||||||
*/ | ||||||
public function getSequenceNumber() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
return $this->getParam('if_seq_no'); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @return bool | ||||||
*/ | ||||||
public function hasSequenceNumber() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
return $this->hasParam('if_seq_no'); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Sets the prmary term of a document for use with optimistic concurrency control. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* @param int $term Primary Term | ||||||
* | ||||||
* @return $this | ||||||
* | ||||||
* @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/optimistic-concurrency-control.html | ||||||
*/ | ||||||
public function setPrimaryTerm($term) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
return $this->setParam('if_primary_term', $term); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Returns document version. | ||||||
* | ||||||
* @return int|string Document version | ||||||
*/ | ||||||
public function getPrimaryTerm() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
return $this->getParam('if_primary_term'); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @return bool | ||||||
*/ | ||||||
public function hasPrimaryTerm() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
return $this->hasParam('if_primary_term'); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @deprecated | ||||||
* Sets the version of a document for use with optimistic concurrency control. | ||||||
* | ||||||
* @param int $version Document version | ||||||
|
@@ -75,10 +140,13 @@ public function getIndex() | |||||
*/ | ||||||
public function setVersion($version) | ||||||
{ | ||||||
return $this->setParam('version', (int) $version); | ||||||
\trigger_error('Elastica\AbstractUpdateAction::setVersion is deprecated. Use Elastica\AbstractUpdateAction::setSequenceNumber and Elastica\AbstractUpdateAction::setPrimaryTerm instead.', E_USER_DEPRECATED); | ||||||
|
||||||
return $this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @deprecated | ||||||
* Returns document version. | ||||||
* | ||||||
* @return int|string Document version | ||||||
|
@@ -89,6 +157,7 @@ public function getVersion() | |||||
} | ||||||
|
||||||
/** | ||||||
* @deprecated | ||||||
* @return bool | ||||||
*/ | ||||||
public function hasVersion() | ||||||
|
@@ -97,6 +166,7 @@ public function hasVersion() | |||||
} | ||||||
|
||||||
/** | ||||||
* @deprecated | ||||||
* Sets the version_type of a document | ||||||
* Default in ES is internal, but you can set to external to use custom versioning. | ||||||
* | ||||||
|
@@ -106,10 +176,13 @@ public function hasVersion() | |||||
*/ | ||||||
public function setVersionType($versionType) | ||||||
{ | ||||||
return $this->setParam('version_type', $versionType); | ||||||
\trigger_error('Elastica\AbstractUpdateAction::setVersionType is deprecated. Use Elastica\AbstractUpdateAction::setSequenceNumber and Elastica\AbstractUpdateAction::setPrimaryTerm instead.', E_USER_DEPRECATED); | ||||||
|
||||||
return $this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @deprecated | ||||||
* Returns document version type. | ||||||
* | ||||||
* @return int|string Document version type | ||||||
|
@@ -120,6 +193,7 @@ public function getVersionType() | |||||
} | ||||||
|
||||||
/** | ||||||
* @deprecated | ||||||
* @return bool | ||||||
*/ | ||||||
public function hasVersionType() | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,8 +277,8 @@ public function updateDocument($id, $data, $index, array $options = []): Respons | |
|
||
$docOptions = $data->getOptions( | ||
[ | ||
'version', | ||
'version_type', | ||
Comment on lines
-280
to
-281
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems the right fix as this not documented anymore: https://www.elastic.co/guide/en/elasticsearch/reference/7.x/docs-update.html |
||
'if_seq_no', | ||
'if_primary_term', | ||
'routing', | ||
'percolate', | ||
'parent', | ||
|
@@ -311,8 +311,11 @@ public function updateDocument($id, $data, $index, array $options = []): Respons | |
&& ($data->isAutoPopulate() || $this->getConfigValue(['document', 'autoPopulate'], false)) | ||
) { | ||
$responseData = $response->getData(); | ||
if (isset($responseData['_version'])) { | ||
$data->setVersion($responseData['_version']); | ||
Comment on lines
-314
to
-315
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure this should be removed finally. As it's still documented as returned. |
||
if (isset($responseData['_seq_no'])) { | ||
$data->setSequenceNumber($responseData['_seq_no']); | ||
} | ||
if (isset($responseData['_primary_term'])) { | ||
$data->setPrimaryTerm($responseData['_primary_term']); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,8 +215,11 @@ public function addDocument(Document $doc): Response | |
if (isset($data['_id']) && !$doc->hasId()) { | ||
$doc->setId($data['_id']); | ||
} | ||
if (isset($data['_version'])) { | ||
$doc->setVersion($data['_version']); | ||
Comment on lines
-218
to
-219
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure this should be removed finally. As it's still documented as returned. |
||
if (isset($responseData['_seq_no'])) { | ||
$doc->setSequenceNumber($responseData['_seq_no']); | ||
} | ||
if (isset($responseData['_primary_term'])) { | ||
$doc->setPrimaryTerm($responseData['_primary_term']); | ||
} | ||
} | ||
|
||
|
@@ -272,10 +275,7 @@ public function getDocument($id, array $options = []): Document | |
$data = []; | ||
} | ||
|
||
$document = new Document($id, $data, $this->getName()); | ||
$document->setVersion($result['_version']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure this should be removed finally. As it's still documented as returned. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll put back setVersion, just remove it for a document update |
||
|
||
return $document; | ||
return new Document($id, $data, $this->getName()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was debating doing that since the param for the document update is different, I think it needs to be separated between what we get back and what is sent for a document update |
||
} | ||
|
||
/** | ||
|
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.