forked from meolu/walle-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWalleController.php
120 lines (108 loc) · 4.01 KB
/
WalleController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/* *****************************************************************
* @Author: wushuiyong
* @Created Time : 日 1/17 09:22:10 2016
*
* @File Name: WalleController.php
* @Description: walle脚手架
* *****************************************************************/
namespace app\console;
use yii;
use yii\console\Controller;
use yii\helpers\Console;
use app\components\Command;
class WalleController extends Controller {
public $writablePaths = [
'@app/runtime',
'@app/web/assets',
];
public $executablePaths = [
'@app/yii',
];
/**
* checkout the current version 查看版本
*/
public function actionIndex() {
printf("\n\033[32mwalle-web %s (built: %s)\033[0m\nCopyright (c) 2015-2016 The walle-web Group.\nGet Help from [email protected]. Enjoy It.\n\n",
Yii::$app->params['version'], Yii::$app->params['buildTime']);
}
/**
* upgrade walle 更新walle版本
*
* @throws yii\console\Exception
*/
public function actionUpgrade() {
$commander = new Command(['console']);
// stash save local change 暂存本地修改
echo 'stash save local change 暂存本地修改: git stash save ...', PHP_EOL;
$commander->runLocalCommand('/usr/bin/env git stash save');
// pull code 更新代码
echo 'pull code 更新代码: git pull ...', PHP_EOL;
$commander->runLocalCommand('/usr/bin/env git pull --rebase');
// stash pop local change 弹出暂存本地修改
echo 'stash pop local change 弹出暂存本地修改: git stash pop ...', PHP_EOL;
$commander->runLocalCommand('/usr/bin/env git stash pop');
// init walle 初始化项目
$this->runAction('setup', ['interactive' => $this->interactive]);
// checkout the current version查看最新版本
echo "\033[32m\n--------------------------------------------------------", PHP_EOL;
echo "Congratulations To Upgrade. Your Walle Current Version:\033[0m", PHP_EOL;
$this->runAction('index', ['interactive' => $this->interactive]);
}
/**
* init walle 初始化项目
*
* @throws yii\console\Exception
*/
public function actionSetup() {
// create dir 创建目录
echo 'create dir 创建目录...', PHP_EOL;
$this->createDir();
// set writable 设置可写权限
echo 'set writable 设置可写权限...', PHP_EOL;
$this->setWritable();
// set executable 设置可执行权限
echo 'set executable 设置可执行权限...', PHP_EOL;
$this->setExecutable();
// update database 更新数据库
echo 'update database 更新数据库: yii migrate/up ...', PHP_EOL;
\Yii::$app->runAction('migrate/up', ['interactive' => $this->interactive]);
}
/**
* create dir 创建目录
*/
protected function createDir() {
$mkdirPaths = [
yii::$app->params['log.dir'],
yii::$app->params['ansible_hosts.dir'],
'@app/vendor/bower/jquery/dist',
];
foreach ($mkdirPaths as $path) {
$path = Yii::getAlias($path);
Console::output("mkdiring dir: {$path}");
@mkdir($path, 0755, true);
}
}
/**
* set writable 设置可写权限
*/
protected function setWritable() {
$this->writablePaths[] = yii::$app->params['log.dir'];
$this->writablePaths[] = yii::$app->params['ansible_hosts.dir'];
foreach ($this->writablePaths as $writable) {
$writable = Yii::getAlias($writable);
Console::output("Setting writable: {$writable}");
@chmod($writable, 0777);
}
}
/**
* set executable 设置可执行权限
*/
protected function setExecutable() {
foreach ($this->executablePaths as $executable) {
$executable = Yii::getAlias($executable);
Console::output("Setting executable: {$executable}");
@chmod($executable, 0755);
}
}
}