forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnv.php
More file actions
executable file
·134 lines (114 loc) · 3.02 KB
/
Copy pathEnv.php
File metadata and controls
executable file
·134 lines (114 loc) · 3.02 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "doc_env".
*
* @property int $id
* @property string $encode_id 加密id
* @property string $title 环境名称
* @property string $name 环境标识
* @property string $base_url 环境根路径
* @property int $sort 环境排序
* @property int $status 环境状态
* @property int $project_id 项目id
* @property int $creater_id 创建者id
* @property int $updater_id 更新者id
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
*/
class Env extends Model
{
/**
* 默认环境
* @var array
*/
public $defaultEnvs = [
1 => [
'name' => 'product',
'title' => '生产环境',
],
2 => [
'name' => 'develop',
'title' => '开发环境',
],
3 => [
'name' => 'test',
'title' => '测试环境',
]
];
/**
* 绑定数据表
*/
public static function tableName()
{
return '{{%env}}';
}
/**
* 验证规则
*/
public function rules()
{
return [
[['sort', 'status', 'project_id', 'creater_id'], 'integer'],
[['name'], 'string', 'max' => 10],
[['title','encode_id'], 'string', 'max' => 50],
[['base_url'], 'string', 'max' => 250],
[['encode_id'], 'unique'],
[['created_at', 'updated_at'], 'safe'],
[['encode_id', 'title', 'name', 'base_url', 'project_id', 'creater_id'], 'required'],
];
}
/**
* 字段字典
* @return array
*/
public function attributeLabels()
{
return [
'id' => '环境id',
'encode_id' => '加密id',
'name' => '环境标识',
'title' => '环境名称',
'base_url' => '环境根路径',
'status' => '环境状态',
'sort' => '环境排序',
'project_id' => '项目id',
'creater_id' => '创建者id',
'created_at' => '创建时间',
'updated_at' => '更新时间',
];
}
/**
* 获取项目
* @return \yii\db\ActiveQuery
*/
public function getProject()
{
return $this->hasOne(Project::className(),['id'=>'project_id']);
}
/**
* 创建还不存在的下个环境
* @return string
*/
public function getNextEnv()
{
$query = self::find();
$filter = [
'project_id' => $this->project_id,
'status' => self::ACTIVE_STATUS,
];
$filter['name'] = 'product';
if(!$query->where($filter)->exists()){
return $this->defaultEnvs[1];
}
$filter['name'] = 'develop';
if(!$query->where($filter)->exists()){
return $this->defaultEnvs[2];
}
$filter['name'] = 'test';
if(!$query->where($filter)->exists()){
return $this->defaultEnvs[3];
}
}
}