Esempio n. 1
0
 /**
  * Retrieves a value from cache with a specified key.
  * This method should be implemented by child classes to retrieve the data
  * from specific cache storage.
  * @param string $key a unique key identifying the cached value
  * @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
  */
 protected function getValue($key)
 {
     $query = new Query();
     $row = $query->select(['data'])->from($this->cacheCollection)->where(['id' => $key, '$or' => [['expire' => 0], ['expire' => ['$gt' => time()]]]])->one($this->db);
     if (empty($row)) {
         return false;
     } else {
         return $row['data'];
     }
 }
Esempio n. 2
0
 /**
  * Ensures migration history contains at least base migration entry.
  */
 protected function ensureBaseMigrationHistory()
 {
     if (!$this->baseMigrationEnsured) {
         $query = new Query();
         $row = $query->select(['version'])->from($this->migrationCollection)->andWhere(['version' => self::BASE_MIGRATION])->limit(1)->one($this->db);
         if (empty($row)) {
             $this->addMigrationHistory(self::BASE_MIGRATION);
         }
         $this->baseMigrationEnsured = true;
     }
 }
Esempio n. 3
0
 /**
  * Performs 'findAndModify' query and returns a single row of result.
  * Warning: in case 'new' option is set to 'false' (which is by default) usage of this method may lead
  * to unexpected behavior at some Active Record features, because object will be populated by outdated data.
  * @param array $update update criteria
  * @param array $options list of options in format: optionName => optionValue.
  * @param Connection $db the Mongo connection used to execute the query.
  * @return ActiveRecord|array|null the original document, or the modified document when $options['new'] is set.
  * Depending on the setting of [[asArray]], the query result may be either an array or an ActiveRecord object.
  * Null will be returned if the query results in nothing.
  */
 public function modify($update, $options = [], $db = null)
 {
     $row = parent::modify($update, $options, $db);
     if ($row !== null) {
         $models = $this->populate([$row]);
         return reset($models) ?: null;
     } else {
         return null;
     }
 }