1
1
<?php namespace Spatie \DatabaseBackup \Commands ;
2
2
3
- use Illuminate \Console \Command ;
4
-
5
- class BackupCommand extends Command
3
+ class BackupCommand extends BaseCommand
6
4
{
7
5
/**
8
6
* The console command name.
9
7
*
10
8
* @var string
11
9
*/
12
- protected $ name = 'db.backup ' ;
10
+ protected $ name = 'db:backup ' ;
11
+
13
12
/**
14
13
* The console command description.
15
14
*
16
15
* @var string
17
16
*/
18
17
protected $ description = 'Backup the database to a file ' ;
19
- /**
20
- * Create a new command instance.
21
- *
22
- */
23
- public function __construct ()
24
- {
25
- parent ::__construct ();
26
- }
18
+
19
+ protected $ filePath ;
20
+ protected $ fileName ;
21
+
27
22
/**
28
23
* Execute the console command.
29
24
* @return mixed
30
25
* @throws Exception
31
26
*/
32
27
public function fire ()
33
28
{
29
+ $ this ->info ('Starting database dump... ' );
30
+
31
+ $ database = $ this ->getDatabase ([]);
32
+
33
+ $ this ->checkDumpFolder ();
34
+
35
+ $ this ->fileName = date ('YmdHis ' ).'. ' .$ database ->getFileExtension ();
36
+ $ this ->filePath = rtrim ($ this ->getDumpsPath (), '/ ' ).'/ ' .$ this ->fileName ;
34
37
38
+ $ status = $ database ->dump ($ this ->filePath );
39
+
40
+ if ($ status === true ) {
41
+ $ this ->info ('Database dumped successful in: ' );
42
+ $ this ->comment ($ this ->filePath );
43
+ }
44
+ }
45
+
46
+ protected function getArguments ()
47
+ {
48
+ return [
49
+ ];
35
50
}
36
51
52
+ protected function getOptions ()
53
+ {
54
+ return [
55
+ ];
56
+ }
37
57
38
- }
58
+ /**
59
+ * Checks if dump-folder already exists
60
+ */
61
+ protected function checkDumpFolder ()
62
+ {
63
+ $ dumpsPath = $ this ->getDumpsPath ();
64
+
65
+ if (!is_dir ($ dumpsPath )) {
66
+ mkdir ($ dumpsPath );
67
+ }
68
+ }
69
+ }
0 commit comments