/** * 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; }
/** * 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(); }
/** * 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; } }
/** * 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()); }
/** * 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.'); } }
/** * 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()); } }