提交 acbe44f4 编写于 作者: T Terry

fecmall 界面安装

上级 0bca1d47
<?php
namespace fecshop\app\appinstall\assets;
use yii\web\AssetBundle;
/**
* Main frontend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $sourcePath = '@fecshop/app/appinstall/assets';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
.body-container{
min-height: 900px;
margin-top: 50px;
padding-top: 20px;
}
.error-msg {
margin:3px 0;
background: #faebe7 url("../images/i_msg-error.gif") no-repeat scroll 8px 7px;
border: 1px solid #f16048;
color: #df280a;
font-size: 0.8em;
padding: 5px 30px;
}
.correct-msg {
margin:3px 0;
background: #eff5ea url("../images/i_msg-success.gif") no-repeat scroll 8px 7px;
border: 1px solid #95a486;
color: #3d6611 ;
font-size: 0.8em;
padding: 5px 30px;
}
\ No newline at end of file
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
/**
* 本文件在@appfront/web/index.php 处,会被引入。
* 该配置文件会加载./modules/*.php,并合并成一个数组,返回。
*/
$modules = [];
foreach (glob(__DIR__ . '/modules/*.php') as $filename) {
$modules = array_merge($modules, require($filename));
}
$params = require __DIR__ .'/params.php';
// 此处也可以重写fecshop的组件。供调用。
$config = [
'modules'=>$modules,
// 参数配置部分
'params' => $params,
// Yii组件配置 ,关于yii2组件,可以参看:http://www.yiichina.com/doc/guide/2.0/structure-application-components
'components' => [
// 404页面对应的url key
'errorHandler' => [
'errorAction' => 'site/helper/error',
],
// 首页对应的url key
'urlManager' => [
'rules' => [
'' => 'database/config/index',
],
],
'assetManager' => [
'forceCopy' => true,
],
],
];
return $config;
\ No newline at end of file
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
return [
/**
* Catalog 模块的配置,您可以在@appfront/config/fecshop_local_modules/Catalog.php
* 中进行配置,二开,或者重写该模块(在上面路径中如果文件不存在,自行新建配置文件。)
*/
'database' => [
'class' => '\fecshop\app\appinstall\modules\Database\Module',
'params'=> [
/*
'productImgSize' => [
'small_img_width' => 80, // 底部小图的宽度
'small_img_height' => 110, // 底部小图的高度
'middle_img_width' => 400, // 主图的宽度
],
'category_breadcrumbs' => true,
'product_breadcrumbs' => true,
*/
],
],
];
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
return [
/**
* 模板路径配置部分
*/
'appinstallBaseTheme' => '@fecshop/app/appinstall/theme',
/**
* 模板默认的layout文件,也就是模板路径下面的layout文件夹下的文件,
* 对于上面的模板路径的配置,也就是文件:@fecshop/app/appfront/theme/base/front/layouts/main.php
*/
'appfrontBaseLayoutName'=> 'main.php',
/**
* 入口的名字,这个对应入口的文件夹命名。
*/
'appName' => 'appinstall',
];
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace fecshop\app\appinstall\modules\Database;
use Yii;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
* Catalog Module 模块
*/
class Module extends \yii\base\Module
{
public $blockNamespace;
public function init()
{
// 以下代码必须指定
$nameSpace = __NAMESPACE__;
// 如果 Yii::$app 对象是由类\yii\web\Application 实例化出来的。
if (Yii::$app instanceof \yii\web\Application) {
// 设置模块 controller namespace的文件路径
$this->controllerNamespace = $nameSpace . '\\controllers';
// 设置模块block namespace的文件路径
$this->blockNamespace = $nameSpace . '\\block';
}
$this->layout = 'main.php';
parent::init();
}
}
<?php
namespace fecshop\app\appinstall\modules\Database\controllers;
use Yii;
class ConfigController extends \yii\web\Controller
{
public function init()
{
parent::init();
}
public $_migrateLog = '';
// 数据库管理
public function actionMigrate()
{
$successInfo = Yii::$app->session->getFlash('database-success');
$successInfo = $this->getSuccessHtml($successInfo);
$errorInfo = Yii::$app->session->getFlash('migrate-errors');
$errorInfo = $this->getErrorHtml($errorInfo);
return $this->render($this->action->id, [
'successInfo' => $successInfo,
'errorInfo' => $errorInfo,
'initUrl' => Yii::$app->homeUrl . '/database/config/migrateprocess',
'nextUrl' => Yii::$app->homeUrl . '/database/config/addtestdata',
'migrateLog' => $this->_migrateLog
]);
}
public function actionComplete()
{
// 执行 chmod 644 @common/config/main-local
// 删除掉install.php文件
return $this->render($this->action->id, [
]);
}
// 进行测试数据sql的安装和测试图片的复制
public function actionAddtestdata()
{
$errorInfo = Yii::$app->session->getFlash('add-test-errors');
$errorInfo = $this->getErrorHtml($errorInfo);
return $this->render($this->action->id, [
'errorInfo' => $errorInfo,
'initUrl' => Yii::$app->homeUrl . '/database/config/addtestdatainit',
'nextUrl' => Yii::$app->homeUrl . '/database/config/complete',
//'migrateLog' => $this->_migrateLog
]);
}
public function actionAddtestdatainit()
{
// 1. 图片的复制
$sourcePath = dirname(Yii::getAlias('@common')) . '/environments/test_data/appimage';
//$sourcePath = Yii::getAlias('@fectmelani/app/appimage');
$targetPath = Yii::getAlias('@appimage');
$this->copyDir($sourcePath, $targetPath);
// 2. sql文件的执行
$sqlFile = dirname(Yii::getAlias('@common')) . '/environments/test_data/fecshop.sql';
$sqlStr = file_get_contents($sqlFile);
$conn = Yii::$app->db;
$innerTransaction = $conn->beginTransaction();
try {
$result = $conn->createCommand($sqlStr)->execute();
$innerTransaction->commit();
echo json_encode([
'status' => 'success',
]);exit;
} catch (\Exception $e) {
$innerTransaction->rollBack();
$message = $e->getMessage();
echo json_encode([
'status' => 'fail',
'info' => $message ,
]);exit;
}
echo json_encode([
'status' => 'fail',
'info' => 'error' ,
]);
exit;
}
// 进行数据库的migrate操作
public function actionMigrateprocess()
{
$this->runMigrate();
exit;
}
// 安装默认第一步页面
public function actionIndex()
{
$editForm = Yii::$app->request->post('editForm');
if ($editForm && $this->checkDatabaseData($editForm)
&& $this->updateDatabase($editForm)) {
Yii::$app->session->setFlash('database-success', 'mysql config set success, mysql config file path: @common/config/main-local.php');
// 进行跳转
$homeUrl = Yii::$app->homeUrl;
return $this->redirect($homeUrl.'/database/config/migrate');
}
$errorInfo = Yii::$app->session->getFlash('database-errors');
$errorInfo = $this->getErrorHtml($errorInfo);
return $this->render($this->action->id, [
'errorInfo' => $errorInfo,
'editForm' => $editForm,
]);
}
// 进行数据库的信息的检查,以及将数据库信息写入文件
public function updateDatabase($editForm)
{
$host = $editForm['host'];
$database = $editForm['database'];
$user = $editForm['user'];
$password = $editForm['password'];
$dbConfig = [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host='.$host.';dbname='.$database,
'username' => $user,
'password' => $password,
'charset' => 'utf8',
];
$connection = Yii::createObject($dbConfig);
$connError = '';
try {
$connection->open();
} catch (\Exception $e) {
$connError = $e->getMessage();
Yii::$app->session->setFlash('database-errors', $connError);
return false;
}
// 将信息写入配置文件
$mainLocalFile = Yii::getAlias("@common/config/main-local.php");
if(!file_exists($mainLocalFile)){
$errors = 'config file[@common/config/main-local.php] is not exist, you exec init command before install';
Yii::$app->session->setFlash('database-errors', $errors);
return false;
}
$mainLocalInfo = file_get_contents($mainLocalFile);
//$mainLocalInfo = require($mainLocalFile);
$mainLocalInfo = str_replace('{mysql_host}', $host, $mainLocalInfo);
$mainLocalInfo = str_replace('{mysql_database}', $database, $mainLocalInfo);
$mainLocalInfo = str_replace('{mysql_user}', $user, $mainLocalInfo);
$mainLocalInfo = str_replace('{mysql_password}', $password, $mainLocalInfo);
//var_dump($mainLocalInfo);exit;
if (@file_put_contents($mainLocalFile, $mainLocalInfo) === false) {
$errors = 'Unable to write the file '.$mainLocalFile;
Yii::$app->session->setFlash('database-errors', $errors);
return false;
}
// 设置数据库文件644, 需要shell手动设置文件权限。
/*
if (@chmod($mainLocalFile,0644) === false) {
$errors = 'Unable to set mainLocalFile 644, please change it';
Yii::$app->session->setFlash('database', $errors);
return false;
}
*/
return true;
}
// 检查前端传递的参数
public function checkDatabaseData($editForm)
{
$session = Yii::$app->session;
if (!$editForm['host']) {
$session->setFlash('database-errors', 'Mysql数据库Host为空');
return false;
}
if (!$editForm['database']) {
$session->setFlash('database-errors', 'Mysql数据库名称为空');
return false;
}
if (!$editForm['user']) {
$session->setFlash('database-errors', 'Mysql数据库账户为空');
return false;
}
if (!$editForm['password']) {
$session->setFlash('database-errors', 'Mysql数据库密码为空');
return false;
}
return true;
}
public function getSuccessHtml($successInfo){
if ($successInfo) {
return '
<div class="fecshop_message">
<div class="correct-msg">
<div>'. $successInfo .'</div>
</div>
</div>
';
}
return '';
}
public function getErrorHtml($errorInfo){
if ($errorInfo) {
return '
<div class="fecshop_message">
<div class="error-msg">
<div>'. $errorInfo .'</div>
</div>
</div>
';
}
return '';
}
public function runMigrate()
{
$oldApp = \Yii::$app;
Yii::$app = new \yii\console\Application([
'id' => 'install-console',
'basePath' => '@appfront',
'components' => [
'db' => $oldApp->db,
],
]);
$dd = \Yii::$app->runAction('migrate/up', ['migrationPath' => '@fecshop/migrations/mysqldb', 'interactive' => false]);
\Yii::$app = $oldApp;
return $dd ;
}
/*
public function runMigrate()
{
// 通过ob函数截取输出字符
ob_start();
ob_implicit_flush(false);
extract(['oldApp' => \Yii::$app], EXTR_OVERWRITE);
\Yii::$app = new \yii\console\Application([
'id' => 'install-console',
'basePath' => '@appfront',
'components' => [
'db' => $oldApp->db,
],
]);
$result = \Yii::$app->runAction('migrate/up', ['migrationPath' => '@fecshop/migrations/mysqldb', 'interactive' => false]);
\Yii::$app = $oldApp;
$this->_migrateLog = ob_get_clean();
return true;
}
*/
public function dir_mkdir($path = '', $mode = 0777, $recursive = true)
{
clearstatcache();
if (!is_dir($path))
{
mkdir($path, $mode, $recursive);
return chmod($path, $mode);
}
return true;
}
/**
* 文件夹文件拷贝
*
* @param string $sourcePath 来源文件夹
* @param string $targetPath 目的地文件夹
* @param boolean $isForce 是否强制复制
* @return bool
*/
public function copyDir($sourcePath, $targetPath, $isForce = true)
{
if (empty($sourcePath) || empty($targetPath))
{
return false;
}
$dir = opendir($sourcePath);
$this->dir_mkdir($targetPath);
while (false !== ($file = readdir($dir)))
{
if (($file != '.') && ($file != '..')) {
$sourcePathFile = $sourcePath . '/' . $file;
$targetPathFile = $targetPath . '/' . $file;
if (is_dir( $sourcePathFile)) {
$this->copyDir( $sourcePathFile, $targetPathFile);
} else {
//copy($sourcePath . '/' . $file, $targetPath . '/' . $file);
if ($isForce) {
copy($sourcePathFile, $targetPathFile);
} else if (!file_exists($targetPathFile)) {
copy($sourcePathFile, $targetPathFile);
} else {
//Yii::$service->helper->errors->add('target path:' . $targetPathFile . ' is exist.');
}
}
}
}
closedir($dir);
return true;
}
}
<?php
use fec\helpers\CRequest;
?>
<h1>测试产品数据安装</h1>
<br/>
<?= $errorInfo ?>
<?= $successInfo ?>
<br/>
<br/>
<?php echo CRequest::getCsrfInputHtml(); ?>
<p>此步骤执行:</p>
<p>1.产品测试数据sql安装</p>
<p>2.产品的图片复制</p>
<p>3.请勿重复执行该步骤,因为插入的数据只能插入依次,多次插入将会报错,
如果您已经执行了插入的sql,点击跳过进入下一步即可。</p>
<p>4.如果您不想安装测试数据,点击跳过按钮,进入下一步。</p>
<br/>
<br/>
<button type="button" class="btn btn-default testDataInit">测试产品数据安装</button>
<button type="button" class="btn btn-default testDataSkip">跳过</button>
<button type="button" class="btn btn-default install-next" style="display:none;">下一步</button>
<br/>
<br/>
测试产品数据安装:<span class="logshort" style="display:none;color:#cc0000;">正在进行测试产品数据安装...</span>
<span class="logshort-complete" style="display:none;color:green;">测试产品数据安装完成,您可以点击下一步按钮,进行下一步的安装操作</span>
<br/>
<textarea class="initLog" style="width:1200px;height:300px;"></textarea>
<script>
// add to cart js
<?php $this->beginBlock('db_init') ?>
$(document).ready(function(){
$(".install-next").click(function(){
window.location.href="<?= $nextUrl ?>";
});
$(".testDataSkip").click(function(){
window.location.href="<?= $nextUrl ?>";
});
$(".testDataInit").click(function(){
var initUrl = "<?= $initUrl ?>";
$(".logshort").show();
$.ajax({
async:true,
timeout: 6000,
type:'post',
dataType: 'json',
data: {},
url: initUrl,
success:function(data, textStatus){
$(".logshort").hide();
if(data.status == 'success'){
$(".logshort-complete").show();
$(".testDataInit").hide();
$(".testDataSkip").hide();
$(".install-next").show();
} else if(data.status == 'fail'){
$(".initLog").val(data.info);
}
},
error:function (XMLHttpRequest, textStatus, errorThrown){
$(".logshort").hide();
$(".initLog").val(XMLHttpRequest.responseText);
}
});
});
});
<?php $this->endBlock(); ?>
<?php $this->registerJs($this->blocks['db_init'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
</script>
<?php
use fec\helpers\CRequest;
?>
<h1>完成安装</h1>
<br/>
<?= $errorInfo ?>
<?= $successInfo ?>
<br/>
<br/>
<?php echo CRequest::getCsrfInputHtml(); ?>
<p style="font-size:16px;line-height:25px;">您还需要进行如下的步骤:</p>
<p style="font-size:16px;line-height:25px;">1.需要设置安全权限(根目录执行,win不需要执行):<span style="color:#c7254e">chmod 644 common/config/main-local.php</span></p>
<p style="font-size:16px;line-height:25px;">2.删除安装文件 <span style="color:#c7254e">install.php</span>(为了安全,一定要删除掉)(文件路径为:appfront/web/install.php), </p>
<p style="font-size:16px;line-height:25px;">3.后台默认用户名,用户名密码: <span style="color:#c7254e">admin admin123</span></p>
<p style="font-size:16px;line-height:25px;">4.访问后台,更改<span style="color:#c7254e">admin</span>用户密码,然后根据文档进行后台配置 </p>
<br/>
<br/>
<?php
use fec\helpers\CRequest;
?>
<h1>Mysql数据库配置</h1>
<br/>
<?= $errorInfo ?>
<form action="" method="post">
<?php echo CRequest::getCsrfInputHtml(); ?>
<div class="form-group">
<label for="name">Mysql数据库Host</label>
<input type="text" class="form-control" value="<?= $editForm['host'] ?>" name="editForm[host]" placeholder="Mysql数据库Host Ip,本地请填写127.0.0.1">
</div>
<div class="form-group">
<label for="name">Mysql数据库名称</label>
<input type="text" class="form-control" value="<?= $editForm['database'] ?>" name="editForm[database]" placeholder="Mysql数据库名称,请先去mysql中创建数据库,然后再填写">
</div>
<div class="form-group">
<label for="name">Mysql数据库账户</label>
<input type="text" class="form-control" value="<?= $editForm['user'] ?>" name="editForm[user]" placeholder="Mysql数据库账户">
</div>
<div class="form-group">
<label for="name">Mysql数据库密码</label>
<input type="text" class="form-control" value="<?= $editForm['password'] ?>" name="editForm[password]" placeholder="Mysql数据库密码">
</div>
<button type="submit" class="btn btn-default">提交</button>
</form>
\ No newline at end of file
<?php
use fec\helpers\CRequest;
?>
<h1>Mysql数据库表初始化</h1>
<br/>
<?= $errorInfo ?>
<?= $successInfo ?>
<br/>
<br/>
<?php echo CRequest::getCsrfInputHtml(); ?>
<p>此步骤执行:</p>
<p>1.Fecmall 数据库表的migrate,进行数据库的初始化</p>
<p>2.初始化完成后,mysql的表以及索引,将会被建立, 以及初始数据</p>
<br/>
<br/>
<button type="button" class="btn btn-default dbInit">进行数据表初始化</button>
<button type="button" class="btn btn-default install-next" style="display:none;">下一步</button>
<br/>
<br/>
数据库初始化Log:<span class="logshort" style="display:none;color:#cc0000;">正在进行数据库初始化...</span>
<span class="logshort-complete" style="display:none;color:green;">数据库初始化完成,您可以点击下一步按钮,进行下一步的安装操作</span>
<br/>
<textarea class="initLog" style="width:1200px;height:300px;"></textarea>
<script>
// add to cart js
<?php $this->beginBlock('db_init') ?>
$(document).ready(function(){
$(".install-next").click(function(){
window.location.href="<?= $nextUrl ?>";
});
$(".dbInit").click(function(){
var initUrl = "<?= $initUrl ?>";
$(".logshort").show();
$.ajax({
async:true,
timeout: 6000,
type:'post',
data: {},
url: initUrl,
success:function(data, textStatus){
$(".logshort").hide();
$(".initLog").val(data);
// #21 /www/web/develop/fecshop/appfront/web/install.php(20): yii\base\Application->run()
if (data.indexOf('appfront/web/install.php') != -1) {
// 存在错误
} else {
// 不存在错误, 显示跳转下一步的按钮
$(".install-next").show();
$(".logshort-complete").show();
$(".dbInit").hide();
}
},
error:function (XMLHttpRequest, textStatus, errorThrown){
$(".logshort").hide();
$(".initLog").val(XMLHttpRequest.responseText);
}
});
});
});
<?php $this->endBlock(); ?>
<?php $this->registerJs($this->blocks['db_init'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
</script>
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use fecshop\app\appinstall\assets\AppAsset;
use common\widgets\Alert;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => 'FecMall',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
];
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="container body-container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="pull-left">&copy; FecMall <?= date('Y') ?></p>
<p class="pull-right">Powered by <a href="http://www.fecmall.com">FecMall</a></p>
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册