Commit 19224e74 by Carsten Brandt

Elasticsearch, allow custom options for update+delete

including support for optimistic locking (#1313) fixes #5758
parent de2064d9
......@@ -6,6 +6,8 @@ Yii Framework 2 elasticsearch extension Change Log
- Bug #5662: Elasticsearch AR updateCounters() now uses explicitly `groovy` script for updating making it compatible with ES >1.3.0 (cebe)
- Bug #6065: `ActiveRecord::unlink()` was failing in some situations when working with relations via array valued attributes (cebe)
- Enh #5758: Allow passing custom options to `ActiveRecord::update()` and `::delete()` including support for routing needed for updating records with parent relation (cebe)
- Enh: Add support for optimistic locking (cebe)
2.0.0 October 12, 2014
......
......@@ -220,11 +220,18 @@ class Command extends Component
* @return mixed
* @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html
*/
// public function update($index, $type, $id, $data, $options = [])
// {
// // TODO implement
//// return $this->db->delete([$index, $type, $id], $options);
// }
public function update($index, $type, $id, $data, $options = [])
{
$body = [
'doc' => empty($data) ? new \stdClass() : $data,
];
if (isset($options["detect_noop"])) {
$body["detect_noop"] = $options["detect_noop"];
unset($options["detect_noop"]);
}
return $this->db->post([$index, $type, $id, '_update'], $options, Json::encode($body));
}
// TODO bulk http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html
......
......@@ -198,7 +198,6 @@ class Connection extends Component
public function get($url, $options = [], $body = null, $raw = false)
{
$this->open();
return $this->httpRequest('GET', $this->createUrl($url, $options), $body, $raw);
}
......@@ -215,7 +214,6 @@ class Connection extends Component
public function head($url, $options = [], $body = null)
{
$this->open();
return $this->httpRequest('HEAD', $this->createUrl($url, $options), $body);
}
......@@ -233,7 +231,6 @@ class Connection extends Component
public function post($url, $options = [], $body = null, $raw = false)
{
$this->open();
return $this->httpRequest('POST', $this->createUrl($url, $options), $body, $raw);
}
......@@ -251,7 +248,6 @@ class Connection extends Component
public function put($url, $options = [], $body = null, $raw = false)
{
$this->open();
return $this->httpRequest('PUT', $this->createUrl($url, $options), $body, $raw);
}
......@@ -269,7 +265,6 @@ class Connection extends Component
public function delete($url, $options = [], $body = null, $raw = false)
{
$this->open();
return $this->httpRequest('DELETE', $this->createUrl($url, $options), $body, $raw);
}
......@@ -319,7 +314,7 @@ class Connection extends Component
$body = '';
$options = [
CURLOPT_USERAGENT => 'Yii Framework ' . Yii::getVersion() . __CLASS__,
CURLOPT_USERAGENT => 'Yii Framework ' . Yii::getVersion() . ' ' . __CLASS__,
CURLOPT_RETURNTRANSFER => false,
CURLOPT_HEADER => false,
// http://www.php.net/manual/en/function.curl-setopt.php#82418
......@@ -327,7 +322,6 @@ class Connection extends Component
CURLOPT_WRITEFUNCTION => function ($curl, $data) use (&$body) {
$body .= $data;
return mb_strlen($data, '8bit');
},
CURLOPT_HEADERFUNCTION => function ($curl, $data) use (&$headers) {
......@@ -336,7 +330,6 @@ class Connection extends Component
$headers[strtolower(substr($row, 0, $pos))] = trim(substr($row, $pos + 1));
}
}
return mb_strlen($data, '8bit');
},
CURLOPT_CUSTOMREQUEST => $method,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment