Completed
Push — master ( 99577b...901a4d )
by Freek
03:36
created

Create::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 4
nop 0
1
<?php
2
3
namespace Spatie\DbSnapshots\Commands;
4
5
use DB;
6
use Carbon\Carbon;
7
use Illuminate\Console\Command;
8
use Spatie\DbSnapshots\Helpers\Format;
9
use Spatie\DbSnapshots\SnapshotFactory;
10
use Illuminate\Console\ConfirmableTrait;
11
12
class Create extends Command
13
{
14
    protected $signature = 'snapshot:create {name?} {--connection}';
15
16
    protected $description = 'Create a new snapshot.';
17
18
    public function handle()
19
    {
20
        $this->info('Creating new snapshot...');
21
22
        $connectionName = $this->option('connection')
23
            ?: config('db-snapshots.default_connection')
24
            ?? config('database.default');
25
26
        $snapshotName = $this->argument('name') ?: Carbon::now()->format('Y-m-d H:i:s');
27
28
        $snapshot = app(SnapshotFactory::class)->create(
29
            $snapshotName,
30
            config('db-snapshots.disk'),
31
            $connectionName
32
        );
33
34
        $size = Format::humanReadableSize($snapshot->size());
35
36
        $this->info("Snapshot `{$snapshotName}` created (size: {$size})");
37
    }
38
}
39