Commit 6d0f1e4c by Carsten Brandt

improved error reporting

parent 5dca1257
...@@ -44,8 +44,6 @@ use yii\helpers\StringHelper; ...@@ -44,8 +44,6 @@ use yii\helpers\StringHelper;
*/ */
class ActiveRecord extends BaseActiveRecord class ActiveRecord extends BaseActiveRecord
{ {
const PRIMARY_KEY_NAME = 'id';
private $_id; private $_id;
private $_score; private $_score;
private $_version; private $_version;
...@@ -471,13 +469,18 @@ class ActiveRecord extends BaseActiveRecord ...@@ -471,13 +469,18 @@ class ActiveRecord extends BaseActiveRecord
// TODO do this via command // TODO do this via command
$url = [static::index(), static::type(), '_bulk']; $url = [static::index(), static::type(), '_bulk'];
$response = static::getDb()->post($url, [], $bulk); $response = static::getDb()->post($url, [], $bulk);
$n=0; $n=0;
$errors = [];
foreach($response['items'] as $item) { foreach($response['items'] as $item) {
if ($item['update']['ok']) { if (isset($item['update']['error'])) {
$errors[] = $item['update'];
} elseif ($item['update']['ok']) {
$n++; $n++;
} }
} }
if (!empty($errors)) {
throw new Exception(__METHOD__ . ' failed updating records counters.', $errors);
}
return $n; return $n;
} }
...@@ -521,11 +524,17 @@ class ActiveRecord extends BaseActiveRecord ...@@ -521,11 +524,17 @@ class ActiveRecord extends BaseActiveRecord
$url = [static::index(), static::type(), '_bulk']; $url = [static::index(), static::type(), '_bulk'];
$response = static::getDb()->post($url, [], $bulk); $response = static::getDb()->post($url, [], $bulk);
$n=0; $n=0;
$errors = [];
foreach($response['items'] as $item) { foreach($response['items'] as $item) {
if ($item['delete']['found'] && $item['delete']['ok']) { if (isset($item['delete']['error'])) {
$errors[] = $item['delete'];
} elseif ($item['delete']['found'] && $item['delete']['ok']) {
$n++; $n++;
} }
} }
if (!empty($errors)) {
throw new Exception(__METHOD__ . ' failed deleting records.', $errors);
}
return $n; return $n;
} }
} }
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