Skip to content

Commit

Permalink
fix online install
Browse files Browse the repository at this point in the history
  • Loading branch information
liufee committed Oct 27, 2017
1 parent 794cf01 commit 53c9f46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
40 changes: 18 additions & 22 deletions install/controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use backend\models\User;
use common\models\Options;
use yii\web\Response;
use yii\web\ErrorAction;

/**
* Site controller
Expand Down Expand Up @@ -44,7 +45,7 @@ public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
'class' => ErrorAction::className(),
],
];
}
Expand All @@ -65,7 +66,7 @@ public function actionChooseLanguage()
}

public function actionAccept()
{//var_dump(Yii::$app->session['language']);die;
{
return $this->render('accept');
}

Expand Down Expand Up @@ -202,13 +203,7 @@ public function actionSetinfo()
$dbport = $request->post('dbport', '3306');
$dbname = $request->post('dbname', '');
$table_prefix = $request->post("dbprefix", '');
$dsn = $this->_getDsn($dbtype, $dbhost, $dbuser, $dbpassword, $dbport, $dbname);
switch ($dbtype) {
case "mysql":
case "postgresql":
$dsn .= ";dbname=" . $dbname;
break;
}
$dsn = $this->_getDsn($dbtype, $dbhost, $dbport, $dbname);
$db = new Connection([
'dsn' => $dsn,
'username' => $dbuser,
Expand All @@ -229,34 +224,34 @@ public function actionSetinfo()

$model = Options::findOne(['name' => 'website_title']);
$model->value = $request->post('sitename', 'Feehi CMS');
$model->save();
$model->save(false);
$model = Options::findOne(['name' => 'website_url']);
$model->value = $request->post('website_url', '');
$model->save();
$model->save(false);
$model = Options::findOne(['name' => 'website_url']);
$model->value = $request->post('siteurl', '');
$model->save();
$model->save(false);
$model = Options::findOne(['name' => 'seo_keywords']);
$model->value = $request->post('sitekeywords', '');
$model->save();
$model->save(false);
$model = Options::findOne(['name' => 'seo_description']);
$model->value = $request->post('siteinfo', '');
$model->save();
$model->save(false);
$configFile = yii::getAlias("@common/config/conf/db.php");
$str = <<<EOF
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => '{$dbtype}:host={$dbhost};dbname={$dbname}',
'class' => yii\db\Connection::className(),
'dsn' => '{$dsn}',
'username' => '{$dbuser}',
'password' => '{$dbpassword}',
'charset' => 'utf8',
'tablePrefix' => '{$table_prefix}',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'class' => yii\swiftmailer\Mailer::className(),
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
Expand All @@ -267,14 +262,15 @@ public function actionSetinfo()
'bootstrap' => ['debug'],
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
//'allowedIPs' => ['192.168.1.2','120.85.82.47', '127.0.0.1', '::1']
'class' => yii\debug\Module::className(),
'allowedIPs' => ['127.0.0.1', '::1']
]
]
];
EOF;

file_put_contents($configFile, $str);
file_put_contents(yii::getAlias("@common/config/main-local.php"), "<?php return [];?>");
$_SESSION["_install_setinfo"] = 1;
sleep(1);
echo "<script>location.href='" . Url::to(['success']) . "';</script>";
Expand All @@ -299,7 +295,7 @@ public function actionCreateDatabase()
$dbpassword = $request->post('dbpw', '');
$dbport = $request->post('dbport', '3306');
$dbname = $request->post('dbname', '');
$dsn = $this->_getDsn($dbtype, $dbhost, $dbuser, $dbpassword, $dbport, $dbname);
$dsn = $this->_getDsn($dbtype, $dbhost, $dbport, $dbname);
$db = new Connection([
'dsn' => $dsn,
'username' => $dbuser,
Expand All @@ -320,13 +316,13 @@ public function actionCreateDatabase()
return ['message' => ''];
}

private function _getDsn($dbtype, $dbhost, $dbuser, $dbpassword, $dbport, $dbname)
private function _getDsn($dbtype, $dbhost, $dbport, $dbname)
{
$dsn = '';
switch ($dbtype) {
case "postgresql":
case "mysql":
$dsn = $dbtype . ":host=" . $dbhost . ';port=' . $dbport;
$dsn = $dbtype . ":host=" . $dbhost . ';port=' . $dbport . ";dbname=" . $dbname;
break;

case "sqlite":
Expand Down
12 changes: 6 additions & 6 deletions install/sql/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ INSERT INTO `%__prefix__%comment` VALUES ('1', '25', '0', '0', 'aaa', '', '', '
COMMIT;

-- ----------------------------
-- Table structure for `friend_link`
-- Table structure for `friendly_link`
-- ----------------------------
DROP TABLE IF EXISTS `%__prefix__%friend_link`;
CREATE TABLE `%__prefix__%friend_link` (
DROP TABLE IF EXISTS `%__prefix__%friendly_link`;
CREATE TABLE `%__prefix__%friendly_link` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`image` varchar(255) COLLATE utf8_unicode_ci DEFAULT '',
Expand All @@ -395,10 +395,10 @@ CREATE TABLE `%__prefix__%friend_link` (
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- ----------------------------
-- Records of `friend_link`
-- Records of `friendly_link`
-- ----------------------------
BEGIN;
INSERT INTO `%__prefix__%friend_link` VALUES ('1', '飞嗨博客', '', 'http://blog.feehi.com', '_blank', '0', '1', '1468303851', '0'), ('2', '飞嗨网', '', 'http://www.feehi.com', '_blank', '0', '1', '1468303882', '0'), ('3', '36kr', '', 'http://www.36kr.com', '_blank', '0', '1', '1468303902', '0'), ('4', '破晓电影', '', 'http://www.poxiao.com', '_blank', '0', '1', '1468303938', '0'), ('5', '翠竹林主题', '', 'http://www.cuizl.com/', '_blank', '0', '1', '1468303974', '0');
INSERT INTO `%__prefix__%friendly_link` VALUES ('1', '飞嗨博客', '', 'http://blog.feehi.com', '_blank', '0', '1', '1468303851', '0'), ('2', '飞嗨网', '', 'http://www.feehi.com', '_blank', '0', '1', '1468303882', '0'), ('3', '36kr', '', 'http://www.36kr.com', '_blank', '0', '1', '1468303902', '0'), ('4', '破晓电影', '', 'http://www.poxiao.com', '_blank', '0', '1', '1468303938', '0'), ('5', '翠竹林主题', '', 'http://www.cuizl.com/', '_blank', '0', '1', '1468303974', '0');
COMMIT;

-- ----------------------------
Expand Down Expand Up @@ -443,7 +443,7 @@ INSERT INTO `%__prefix__%menu` VALUES ('14', '0', '0', '权限管理', '', 'fa f
INSERT INTO `%__prefix__%menu` VALUES ('15', '0', '14', '权限', 'rbac/permissions', '', '0', '_blank', '0', '1', '1505570862', '1505570862');
INSERT INTO `%__prefix__%menu` VALUES ('16', '0', '14', '角色', 'rbac/roles', '', '0', '_blank', '0', '1', '1505570882', '1505570882');
INSERT INTO `%__prefix__%menu` VALUES ('17', '0', '14', '管理员', 'admin-user/index', '', '0', '_blank', '0', '1', '1505570902', '1505570902');
INSERT INTO `%__prefix__%menu` VALUES ('18', '0', '0', '友情链接', 'friend-link/index', 'fa fa-link', '0', '_blank', '0', '1', '1505570934', '1505571307');
INSERT INTO `%__prefix__%menu` VALUES ('18', '0', '0', '友情链接', 'friendly-link/index', 'fa fa-link', '0', '_blank', '0', '1', '1505570934', '1505571307');
INSERT INTO `%__prefix__%menu` VALUES ('19', '0', '0', '缓存', '', 'fa fa-file', '0', '_blank', '0', '1', '1505570947', '1505571292');
INSERT INTO `%__prefix__%menu` VALUES ('20', '0', '19', '清除前台', 'clear/frontend', '', '0', '_blank', '0', '1', '1505570974', '1505570974');
INSERT INTO `%__prefix__%menu` VALUES ('21', '0', '19', '清除后台', 'clear/backend', '', '0', '_blank', '0', '1', '1505570994', '1505570994');
Expand Down

0 comments on commit 53c9f46

Please sign in to comment.