-
Notifications
You must be signed in to change notification settings - Fork 730
/
Copy pathDatabaseRestore.php
86 lines (77 loc) · 1.81 KB
/
DatabaseRestore.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
<?php
namespace App;
use App\Events\DatabaseRestoreFailed;
use App\Events\DatabaseRestoreRunning;
use App\Events\DatabaseRestoreFinished;
use Illuminate\Database\Eloquent\Model;
class DatabaseRestore extends Model
{
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'output',
];
/**
* The database that the restore belongs to.
*/
public function database()
{
return $this->belongsTo(Database::class, 'database_id');
}
/**
* Get the database backup the restore belongs to.
*/
public function backup()
{
return $this->belongsTo(DatabaseBackup::class, 'database_backup_id');
}
/**
* Mark the database restore as running.
*
* @return void
*/
public function markAsRunning()
{
DatabaseRestoreRunning::dispatch(tap($this)->update([
'status' => 'running',
]));
}
/**
* Mark the database restore as finished.
*
* @param string $output
* @return void
*/
public function markAsFinished($output = '')
{
DatabaseRestoreFinished::dispatch(tap($this)->update([
'status' => 'finished',
'exit_code' => 0,
'output' => $output,
]));
}
/**
* Mark the database restore as failed.
*
* @param int $exitCode
* @param string $output
* @return void
*/
public function markAsFailed($exitCode, $output = '')
{
DatabaseRestoreFailed::dispatch(tap($this)->update([
'status' => 'failed',
'exit_code' => $exitCode,
'output' => $output,
]));
}
}