public function actionSite($power = false)
 {
     $model = new SiteForm();
     $model->getSetting();
     if (isset($_POST['SiteForm'])) {
         $model->attributes = $_POST['SiteForm'];
         $uploadFile = CUploadedFile::getInstance($model, 'logo');
         if ($uploadFile !== null) {
             $uploadFileName = "logo_" . time() . '.' . $uploadFile->getExtensionName();
             if (file_exists($model->logo)) {
                 unlink(Yii::app()->basePath . "/../" . $model->logo);
             }
             if (!is_dir(Yii::app()->basePath . "/../uploads/setting/site")) {
                 DxdUtil::createFolders(Yii::app()->basePath . "/../uploads/setting/site");
             }
             $model->logo = 'uploads/setting/site/' . $uploadFileName;
             $uploadFile->saveAs(Yii::app()->basePath . "/../" . $model->logo);
         }
         //			var_dump($_POST['SiteForm']);
         if ($model->saveSetting()) {
             Yii::app()->user->setFlash('success', '保存成功!');
         } else {
             Yii::app()->user->setFlash('error', '保存失败!');
         }
     }
     if (!$power) {
         $this->render('site', array('model' => $model));
     } else {
         $this->render('power', array('model' => $model));
     }
 }
 public function actionDoUpgrade()
 {
     $siteInfo = new SiteForm();
     $siteInfo->getSetting();
     if (UpgradeInfo::compareVersion($siteInfo->version, "1.3.0") < 0) {
         $siteInfo->version = "1.3.0";
         $siteInfo->saveSetting();
     }
     $criteria = new CDbCriteria();
     //$criteria->select = 'version';
     $criteria->condition = 'status=:status';
     $criteria->order = 'versionId';
     $criteria->params = array(':status' => 'not installed');
     $upgradeInfos = UpgradeInfo::model()->findAll($criteria);
     $vertionString = '';
     foreach ($upgradeInfos as $upgradeInfo) {
         if (UpgradeInfo::compareVersion($siteInfo->version, $upgradeInfo->version) >= 0) {
             $upgradeInfo->status = "skipped";
             $upgradeInfo->save();
             continue;
         }
         $vertionString .= '"' . strval($upgradeInfo->version) . '",';
     }
     $this->layout = "/layouts/nonav_column1";
     $this->render('do_upgrade_fancy', array('versions' => $vertionString));
 }
Exemple #3
0
 /**
  * 用来更新upgradeinfo信息
  * Enter description here ...
  * @param json $response 从服务器得到的需要更新的更新包信息 
  */
 public static function updateUpgradeInfo($response)
 {
     $result = json_decode($response, true);
     $siteInfo = new SiteForm();
     $siteInfo->getSetting();
     if (count($result)) {
         //对每一个需要更新的包
         foreach ($result as $r) {
             $model = new UpgradeInfo();
             $model->versionId = $r['id'];
             if (UpgradeInfo::model()->findByAttributes(array('versionId' => $r['id']))) {
                 continue;
             }
             $model->version = $r['version'];
             $model->name = $r['name'];
             $model->addTime = $r['addTime'];
             $model->description = $r['description'];
             if (UpgradeInfo::compareVersion($siteInfo->version, $model->version) < 0) {
                 $model->save();
             }
         }
     }
 }
 public function actionInit()
 {
     $model = new InstallInfoForm();
     $mailer = new MailerForm();
     if (isset($_POST['InstallInfoForm']) && isset($_POST['MailerForm'])) {
         $model->attributes = $_POST['InstallInfoForm'];
         $siteForm = new SiteForm();
         $siteForm->name = $model->name;
         $siteForm->subTitle = $model->subTitle;
         $siteForm->saveSetting();
         $user = new User();
         $user->email = $model->adminEmail;
         $user->setPlainPassword($model->adminPassword);
         $user->save();
         $userInfo = new UserInfo();
         $userInfo->name = $model->adminName;
         $userInfo->id = $user->getPrimaryKey();
         $userInfo->email = $user->email;
         $userInfo->bio = $model->adminBio;
         $userInfo->isAdmin = 1;
         //			$userInfo->roles = "superAdmin,admin,teacher";
         $userInfo->status = "ok";
         $userInfo->addTime = time();
         $userInfo->introduction = "admin";
         $mailer->attributes = $_POST['MailerForm'];
         if ($userInfo->save() && $mailer->saveSetting()) {
             $auth = Yii::app()->authManager;
             $auth->createRole('admin');
             $auth->createRole('teacher');
             $userInfo->roles = array('admin', 'teacher');
             $this->setNav();
             $this->setCarousel();
             Yii::app()->user->setFlash('success', '系统初始化成功!');
             $this->redirect(array('finish'));
         }
     }
     $this->render('init', array('model' => $model, 'mailer' => $mailer));
 }