From bb7b1b8f8e26c409f9c113a6bd459e3274e94599 Mon Sep 17 00:00:00 2001 From: Arsen Mirzaev Tatyano-Muradovich Date: Sun, 11 Apr 2021 02:39:51 +1000 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mirzaev/yii2/arangodb/ActiveQuery.php | 2 ++ mirzaev/yii2/arangodb/Migration.php | 2 +- mirzaev/yii2/arangodb/Query.php | 38 ++++++++++++++++----------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/mirzaev/yii2/arangodb/ActiveQuery.php b/mirzaev/yii2/arangodb/ActiveQuery.php index 60be2c2..b574cc5 100644 --- a/mirzaev/yii2/arangodb/ActiveQuery.php +++ b/mirzaev/yii2/arangodb/ActiveQuery.php @@ -103,9 +103,11 @@ class ActiveQuery extends Query implements ActiveQueryInterface public function all($db = null) { $statement = $this->createCommand($db); + $token = $this->getRawAql($statement); Yii::info($token, 'mirzaev\yii2\arangodb\Query::query'); + try { Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query'); $cursor = $statement->execute(); diff --git a/mirzaev/yii2/arangodb/Migration.php b/mirzaev/yii2/arangodb/Migration.php index a786c2a..6eec329 100644 --- a/mirzaev/yii2/arangodb/Migration.php +++ b/mirzaev/yii2/arangodb/Migration.php @@ -23,7 +23,7 @@ abstract class Migration extends Component implements MigrationInterface { parent::init(); - $this->db = Instance::ensure($this->db, Connection::class; + $this->db = Instance::ensure($this->db, Connection::class); } public function execute($aql, $bindValues = [], $params = []) diff --git a/mirzaev/yii2/arangodb/Query.php b/mirzaev/yii2/arangodb/Query.php index 5ef1a1b..8545b5d 100644 --- a/mirzaev/yii2/arangodb/Query.php +++ b/mirzaev/yii2/arangodb/Query.php @@ -819,16 +819,16 @@ class Query extends Component implements QueryInterface protected function genQuery($query = null, array $params = []) { // Инициализация - isset($query) ? $query : $query = $this; - $this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция')); + $query ?? $query = $this; + $this->in ?? $this->in = $this->collection ?? throw new Exception('Не найдена коллекция'); $this->for ?? $this->for = $this->in; - $this->collection ?? $this->collection = $this->in; + $this->collection ?? $this->collection = is_array($this->for) ? $this->in : $this->for; $params = array_merge($params, $query->params); $clauses = [ - static::genFor($query->for ?? $query->collection), - static::genIn($query->in ?? $query->collection, $query->traversals), + static::genFor($query->for), + static::genIn($query->in, $query->traversals), static::genLet($query->lets), $this->genForeach($query->foreach), $this->genWhere($query->where, $params), @@ -874,9 +874,11 @@ class Query extends Component implements QueryInterface public function all($db = null) { $statement = $this->createCommand($db); + $token = $this->getRawAql($statement); Yii::info($token, 'mirzaev\yii2\arangodb\Query::query'); + try { Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query'); $cursor = $statement->execute(); @@ -885,6 +887,7 @@ class Query extends Component implements QueryInterface Yii::endProfile($token, 'mirzaev\yii2\arangodb\Query::query'); throw new Exception($ex->getMessage(), (int) $ex->getCode(), $ex); } + return $this->prepareResult($cursor->getAll()); } @@ -894,10 +897,13 @@ class Query extends Component implements QueryInterface public function one($db = null) { $this->limit(1); + $statement = $this->createCommand($db); + $token = $this->getRawAql($statement); Yii::info($token, 'mirzaev\yii2\arangodb\Query::query'); + try { Yii::beginProfile($token, 'mirzaev\yii2\arangodb\Query::query'); $cursor = $statement->execute(); @@ -923,7 +929,7 @@ class Query extends Component implements QueryInterface { // Инициализация $this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция')); - $this->collection ?? $this->collection = $this->in; + $this->collection ?? $this->collection = is_array($this->for) ? $this->in : $this->for; $data = Serializer::encode($columns); @@ -968,15 +974,15 @@ class Query extends Component implements QueryInterface public function update($columns, $params = [], $db = null) { // Инициализация - $this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция')); + $this->in ?? $this->in = $this->collection ?? throw new Exception('Не найдена коллекция'); $this->for ?? $this->for = $this->in; - $this->collection ?? $this->collection = $this->in; + $this->collection ?? $this->collection = is_array($this->for) ? $this->in : $this->for; $clauses = [ - static::genFor($this->for ?? $this->collection), - static::genIn($this->in ?? $this->collection, $this->traversals), + static::genFor($this->for), + static::genIn($this->in, $this->traversals), $this->genWhere($this->where, $params), - $this->genUpdate($this->collection, $columns), + $this->genUpdate($this->in, $columns), $this->genOptions(), ]; @@ -1020,15 +1026,15 @@ class Query extends Component implements QueryInterface public function remove($params = [], $db = null) { // Инициализация - $this->in ?? (isset($this->collection) ? $this->in = $this->collection : throw new Exception('Не найдена коллекция')); + $this->in ?? $this->in = $this->collection ?? throw new Exception('Не найдена коллекция'); $this->for ?? $this->for = $this->in; - $this->collection ?? $this->collection = $this->in; + $this->collection ?? $this->collection = is_array($this->for) ? $this->in : $this->for; $clauses = [ - static::genFor($this->for ?? $this->collection), - static::genIn($this->in ?? $this->collection, $this->traversals), + static::genFor($this->for), + static::genIn($this->in, $this->traversals), $this->genWhere($this->where, $params), - $this->genRemove($this->in ?? $this->collection), + $this->genRemove($this->in), $this->genOptions(), ];