Example #1
0
 public function save($runValidation = true, $attributes = NULL)
 {
     $a = parent::save($runValidation, $attributes);
     if ($a) {
         Yii::app()->db->setActive(false);
         Yii::app()->db->connectionString = $this->Company->string;
         Yii::app()->db->tablePrefix = $this->Company->prefix;
         Yii::app()->db->setActive(true);
         $user = User::model()->findByPk($this->user_id);
         $user->save();
     }
     return $a;
 }
Example #2
0
 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->getTable('{{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;
 }
Example #3
0
 public function save($runValidation = true, $attributes = NULL)
 {
     $a = parent::save($runValidation, $attributes);
     if ($this->prefix == '') {
         $this->string = Yii::app()->dbMain->connectionString;
         //$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
         $this->prefix = "CA" . $this->id . "_";
         //got prefix
         $a = parent::save($runValidation, $attributes);
     }
     //if tables config notexsits
     Yii::app()->db->setActive(false);
     Yii::app()->db->connectionString = $this->string;
     Yii::app()->db->tablePrefix = $this->prefix;
     Yii::app()->db->setActive(true);
     //needs to clear accounts
     if (Yii::app()->db->schema->getTable('{{config}}') === null) {
         //
         //create tables
         $this->createDb();
         Yii::app()->db->setActive(false);
         Yii::app()->db->connectionString = $this->string;
         Yii::app()->db->tablePrefix = $this->prefix;
         Yii::app()->db->setActive(true);
         $a = Settings::model()->findByPk('company.path');
         //update path by prefix
         $a->value = $this->prefix;
         $a->save();
         //$yiiBasepath = Yii::app()->basePath;
         $folder = Yii::app()->params["filePath"] . $this->prefix . DIRECTORY_SEPARATOR;
         mkdir($folder);
         mkdir($folder . "settings");
         //settings
         mkdir($folder . "cert");
         //cert
         mkdir($folder . "docs");
         //docs
         mkdir($folder . "items");
         //items
         mkdir($folder . "openformat");
         //openformat
         mkdir($folder . "files");
         //openformat
         mkdir($folder . "backup");
         //backup
         //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;
 }