1
1
<?php
2
2
3
+ namespace HM \BackUpWordPress ;
4
+
3
5
/**
4
6
* Implement backup command
5
7
*
6
8
* @todo fix
7
9
* @package wp-cli
8
10
* @subpackage commands/third-party
9
11
*/
10
- class BackUpWordPress_WP_CLI_Command extends WP_CLI_Command {
12
+ class CLI extends \ WP_CLI_Command {
11
13
12
14
/**
13
15
* Perform a Backup.
@@ -26,12 +28,6 @@ class BackUpWordPress_WP_CLI_Command extends WP_CLI_Command {
26
28
* [--root]
27
29
* : dir that should be backed up, defaults to site root.
28
30
*
29
- * [--zip_command_path]
30
- * : path to your zip binary, standard locations are automatically used
31
- *
32
- * [--mysqldump_command_path]
33
- * : path to your mysqldump binary, standard locations are automatically used
34
- *
35
31
* [--archive_filename]
36
32
* : filename for the resulting zip file
37
33
*
@@ -47,39 +43,41 @@ class BackUpWordPress_WP_CLI_Command extends WP_CLI_Command {
47
43
public function backup ( $ args , $ assoc_args ) {
48
44
49
45
add_action ( 'hmbkp_mysqldump_started ' , function () {
50
- WP_CLI ::line ( __ ( 'Backup: Dumping database... ' , 'backupwordpress ' ) );
46
+ \ WP_CLI ::line ( __ ( 'Backup: Dumping database... ' , 'backupwordpress ' ) );
51
47
} );
52
48
53
49
add_action ( 'hmbkp_archive_started ' , function () {
54
- WP_CLI ::line ( __ ( 'Backup: Zipping everything up... ' , 'backupwordpress ' ) );
50
+ \ WP_CLI ::line ( __ ( 'Backup: Zipping everything up... ' , 'backupwordpress ' ) );
55
51
} );
56
52
57
- $ hm_backup = new HM \BackUpWordPress \Backup ();
58
-
59
53
if ( ! empty ( $ assoc_args ['destination ' ] ) ) {
60
- HM \ BackUpWordPress \ Path::get_instance ()->set_path ( $ assoc_args ['destination ' ] );
54
+ Path::get_instance ()->set_path ( $ assoc_args ['destination ' ] );
61
55
}
62
56
63
- HM \ BackUpWordPress \ Path::get_instance ()->cleanup ();
57
+ Path::get_instance ()->cleanup ();
64
58
65
59
if ( ! empty ( $ assoc_args ['root ' ] ) ) {
66
- HM \ BackUpWordPress \ Path->set_root ( $ assoc_args ['root ' ] );
60
+ Path:: get_instance () ->set_root ( $ assoc_args ['root ' ] );
67
61
}
68
62
69
63
if ( ( ! is_dir ( Path::get_path () ) ) ) {
70
- WP_CLI ::error ( __ ( 'Invalid backup path ' , 'backupwordpress ' ) );
64
+ \ WP_CLI ::error ( __ ( 'Invalid backup path ' , 'backupwordpress ' ) );
71
65
return false ;
72
66
}
73
67
74
68
if ( ! is_dir ( Path::get_root () ) || ! is_readable ( Path::get_root () ) ) {
75
- WP_CLI ::error ( __ ( 'Invalid root path ' , 'backupwordpress ' ) );
69
+ \ WP_CLI ::error ( __ ( 'Invalid root path ' , 'backupwordpress ' ) );
76
70
return false ;
77
71
}
78
72
73
+ $ filename = 'backup.zip ' ;
74
+
79
75
if ( isset ( $ assoc_args ['archive_filename ' ] ) ) {
80
- $ hm_backup -> set_archive_filename ( $ assoc_args ['archive_filename ' ] ) ;
76
+ $ filename = $ assoc_args ['archive_filename ' ];
81
77
}
82
78
79
+ $ hm_backup = new Backup ( $ filename );
80
+
83
81
if ( ! empty ( $ assoc_args ['files_only ' ] ) ) {
84
82
$ hm_backup ->set_type ( 'file ' );
85
83
}
@@ -88,28 +86,20 @@ public function backup( $args, $assoc_args ) {
88
86
$ hm_backup ->set_type ( 'database ' );
89
87
}
90
88
91
- if ( isset ( $ assoc_args ['mysqldump_command_path ' ] ) ) {
92
- $ hm_backup ->set_mysqldump_command_path ( $ assoc_args ['mysqldump_command_path ' ] );
93
- }
94
-
95
- if ( isset ( $ assoc_args ['zip_command_path ' ] ) ) {
96
- $ hm_backup ->set_zip_command_path ( $ assoc_args ['zip_command_path ' ] );
97
- }
98
-
99
89
if ( ! empty ( $ assoc_args ['excludes ' ] ) ) {
100
90
$ hm_backup ->set_excludes ( $ assoc_args ['excludes ' ] );
101
91
}
102
92
103
- $ hm_backup ->backup ();
93
+ $ hm_backup ->run ();
104
94
105
- if ( file_exists ( $ hm_backup ->get_archive_filepath () ) ) {
106
- WP_CLI ::success ( __ ( 'Backup Complete: ' , 'backupwordpress ' ) . $ hm_backup ->get_archive_filepath () );
95
+ if ( file_exists ( $ hm_backup ->get_backup_filepath () ) ) {
96
+ \ WP_CLI ::success ( __ ( 'Backup Complete: ' , 'backupwordpress ' ) . $ hm_backup ->get_backup_filepath () );
107
97
} else {
108
- WP_CLI ::error ( __ ( 'Backup Failed ' , 'backupwordpress ' ) );
98
+ \ WP_CLI ::error ( __ ( 'Backup Failed ' , 'backupwordpress ' ) );
109
99
}
110
100
111
101
}
112
102
113
103
}
114
104
115
- WP_CLI ::add_command ( 'backupwordpress ' , 'BackUpWordPress_WP_CLI_Command ' );
105
+ \ WP_CLI ::add_command ( 'backupwordpress ' , 'HM\BackUpWordPress\CLI ' );
0 commit comments