Skip to content

Commit

Permalink
* Command::perform - changed request type from PUT to POST
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Oct 26, 2015
1 parent b097fdf commit 7e95cbe
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 42 deletions.
30 changes: 10 additions & 20 deletions src/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ public function isScenarioDefault()
* Gets a record by its primary key.
*
* @param mixed $primaryKey the primaryKey value
* @param array $options options given in this parameter are passed to elasticsearch
* as request URI parameters.
* Please refer to the [elasticsearch documentation](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html)
* for more details on these options.
* @param array $options options given in this parameter are passed to API.
*
* @return null|static The record instance or null if it was not found.
*/
Expand All @@ -94,14 +91,12 @@ public static function get($primaryKey = null, $options = [])
/**
* This method defines the attribute that uniquely identifies a record.
*
* The primaryKey for elasticsearch documents is the `_id` field by default. This field is not part of the
* The primaryKey for HiArt objects is the `id` field by default. This field is not part of the
* ActiveRecord attributes so you should never add `_id` to the list of [[attributes()|attributes]].
*
* You may override this method to define the primary key name when you have defined
* [path mapping](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html)
* for the `_id` field so that it is part of the `_source` and thus part of the [[attributes()|attributes]].
* You may override this method to define the primary key name.
*
* Note that elasticsearch only supports _one_ attribute to be the primary key. However to match the signature
* Note that HiArt only supports _one_ attribute to be the primary key. However to match the signature
* of the [[\yii\db\ActiveRecordInterface|ActiveRecordInterface]] this methods returns an array instead of a
* single string.
*
Expand Down Expand Up @@ -176,18 +171,16 @@ public function getPrimaryValue()
*
* This method must be overridden by child classes to define available attributes.
*
* Attributes are names of fields of the corresponding elasticsearch document.
* The primaryKey for elasticsearch documents is the `_id` field by default which is not part of the attributes.
* You may define [path mapping](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html)
* for the `_id` field so that it is part of the `_source` fields and thus becomes part of the attributes.
* Attributes are names of fields of the corresponding API object.
* The primaryKey for HiArt documents is the `id` field by default which is not part of the attributes.
*
* @throws \yii\base\InvalidConfigException if not overridden in a child class.
*
* @return string[] list of attribute names.
*/
public function attributes()
{
throw new InvalidConfigException('The attributes() method of Hiresource ActiveRecord has to be implemented by child classes.');
throw new InvalidConfigException('The attributes() method of HiArt ActiveRecord has to be implemented by child classes.');
}

/**
Expand Down Expand Up @@ -432,10 +425,7 @@ public function getIsNewRecord()
}

/**
* This method has no effect in Elasticsearch ActiveRecord.
*
* Elasticsearch ActiveRecord uses [native Optimistic locking](http://www.elastic.co/guide/en/elasticsearch/guide/current/optimistic-concurrency-control.html).
* See [[update()]] for more details.
* This method has no effect in HiArt ActiveRecord.
*/
public function optimisticLock()
{
Expand All @@ -445,11 +435,11 @@ public function optimisticLock()
/**
* Destroys the relationship in current model.
*
* This method is not supported by elasticsearch.
* This method is not supported by HiArt.
*/
public function unlinkAll($name, $delete = false)
{
throw new NotSupportedException('unlinkAll() is not supported by elasticsearch, use unlink() instead.');
throw new NotSupportedException('unlinkAll() is not supported by HiArt, use unlink() instead.');
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class Command extends Component
public $db;
/**
* @var string|array the indexes to execute the query on. Defaults to null meaning all indexes
*
* @see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search.html#search-multi-index
*/
public $index;
/**
Expand Down Expand Up @@ -118,6 +116,6 @@ public function update($index, $id, $data, $options = [])
*/
public function perform($action, $options = [])
{
return $this->db->put($action, $options);
return $this->db->post($action, $options);
}
}
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ protected function httpRequest($method, $url, $requestBody = null, $raw = false)
$body = '';
$options = [
CURLOPT_URL => $url,
CURLOPT_USERAGENT => 'Yii Framework ' . Yii::getVersion() . __CLASS__,
CURLOPT_USERAGENT => 'Yii Framework ' . Yii::getVersion() . ' (HiArt)',
//CURLOPT_ENCODING => 'UTF-8',
# CURLOPT_USERAGENT => 'curl/0.00 (php 5.x; U; en)',
CURLOPT_RETURNTRANSFER => false,
Expand Down
34 changes: 22 additions & 12 deletions src/DebugAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use yii\web\Response;

/**
* Debug Action is used by [[DebugPanel]] to perform HiActiveResource queries using ajax.
* Debug Action is used by [[DebugPanel]] to perform HiArt queries using ajax.
*/
class DebugAction extends Action
{
Expand Down Expand Up @@ -47,28 +47,38 @@ public function run($logId, $tag)
}
$message = $timings[$logId][1];
if (($pos = mb_strpos($message, '#')) !== false) {
$url = mb_substr($message, 0, $pos);
$url = mb_substr($message, 0, $pos);
$body = mb_substr($message, $pos + 1);
} else {
$url = $message;
$url = $message;
$body = null;
}
$method = mb_substr($url, 0, $pos = mb_strpos($url, ' '));
$url = mb_substr($url, $pos + 1);
$url = mb_substr($url, $pos + 1);

parse_str($body, $options);

/* @var $db Connection */
$db = \Yii::$app->get($this->db);
$db = \Yii::$app->get($this->db);
$time = microtime(true);
switch ($method) {
case 'GET': $result = $db->get($url, $options, $body, true); break;
case 'POST': $result = $db->post($url, $options, $body, true); break;
case 'PUT': $result = $db->put($url, $options, $body, true); break;
case 'DELETE': $result = $db->delete($url, $options, $body, true); break;
case 'HEAD': $result = $db->head($url, $options, $body); break;
case 'GET':
$result = $db->get($url, $options, $body, true);
break;
case 'POST':
$result = $db->post($url, $options, $body, true);
break;
case 'PUT':
$result = $db->put($url, $options, $body, true);
break;
case 'DELETE':
$result = $db->delete($url, $options, $body, true);
break;
case 'HEAD':
$result = $db->head($url, $options, $body);
break;
default:
throw new NotSupportedException("Request method '$method' is not supported by elasticsearch.");
throw new NotSupportedException("Request method '$method' is not supported by HiArt.");
}
$time = microtime(true) - $time;

Expand All @@ -81,7 +91,7 @@ public function run($logId, $tag)
Yii::$app->response->format = Response::FORMAT_JSON;

return [
'time' => sprintf('%.1f ms', $time * 1000),
'time' => sprintf('%.1f ms', $time * 1000),
'result' => $result,
];
}
Expand Down
12 changes: 6 additions & 6 deletions src/DebugPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use yii\web\View;

/**
* Debugger panel that collects and displays HiActiveResource queries performed.
* Debugger panel that collects and displays HiArt queries performed.
*/
class DebugPanel extends Panel
{
Expand All @@ -40,7 +40,7 @@ public function init()
*/
public function getName()
{
return 'HiActiveResource';
return 'HiArt';
}

/**
Expand All @@ -59,7 +59,7 @@ public function getSummary()
$output = <<<HTML
<div class="yii-debug-toolbar-block">
<a href="$url" title="Executed $queryCount queries which took $queryTime.">
ES <span class="label">$queryCount</span> <span class="label">$queryTime</span>
HiArt <span class="label">$queryCount</span> <span class="label">$queryTime</span>
</a>
</div>
HTML;
Expand Down Expand Up @@ -116,7 +116,7 @@ public function getDetail()
<td style="width: 75%;"><div><b>$url_encoded</b><br/><p>$body_encoded</p>$traceString</div></td>
<td style="width: 15%;">$runLink</td>
</tr>
<tr style="display: none;" class="elastic-wrapper" data-id="$i">
<tr style="display: none;" class="hiart-wrapper" data-id="$i">
<td class="time"></td><td colspan="3" class="result"></td>
</tr>
HTML;
Expand Down Expand Up @@ -157,7 +157,7 @@ function syntaxHighlight(json) {
event.preventDefault();
var id = $(this).data('id');
var result = $('.elastic-wrapper[data-id=' + id +']');
var result = $('.hiart-wrapper[data-id=' + id +']');
result.find('.result').html('Sending request...');
result.show();
$.ajax({
Expand Down Expand Up @@ -189,7 +189,7 @@ function syntaxHighlight(json) {
, View::POS_READY);

return <<<HTML
<h1>HiResource Queries</h1>
<h1>HiArt Queries</h1>
<table class="table table-condensed table-bordered table-striped table-hover" style="table-layout: fixed;">
<thead>
Expand Down

0 comments on commit 7e95cbe

Please sign in to comment.