Skip to content

Commit b3d5efd

Browse files
界面安装部分
1 parent eee228f commit b3d5efd

File tree

6 files changed

+105
-155
lines changed

6 files changed

+105
-155
lines changed

app/appinstall/config/appinstall.php

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
'forceCopy' => true,
3838
],
3939
],
40+
4041

4142
];
4243
return $config;

app/appinstall/modules/Database/controllers/ConfigController.php

+41-57
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ public function init()
2020
parent::init();
2121
}
2222

23-
public $_migrateLog = '';
23+
// public $_migrateLog = '';
2424

2525
// 安装默认第一步页面
2626
public function actionIndex()
2727
{
2828
$editForm = Yii::$app->request->post('editForm');
2929
if ($editForm && $this->checkDatabaseData($editForm)
30-
&& $this->updateDatabase($editForm)) {
30+
&& $this->updateDatabaseConfig($editForm)) {
3131
Yii::$app->session->setFlash('database-success', 'mysql config set success, mysql config file path: @common/config/main-local.php');
3232
// 进行跳转
3333
$homeUrl = Yii::$app->homeUrl;
@@ -44,6 +44,25 @@ public function actionIndex()
4444
// 数据库migrate页面
4545
public function actionMigrate()
4646
{
47+
48+
$isPost = Yii::$app->request->post('isPost');
49+
if ($isPost ) {
50+
// 进行数据库初始化
51+
if ($this->runMigrate()) {
52+
$successInfo = '数据库migrate初始化完成';
53+
$successInfo = $this->getSuccessHtml($successInfo);
54+
//exit;
55+
return $this->render('migratesuccess', [
56+
'successInfo' => $successInfo,
57+
'nextUrl' => Yii::$app->homeUrl . '/database/config/addtestdata',
58+
'skipUrl' => Yii::$app->homeUrl . '/database/config/complete',
59+
]);
60+
} else {
61+
$errors = 'migrate 失败,你可以在logs文件中查看具体原因(@appfront/config/main.php中log组件,对应的logFile配置,查看该log文件,如果没有可以手动创建该log文件,清空数据库,重新执行该操作)';
62+
Yii::$app->session->setFlash('migrate-errors', $errors);
63+
}
64+
}
65+
4766
$successInfo = Yii::$app->session->getFlash('database-success');
4867
$successInfo = $this->getSuccessHtml($successInfo);
4968
$errorInfo = Yii::$app->session->getFlash('migrate-errors');
@@ -52,27 +71,29 @@ public function actionMigrate()
5271
return $this->render($this->action->id, [
5372
'successInfo' => $successInfo,
5473
'errorInfo' => $errorInfo,
55-
'initUrl' => Yii::$app->homeUrl . '/database/config/migrateprocess',
56-
'nextUrl' => Yii::$app->homeUrl . '/database/config/addtestdata',
57-
'migrateLog' => $this->_migrateLog
5874
]);
5975
}
60-
76+
// 产品测试数据添加
6177
public function actionAddtestdata()
6278
{
63-
$errorInfo = Yii::$app->session->getFlash('add-test-errors');
64-
$errorInfo = $this->getErrorHtml($errorInfo);
79+
if ($this->addProductData()) {
80+
$successInfo = $this->getSuccessHtml('产品测试数据添加成功');
81+
} else {
82+
$errorInfo = Yii::$app->session->getFlash('add-test-data-errors');
83+
$errorInfo = $this->getErrorHtml($errorInfo);
84+
}
6585

6686
return $this->render($this->action->id, [
6787
'errorInfo' => $errorInfo,
88+
'successInfo' => $successInfo,
6889
'initUrl' => Yii::$app->homeUrl . '/database/config/addtestdatainit',
6990
'nextUrl' => Yii::$app->homeUrl . '/database/config/complete',
7091
//'migrateLog' => $this->_migrateLog
7192
]);
7293

7394
}
7495
// 进行sql migrate ,产品图片的复制
75-
public function actionAddtestdatainit()
96+
public function addProductData()
7697
{
7798
// 1. 图片的复制
7899
$sourcePath = dirname(Yii::getAlias('@common')) . '/environments/test_data/appimage';
@@ -87,34 +108,15 @@ public function actionAddtestdatainit()
87108
try {
88109
$result = $conn->createCommand($sqlStr)->execute();
89110
$innerTransaction->commit();
90-
echo json_encode([
91-
'status' => 'success',
92-
]);
93111

94-
exit;
112+
return true;
95113
} catch (\Exception $e) {
96114
$innerTransaction->rollBack();
97115
$message = $e->getMessage();
98-
echo json_encode([
99-
'status' => 'fail',
100-
'info' => $message ,
101-
]);
102-
103-
exit;
116+
Yii::$app->session->setFlash('add-test-data-errors', $message);
104117
}
105-
echo json_encode([
106-
'status' => 'fail',
107-
'info' => 'error' ,
108-
]);
109118

110-
exit;
111-
}
112-
113-
// 进行数据库的migrate操作(ajax)
114-
public function actionMigrateprocess()
115-
{
116-
$this->runMigrate();
117-
exit;
119+
return false;
118120
}
119121

120122
// 完成页面
@@ -124,7 +126,7 @@ public function actionComplete()
124126
}
125127

126128
// 进行数据库的信息的检查,以及将数据库信息写入文件
127-
public function updateDatabase($editForm)
129+
public function updateDatabaseConfig($editForm)
128130
{
129131
$host = $editForm['host'];
130132
$database = $editForm['database'];
@@ -242,42 +244,24 @@ public function getErrorHtml($errorInfo){
242244
*/
243245
public function runMigrate()
244246
{
247+
$bashPath = dirname(Yii::getAlias('@appfront'));
245248
$oldApp = \Yii::$app;
246249
Yii::$app = new \yii\console\Application([
247250
'id' => 'install-console',
248-
'basePath' => '@appfront',
251+
'basePath' => $bashPath,
249252
'components' => [
250253
'db' => $oldApp->db,
251254
],
252255
]);
253-
$runResult = \Yii::$app->runAction('migrate/up', ['migrationPath' => '@fecshop/migrations/mysqldb', 'interactive' => false]);
254-
\Yii::$app = $oldApp;
255-
256-
return $runResult ;
257-
}
258-
259-
/*
260-
public function runMigrate()
261-
{
262-
263-
// 通过ob函数截取输出字符
264256
ob_start();
265257
ob_implicit_flush(false);
266-
extract(['oldApp' => \Yii::$app], EXTR_OVERWRITE);
267-
\Yii::$app = new \yii\console\Application([
268-
'id' => 'install-console',
269-
'basePath' => '@appfront',
270-
'components' => [
271-
'db' => $oldApp->db,
272-
],
273-
]);
274-
$result = \Yii::$app->runAction('migrate/up', ['migrationPath' => '@fecshop/migrations/mysqldb', 'interactive' => false]);
258+
$runResult = \Yii::$app->runAction('migrate/up', ['migrationPath' => '@fecshop/migrations/mysqldb', 'interactive' => false]);
259+
$post_log = ob_get_clean();
260+
Yii::info($post_log, 'fecshop_debug');
275261
\Yii::$app = $oldApp;
276-
$this->_migrateLog = ob_get_clean();
277-
278-
return true;
262+
// $runResult 返回值,0代表执行完成,1代表执行出错。
263+
return $runResult === 0 ? true : false ;
279264
}
280-
*/
281265

282266
// 创建文件夹,在图片文件复制的过程中使用。
283267
public function dirMkdir($path = '', $mode = 0777, $recursive = true)

app/appinstall/modules/Database/views/config/addtestdata.php

+10-47
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,31 @@
1111
<br/>
1212

1313
<?php echo CRequest::getCsrfInputHtml(); ?>
14-
<p>此步骤执行:</p>
14+
<p>产品测试数据安装操作:</p>
1515

1616
<p>1.产品测试数据sql安装</p>
1717

1818
<p>2.产品的图片复制</p>
1919

20-
<p>3.请勿重复执行该步骤,因为插入的数据只能插入依次,多次插入将会报错
20+
<p>3.<b>请勿重复执行该步骤</b>,操作成功后,请勿刷新页面,因为插入的测试数据多次插入将会报错
2121
如果您已经执行了插入的sql,点击跳过进入下一步即可。</p>
2222

23-
<p>4.如果您不想安装测试数据,点击跳过按钮,进入下一步。</p>
23+
<p>4.如果您进行了重复操作,请清空数据库的表,从头开始安装</p>
2424

2525
<br/>
2626
<br/>
2727

28-
<button type="button" class="btn btn-default testDataInit">测试产品数据安装</button>
29-
30-
<button type="button" class="btn btn-default testDataSkip">跳过</button>
31-
32-
<button type="button" class="btn btn-default install-next" style="display:none;">下一步</button>
28+
<button type="button" class="btn btn-default install-next" >下一步</button>
3329

3430

3531
<br/>
3632
<br/>
37-
测试产品数据安装:<span class="logshort" style="display:none;color:#cc0000;">正在进行测试产品数据安装...</span>
38-
<span class="logshort-complete" style="display:none;color:green;">测试产品数据安装完成,您可以点击下一步按钮,进行下一步的安装操作</span>
3933
<br/>
40-
<textarea class="initLog" style="width:1200px;height:300px;"></textarea>
41-
42-
43-
34+
<br/>
35+
<br/>
36+
<br/>
37+
<br/>
38+
<br/>
4439

4540
<script>
4641
// add to cart js
@@ -49,39 +44,7 @@
4944
$(".install-next").click(function(){
5045
window.location.href="<?= $nextUrl ?>";
5146
});
52-
$(".testDataSkip").click(function(){
53-
window.location.href="<?= $nextUrl ?>";
54-
});
55-
$(".testDataInit").click(function(){
56-
var initUrl = "<?= $initUrl ?>";
57-
$(".logshort").show();
58-
$.ajax({
59-
async:true,
60-
timeout: 6000,
61-
type:'post',
62-
dataType: 'json',
63-
data: {},
64-
url: initUrl,
65-
success:function(data, textStatus){
66-
$(".logshort").hide();
67-
if(data.status == 'success'){
68-
$(".logshort-complete").show();
69-
$(".testDataInit").hide();
70-
$(".testDataSkip").hide();
71-
$(".install-next").show();
72-
73-
} else if(data.status == 'fail'){
74-
$(".initLog").val(data.info);
75-
}
76-
77-
},
78-
error:function (XMLHttpRequest, textStatus, errorThrown){
79-
$(".logshort").hide();
80-
$(".initLog").val(XMLHttpRequest.responseText);
81-
}
82-
});
83-
84-
});
47+
8548
});
8649
<?php $this->endBlock(); ?>
8750
<?php $this->registerJs($this->blocks['db_init'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>

app/appinstall/modules/Database/views/config/complete.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<p style="font-size:16px;line-height:25px;">3.后台默认用户名,用户名密码: <span style="color:#c7254e">admin admin123</span></p>
2121

22-
<p style="font-size:16px;line-height:25px;">4.访问后台,更改<span style="color:#c7254e">admin</span>用户密码,然后根据文档进行后台配置 </p>
22+
<p style="font-size:16px;line-height:25px;">4.访问后台(访问nginx配置的后台appadmin域名),更改<span style="color:#c7254e">admin</span>用户密码,然后根据文档进行后台配置 </p>
2323

2424

2525
<br/>

app/appinstall/modules/Database/views/config/migrate.php

+12-50
Original file line numberDiff line numberDiff line change
@@ -10,70 +10,32 @@
1010
<br/>
1111
<br/>
1212

13-
<?php echo CRequest::getCsrfInputHtml(); ?>
1413
<p>此步骤执行:</p>
1514

1615
<p>1.Fecmall 数据库表的migrate,进行数据库的初始化</p>
1716

1817
<p>2.初始化完成后,mysql的表以及索引,将会被建立, 以及初始数据</p>
1918

20-
<br/>
21-
<br/>
22-
23-
<button type="button" class="btn btn-default dbInit">进行数据表初始化</button>
24-
25-
<button type="button" class="btn btn-default install-next" style="display:none;">下一步</button>
19+
<p>3.您需要等待一段时间,等待sql的执行完成</p>
2620

27-
28-
<br/>
2921
<br/>
30-
数据库初始化Log:<span class="logshort" style="display:none;color:#cc0000;">正在进行数据库初始化...</span>
31-
<span class="logshort-complete" style="display:none;color:green;">数据库初始化完成,您可以点击下一步按钮,进行下一步的安装操作</span>
3222
<br/>
33-
<textarea class="initLog" style="width:1200px;height:300px;"></textarea>
34-
35-
36-
23+
<form action="" method="post">
24+
<?php echo CRequest::getCsrfInputHtml(); ?>
25+
<input type="hidden" value="1" name="isPost" />
26+
<button type="submit" class="btn btn-default dbInit">进行数据表初始化</button>
27+
<span class="d_info" style="margin-left:20px;display:none; color: #cc0000">数据库migrate初始化中...</span>
28+
</form>
3729

3830
<script>
3931
// add to cart js
40-
<?php $this->beginBlock('db_init') ?>
32+
<?php $this->beginBlock('dbInit') ?>
4133
$(document).ready(function(){
42-
$(".install-next").click(function(){
43-
window.location.href="<?= $nextUrl ?>";
34+
$(".dbInit").click(function(){
35+
$(".d_info").show();
4436
});
45-
$(".dbInit").click(function(){
46-
var initUrl = "<?= $initUrl ?>";
47-
$(".logshort").show();
48-
$.ajax({
49-
async:true,
50-
timeout: 6000,
51-
type:'post',
52-
data: {},
53-
url: initUrl,
54-
success:function(data, textStatus){
55-
$(".logshort").hide();
56-
$(".initLog").val(data);
57-
// #21 /www/web/develop/fecshop/appfront/web/install.php(20): yii\base\Application->run()
58-
if (data.indexOf('appfront/web/install.php') != -1) {
59-
// 存在错误
60-
} else {
61-
// 不存在错误, 显示跳转下一步的按钮
62-
$(".install-next").show();
63-
$(".logshort-complete").show();
64-
65-
$(".dbInit").hide();
66-
}
67-
68-
},
69-
error:function (XMLHttpRequest, textStatus, errorThrown){
70-
$(".logshort").hide();
71-
$(".initLog").val(XMLHttpRequest.responseText);
72-
}
73-
});
74-
75-
});
37+
7638
});
7739
<?php $this->endBlock(); ?>
78-
<?php $this->registerJs($this->blocks['db_init'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
40+
<?php $this->registerJs($this->blocks['dbInit'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
7941
</script>

0 commit comments

Comments
 (0)