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

DbDump   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 2
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