From 25dd79aa51e6b4a741c56bf9a400c1986f0f3619 Mon Sep 17 00:00:00 2001 From: Araz Date: Sat, 3 Jun 2023 12:38:33 +0330 Subject: [PATCH 1/2] Fix ES exception when a field missed in using `updateAllCounters`. --- ActiveRecord.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ActiveRecord.php b/ActiveRecord.php index 97dd11c8..e459eebd 100644 --- a/ActiveRecord.php +++ b/ActiveRecord.php @@ -252,7 +252,7 @@ public function getPrimaryKey($asArray = false) * @param mixed $value * @throws \yii\base\InvalidCallException when record is not new * @deprecated since 2.1.0 - */ + */0 public function setPrimaryKey($value) { $pk = static::primaryKey()[0]; @@ -720,7 +720,7 @@ public static function updateAllCounters($counters, $condition = []) foreach ($primaryKeys as $pk) { $script = ''; foreach ($counters as $counter => $value) { - $script .= "ctx._source.{$counter} += params.{$counter};\n"; + $script .= "ctx._source.{$counter} = (ctx._source.{$counter} == null ? 0 : ctx._source.{$counter}) + params.{$counter};\n"; } $bulkCommand->addAction(["update" => ["_id" => $pk]], [ 'script' => [ From befeb315d1f9952e41a1324ac5848ddba159e90c Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sun, 4 Jun 2023 11:32:40 +0400 Subject: [PATCH 2/2] Update ActiveRecord.php --- ActiveRecord.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ActiveRecord.php b/ActiveRecord.php index e459eebd..fbb73e67 100644 --- a/ActiveRecord.php +++ b/ActiveRecord.php @@ -252,7 +252,7 @@ public function getPrimaryKey($asArray = false) * @param mixed $value * @throws \yii\base\InvalidCallException when record is not new * @deprecated since 2.1.0 - */0 + */ public function setPrimaryKey($value) { $pk = static::primaryKey()[0];