Completed
Push — master ( b56a59...34b930 )
by Avtandil
04:51
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
wmc 2
lcom 0
cbo 3
dl 0
loc 41
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 2
1
<?php
2
/*
3
 * This file is part of the Laravel Lodash 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
declare(strict_types=1);
11
12
namespace Longman\LaravelLodash\Commands;
13
14
use Illuminate\Console\Command;
15
use Symfony\Component\Process\Exception\ProcessFailedException;
16
use Symfony\Component\Process\Process;
17
18
class DbDump extends Command
19
{
20
    /**
21
     * The name and signature of the console command.
22
     *
23
     * @var string
24
     */
25
    protected $signature = 'db:dump';
26
27
    /**
28
     * The console command description.
29
     *
30
     * @var string
31
     */
32
    protected $description = 'Dump database';
33
34
    /**
35
     * Execute the console command.
36
     *
37
     * @return mixed
38
     */
39
    public function handle()
40
    {
41
        $path = storage_path('dump.sql');
42
43
        $config = config('database');
44
45
        $default = $config['default'];
46
        $connection = $config['connections'][$default];
47
48
        $process = new Process('mysqldump --host=' . $connection['host'] . ' --user=' . $connection['username'] . ' --password=' . $connection['password'] . ' ' . $connection['database'] . ' > ' . $path);
49
        $process->run();
50
51
        // executes after the command finishes
52
        if (!$process->isSuccessful()) {
53
            throw new ProcessFailedException($process);
54
        }
55
56
        $this->info('Database backup saved to: ' . storage_path('dump.sql'));
57
    }
58
}
59