public function save($runValidation = true, $attributes = NULL) { $a = parent::save($runValidation, $attributes); if ($a) { Yii::$app->db->close(); Yii::$app->db->dsn = $this->company->string; Yii::$app->db->tablePrefix = $this->company->prefix; Yii::$app->db->open(); $user = User::findOne($this->user_id); $user->save(); } return $a; }
public function save($runValidation = true, $attributes = NULL) { //$this->id=0; if ($this->salt == '') { $this->salt = $this->generateSalt(); } if ($this->passwd != '') { $this->password = $this->hashPassword($this->passwd, $this->salt); } $res = parent::save($runValidation, $attributes); if (Yii::$app->db->schema->getTableSchema('{{%config}}') !== null && $res) { $this->compSave(); //echo $this->warehouse; //exit; if (isset($this->warehouse)) { $this->warehouseSave($this->warehouse); } if (isset($this->certpasswd)) { $this->certpasswdSave($this->certpasswd); } } return $res; }
public function save($runValidation = true, $attributes = NULL) { $a = parent::save($runValidation, $attributes); if ($this->prefix == '') { $this->string = Yii::$app->dbMain->dsn; //$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $this->prefix = "CA" . $this->id . "_"; //got prefix $a = parent::save($runValidation, $attributes); } //if tables config notexsits Yii::$app->db->close(); Yii::$app->db->dsn = $this->string; Yii::$app->db->tablePrefix = $this->prefix; Yii::$app->db->open(); //needs to clear accounts if (Yii::$app->db->schema->getTableSchema('{{config}}') === null) { // //create tables $this->createDb(); Yii::$app->db->close(); Yii::$app->db->dsn = $this->string; Yii::$app->db->tablePrefix = $this->prefix; Yii::$app->db->open(); \app\helpers\Linet3Helper::setSetting('company.path', $this->prefix); //update path by prefix //$yiiBasepath = Yii::$app->basePath; //add permisstions } else { //else //table version //upgrade } $perm = new DatabasesPerm(); $perm->user_id = Yii::$app->user->id; $perm->database_id = $this->id; $perm->level_id = 1; $perm->save(); return $a; }