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(), ];