/
Reset.php
78 lines (65 loc) · 1.66 KB
/
Reset.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
<?php
namespace App\Console\Commands;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Process\Process;
use Illuminate\Console\Command;
use File;
class Reset extends Command
{
/**
* human readable command name
*
* @var String
*/
protected $title = 'Sync Automation Job';
/**
* The console command name.
*
* @var string
*/
protected $signature = 'reset:app';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Reset app instance using fresh database instance.';
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
if (!$this->requirement()) {
return;
}
Artisan::call('down');
File::cleanDirectory(storage_path('logs'));
File::cleanDirectory(storage_path('framework/sessions'));
File::cleanDirectory(storage_path('framework/cache'));
File::cleanDirectory(storage_path('framework/temp'));
$command = 'mysql demo < ' . storage_path('db/dump.sql');
$process = new Process($command);
$process->run();
if (!$process->isSuccessful()) {
$this->error($process->getErrorOutput());
}
Artisan::call('up');
}
/**
* Checks mysqldump availability
*
* @return boolean
*/
protected function requirement()
{
$process = new Process('mysqldump --version');
$process->run();
if (!$process->isSuccessful()) {
$this->error($process->getErrorOutput());
return false;
}
return true;
}
}