/** * 初始化数据库 */ public function actionInitDB() { //初始化数据库 $migration = new MiniMigration(); $migration->up(); }
/** * 启用插件 * @param $id * @return array */ public function enablePlugin($id) { $data = array(); //判断插件是否在约定的目录下 $path = Yii::getPathOfAlias('application.plugins') . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR . ucfirst($id) . "Module.php"; if (!file_exists($path)) { $data["success"] = false; return $data; } //获得插件元数据 $pluginMeta = $this->getPluginMeta($path); $value = MiniOption::getInstance()->getOptionValue("active_plugins"); $list = (array) unserialize($value); foreach ($list as $key => $item) { //判断插件是否已经激活 if ($key === $id) { $data["success"] = true; return $data; } //判断同类型的插件是否已激活,同类型的插件只能启动一个 if ($item["type"] === $pluginMeta["type"]) { $data["success"] = false; $data["msg"] = Yii::t("common", "plugin_has_install", array("{plugin_name}" => $item["name"])); return $data; } } //把激活插件列表写入到DB中 $item = array(); $item[$id] = array("type" => $pluginMeta["type"], "name" => $pluginMeta["name"]); $list = array_merge($item, $list); MiniOption::getInstance()->setOptionValue("active_plugins", serialize($list)); //数据库增量更新插件相关数据结构 $data["success"] = true; try { $migration = new MiniMigration(); $migration->up($id); } catch (Exception $e) { // Yii::log($e->getMessage(), CLogger::LEVEL_ERROR); // $data["success"] = false; } return $data; }
public function save() { $success = false; if ($this->validate()) { if ($this->baseValidate()) { if (!$this->hasErrors()) { //如果校驗没有错误 $dbComponent = Yii::createComponent(array('class' => 'CDbConnection', 'connectionString' => 'mysql:host=' . trim($this->dbHost) . ';port=' . trim($this->dbPort) . ';dbname=' . $this->dbName, 'username' => $this->userName, 'password' => $this->password, 'emulatePrepare' => true, 'charset' => "utf8")); Yii::app()->setComponent("dbInstall", $dbComponent); define('DB_PREFIX', $this->tablePrefix); $migration = new MiniMigration(); $migration->connectionID = "dbInstall"; $migration->up(); $this->initDbConfigFile(); $success = true; } } } if (isset($this->_db)) { if (function_exists('mysqli_close')) { mysqli_close($this->_db); } else { mysql_close($this->_db); } } return $success; }
/** * 升级数据库 */ public function actionUpgrade() { $migration = new MiniMigration(); $migration->up(); echo "success!<br>"; }