Completed
Push — master ( ff94ff...f5576b )
by Avtandil
04:05
created

DbDump::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 0
dl 0
loc 19
ccs 0
cts 13
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Laravel Platfourm package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\Platfourm\Foundation\Console;
12
13
use Longman\Platfourm\Console\Command;
14
use Symfony\Component\Process\Exception\ProcessFailedException;
15
use Symfony\Component\Process\Process;
16
17
class DbDump extends Command
18
{
19
    /**
20
     * The name and signature of the console command.
21
     *
22
     * @var string
23
     */
24
    protected $signature = 'db:dump';
25
26
    /**
27
     * The console command description.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Dump database';
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return mixed
37
     */
38
    public function handle()
39
    {
40
        $path = storage_path('dump.sql');
41
42
        $config = config('database');
43
44
        $default = $config['default'];
45
        $connection = $config['connections'][$default];
46
47
        $process = new Process('mysqldump --host='.$connection['host'].' --user='.$connection['username'].' --password='.$connection['password'].' '.$connection['database'].' > '.$path);
48
        $process->run();
49
50
        // executes after the command finishes
51
        if (!$process->isSuccessful()) {
52
            throw new ProcessFailedException($process);
53
        }
54
55
        $this->info('Database backup saved to: '.storage_path('dump.sql'));
56
    }
57
}
58