1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gameap\Models; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class GdaemonTask |
11
|
|
|
* @package App\Models |
12
|
|
|
* |
13
|
|
|
* @property integer $id |
14
|
|
|
* @property integer $run_aft_id |
15
|
|
|
* @property integer $dedicated_server_id |
16
|
|
|
* @property integer $server_id |
17
|
|
|
* @property string $task |
18
|
|
|
* @property string $data |
19
|
|
|
* @property string $cmd |
20
|
|
|
* @property string $output |
21
|
|
|
* @property string $status |
22
|
|
|
* @property Carbon $created_at |
23
|
|
|
* @property Carbon $updated_at |
24
|
|
|
* |
25
|
|
|
* @property Server $server |
26
|
|
|
*/ |
27
|
|
|
class GdaemonTask extends Model |
28
|
|
|
{ |
29
|
|
|
public const CREATED_AT = 'created_at'; |
30
|
|
|
public const UPDATED_AT = 'updated_at'; |
31
|
|
|
|
32
|
|
|
public const TASK_SERVER_START = 'gsstart'; |
33
|
|
|
public const TASK_SERVER_STOP = 'gsstop'; |
34
|
|
|
public const TASK_SERVER_RESTART = 'gsrest'; |
35
|
|
|
public const TASK_SERVER_UPDATE = 'gsupd'; |
36
|
|
|
public const TASK_SERVER_INSTALL = 'gsinst'; |
37
|
|
|
public const TASK_SERVER_DELETE = 'gsdel'; |
38
|
|
|
public const TASK_SERVER_MOVE = 'gsmove'; |
39
|
|
|
public const TASK_CMD_EXEC = 'cmdexec'; |
40
|
|
|
|
41
|
|
|
public const STATUS_WAITING = 'waiting'; |
42
|
|
|
public const STATUS_WORKING = 'working'; |
43
|
|
|
public const STATUS_ERROR = 'error'; |
44
|
|
|
public const STATUS_SUCCESS = 'success'; |
45
|
|
|
public const STATUS_CANCELED = 'canceled'; |
46
|
|
|
|
47
|
|
|
public const NUM_STATUSES = [ |
48
|
|
|
self::STATUS_WAITING => 1, |
49
|
|
|
self::STATUS_WORKING => 2, |
50
|
|
|
self::STATUS_ERROR => 3, |
51
|
|
|
self::STATUS_SUCCESS => 4, |
52
|
|
|
self::STATUS_CANCELED => 5, |
53
|
|
|
]; |
54
|
|
|
public $table = 'gdaemon_tasks'; |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
public $hidden = [ |
58
|
|
|
'output', |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
public $fillable = [ |
62
|
|
|
'run_aft_id', |
63
|
|
|
'dedicated_server_id', |
64
|
|
|
'server_id', |
65
|
|
|
'task', |
66
|
|
|
'data', |
67
|
|
|
'cmd', |
68
|
|
|
'output', |
69
|
|
|
'status', |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Validation rules |
74
|
|
|
* |
75
|
|
|
* @var array |
76
|
|
|
*/ |
77
|
|
|
public static $rules = [ |
78
|
|
|
|
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* The attributes that should be casted to native types. |
83
|
|
|
* |
84
|
|
|
* @var array |
85
|
|
|
*/ |
86
|
|
|
protected $casts = [ |
87
|
|
|
'id' => 'integer', |
88
|
|
|
'run_aft_id' => 'integer', |
89
|
|
|
'dedicated_server_id' => 'integer', |
90
|
|
|
'server_id' => 'integer', |
91
|
|
|
'task' => 'string', |
92
|
3 |
|
'data' => 'string', |
93
|
|
|
'cmd' => 'string', |
94
|
3 |
|
'output' => 'string', |
95
|
|
|
'status' => 'string', |
96
|
|
|
]; |
97
|
|
|
|
98
|
|
|
public function server(): BelongsTo |
99
|
|
|
{ |
100
|
|
|
return $this->belongsTo(Server::class, 'server_id'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getStatusNumAttribute() |
104
|
|
|
{ |
105
|
|
|
return self::NUM_STATUSES[$this->status]; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|