Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends yii\console\Controller
Beispiel #1
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;
     }
 }
 /**
  * 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.
  * @throws Exception if db component isn't configured
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($action->id !== 'create') {
             if (is_string($this->db)) {
                 $this->db = Yii::$app->get($this->db);
             }
         }
         return true;
     } else {
         return false;
     }
 }
Beispiel #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.
  * @throws Exception if db component isn't configured
  * @return boolean whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($action->id !== 'create') {
             if (is_string($this->db)) {
                 $this->db = Yii::$app->get($this->db);
             }
             if (!$this->db instanceof Connection) {
                 throw new Exception("The 'db' option must refer to the application component ID of a MongoDB connection.");
             }
         }
         return true;
     } else {
         return false;
     }
 }
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if (is_string($this->db)) {
             $this->db = Yii::$app->get($this->db);
         }
         if (!$this->db instanceof Connection) {
             throw new Exception("The 'db' option must refer to the application component ID of a DB connection.");
         }
         $path = (string) Yii::getAlias($this->migrationPath);
         if (!is_dir($path)) {
             if ($action->id !== 'table') {
                 throw new Exception("Migration failed. Directory specified in migrationPath doesn't exist: {$this->migrationPath}");
             }
             FileHelper::createDirectory($path);
         }
         $this->migrationPath = $path;
         $version = Yii::getVersion();
         $this->stdout("Yii Database Migration Tool (based on Yii v{$version})\n", Console::FG_YELLOW);
         return true;
     }
     return false;
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
 }
 /**
  * {@inheritdoc}
  */
 public function options($actionID)
 {
     return array_merge(parent::options($actionID), ['migrationTable', 'db']);
 }