Exemplo n.º 1
0
 /**
  * Generates the data needed to determine if dependency has been changed.
  * This method returns the value of the global state.
  * @param Cache $cache the cache component that is currently evaluating this dependency
  * @return mixed the data needed to determine if dependency has been changed.
  * @throws InvalidConfigException if [[db]] is not a valid application component ID
  */
 protected function generateDependencyData($cache)
 {
     $db = Instance::ensure($this->db, Connection::className());
     if ($this->sql === null) {
         throw new InvalidConfigException("DbDependency::sql must be set.");
     }
     if ($db->enableQueryCache) {
         // temporarily disable and re-enable query caching
         $db->enableQueryCache = false;
         $result = $db->createCommand($this->sql, $this->params)->queryOne();
         $db->enableQueryCache = true;
     } else {
         $result = $db->createCommand($this->sql, $this->params)->queryOne();
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Initializes the migration.
  * This method will set [[db]] to be the 'db' application component, if it is `null`.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     $this->db->getSchema()->refresh();
 }
Exemplo n.º 3
0
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * It checks the existence of the [[migrationPath]].
  * @param \yii\base\Action $action the action to be executed.
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($action->id !== 'create') {
             $this->db = Instance::ensure($this->db, Connection::className());
         }
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 4
0
 /**
  * Initializes generic database table based mutex implementation.
  * @throws InvalidConfigException if [[db]] is invalid.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
 }
Exemplo n.º 5
0
 /**
  * Initializes the DB connection component.
  * This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
  *
  * @throws InvalidConfigException if [[db]] is invalid.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     if ($this->sql === null) {
         throw new InvalidConfigException('The "sql" property must be set.');
     }
 }
Exemplo n.º 6
0
 /**
  * Initializes the DbMessageSource component.
  * This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
  * Configured [[cache]] component would also be initialized.
  * @throws InvalidConfigException if [[db]] is invalid or [[cache]] is invalid.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     if ($this->enableCaching) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }