Skip to content

Commit 7031a2b

Browse files
committed
Back compat pass
Ensure the API we expose to Extensions stays backwards compatible. - Renames Site_Backup back to Backup as the extensions use type hinting to ensure that the Backup object is of type `Backup`. - Introduce a back compat `Backup::get_archive_filepath()` which fires a deprecated warning and calls `Backup::get_backup_filepath()`. - Introduce a back compat `Scheduled_Backup::set_status()` which fires a deprecated warning and calls `Scheduled_Backup->status::set_status()`. - Introduce a back compat `hmbkp_add_settings_error` which fires a deprecated warning and calls `add_settings_error`. Tested the existing versions of all our extensions and they now work as intended.
1 parent b87da86 commit 7031a2b

11 files changed

+62
-41
lines changed

admin/actions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function edit_schedule_services_submit() {
193193

194194
if ( $errors ) {
195195
foreach ( $errors as $error ) {
196-
hmbkp_add_settings_error( $error );
196+
add_settings_error( $error );
197197
}
198198
}
199199

classes/backup/class-site-backup.php classes/backup/class-backup.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace HM\BackUpWordPress;
44

5-
class Site_Backup {
5+
class Backup {
66

77
private $excludes;
88
public $warnings = array();
@@ -186,4 +186,15 @@ public function get_backup_filepath() {
186186
return $this->backup_filepath;
187187
}
188188

189+
/**
190+
* Back compat with old method name
191+
*
192+
* @see Backup::get_backup_filepath()
193+
* @deprecated 3.4 Use Backup::get_backup_filepath()
194+
*/
195+
public function get_archive_filepath() {
196+
_deprecated_function( __FUNCTION__, '3.4', 'get_backup_filepath()' );
197+
return $this->get_backup_filepath();
198+
}
199+
189200
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3+
namespace HM\BackUpWordPress;
4+
35
/**
46
* Implement backup command
57
*
68
* @todo fix
79
* @package wp-cli
810
* @subpackage commands/third-party
911
*/
10-
class BackUpWordPress_WP_CLI_Command extends WP_CLI_Command {
12+
class CLI extends \WP_CLI_Command {
1113

1214
/**
1315
* Perform a Backup.
@@ -26,12 +28,6 @@ class BackUpWordPress_WP_CLI_Command extends WP_CLI_Command {
2628
* [--root]
2729
* : dir that should be backed up, defaults to site root.
2830
*
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-
*
3531
* [--archive_filename]
3632
* : filename for the resulting zip file
3733
*
@@ -47,39 +43,41 @@ class BackUpWordPress_WP_CLI_Command extends WP_CLI_Command {
4743
public function backup( $args, $assoc_args ) {
4844

4945
add_action( 'hmbkp_mysqldump_started', function () {
50-
WP_CLI::line( __( 'Backup: Dumping database...', 'backupwordpress' ) );
46+
\WP_CLI::line( __( 'Backup: Dumping database...', 'backupwordpress' ) );
5147
} );
5248

5349
add_action( 'hmbkp_archive_started', function () {
54-
WP_CLI::line( __( 'Backup: Zipping everything up...', 'backupwordpress' ) );
50+
\WP_CLI::line( __( 'Backup: Zipping everything up...', 'backupwordpress' ) );
5551
} );
5652

57-
$hm_backup = new HM\BackUpWordPress\Backup();
58-
5953
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'] );
6155
}
6256

63-
HM\BackUpWordPress\Path::get_instance()->cleanup();
57+
Path::get_instance()->cleanup();
6458

6559
if ( ! empty( $assoc_args['root'] ) ) {
66-
HM\BackUpWordPress\Path->set_root( $assoc_args['root'] );
60+
Path::get_instance()->set_root( $assoc_args['root'] );
6761
}
6862

6963
if ( ( ! is_dir( Path::get_path() ) ) ) {
70-
WP_CLI::error( __( 'Invalid backup path', 'backupwordpress' ) );
64+
\WP_CLI::error( __( 'Invalid backup path', 'backupwordpress' ) );
7165
return false;
7266
}
7367

7468
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' ) );
7670
return false;
7771
}
7872

73+
$filename = 'backup.zip';
74+
7975
if ( isset( $assoc_args['archive_filename'] ) ) {
80-
$hm_backup->set_archive_filename( $assoc_args['archive_filename'] );
76+
$filename = $assoc_args['archive_filename'];
8177
}
8278

79+
$hm_backup = new Backup( $filename );
80+
8381
if ( ! empty( $assoc_args['files_only'] ) ) {
8482
$hm_backup->set_type( 'file' );
8583
}
@@ -88,28 +86,20 @@ public function backup( $args, $assoc_args ) {
8886
$hm_backup->set_type( 'database' );
8987
}
9088

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-
9989
if ( ! empty( $assoc_args['excludes'] ) ) {
10090
$hm_backup->set_excludes( $assoc_args['excludes'] );
10191
}
10292

103-
$hm_backup->backup();
93+
$hm_backup->run();
10494

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() );
10797
} else {
108-
WP_CLI::error( __( 'Backup Failed', 'backupwordpress' ) );
98+
\WP_CLI::error( __( 'Backup Failed', 'backupwordpress' ) );
10999
}
110100

111101
}
112102

113103
}
114104

115-
WP_CLI::add_command( 'backupwordpress', 'BackUpWordPress_WP_CLI_Command' );
105+
\WP_CLI::add_command( 'backupwordpress', 'HM\BackUpWordPress\CLI' );

classes/class-email-service.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private function get_email_address_array() {
150150
* @param string $action The action received from the backup
151151
* @return void
152152
*/
153-
public function action( $action, Site_Backup $backup ) {
153+
public function action( $action, Backup $backup ) {
154154

155155
if ( $action === 'hmbkp_backup_complete' && $this->get_email_address_array() ) {
156156

classes/class-plugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected function includes() {
147147
require_once( HMBKP_PLUGIN_PATH . 'classes/backup/class-backup-engine-file-zip.php' );
148148
require_once( HMBKP_PLUGIN_PATH . 'classes/backup/class-backup-engine-file-zip-archive.php' );
149149

150-
require_once( HMBKP_PLUGIN_PATH . 'classes/backup/class-site-backup.php' );
150+
require_once( HMBKP_PLUGIN_PATH . 'classes/backup/class-backup.php' );
151151

152152
// Load the backup scheduling classes
153153
require_once( HMBKP_PLUGIN_PATH . 'classes/class-scheduled-backup.php' );

classes/class-scheduled-backup.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ public function get_status() {
209209
return $this->status;
210210
}
211211

212+
/**
213+
* Back compat with old set_status mathod
214+
*
215+
* @deprecated 3.4 Backup->status->set_status()
216+
*/
217+
public function set_status( $message ) {
218+
_deprecated_function( __FUNCTION__, '3.4', 'Backup->status->set_status()' );
219+
$this->status->set_status( $message );
220+
}
221+
212222
/**
213223
* Get the array of services options for this schedule
214224
*
@@ -408,7 +418,7 @@ public function run() {
408418
}
409419

410420
// Setup our Site Backup Object
411-
$backup = new Site_Backup( $this->get_backup_filename(), $this->get_database_dump_filename() );
421+
$backup = new Backup( $this->get_backup_filename(), $this->get_database_dump_filename() );
412422
$backup->set_type( $this->get_type() );
413423
$backup->set_excludes( $this->get_excludes() );
414424
$backup->set_status( $this->status );
@@ -462,7 +472,7 @@ public function get_database_dump_filename() {
462472
*
463473
* @param $action
464474
*/
465-
public function do_action( $action, Site_Backup $backup ) {
475+
public function do_action( $action, Backup $backup ) {
466476

467477
// Pass the actions to all the services
468478
// Todo should be decoupled into the service class

classes/class-service.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ abstract public function display();
8686
*
8787
* @return mixed
8888
*/
89-
public function action( $action, Site_Backup $backup ) {}
89+
public function action( $action, Backup $backup ) {}
9090

9191
public function get_slug() {
9292
return sanitize_key( $this->name );

classes/class-webhook-service.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract protected function get_url();
3232
* @param string $action The action received from the backup
3333
* @return void
3434
*/
35-
public function action( $action, Site_Backup $backup ) {
35+
public function action( $action, Backup $backup ) {
3636

3737
if ( 'hmbkp_backup_complete' !== $action || ! $this->is_service_active() ) {
3838
return;

functions/interface.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ function get_settings_url() {
349349
*
350350
* @param $error_message
351351
*/
352-
function add_settings_error( $error_message ){
352+
function add_settings_error( $error_message ) {
353353

354354
$hmbkp_settings_errors = get_transient( 'hmbkp_settings_errors' );
355355

@@ -362,6 +362,16 @@ function add_settings_error( $error_message ){
362362

363363
}
364364

365+
/**
366+
* Back compat version of add_settings_error
367+
*
368+
* @deprecated 3.4 add_settings_error()
369+
*/
370+
function hmbkp_add_settings_error( $error_message ) {
371+
_deprecated_function( __FUNCTION__, '3.4', 'add_settings_error()' );
372+
add_settings_error( $error_message );
373+
}
374+
365375
/**
366376
* Fetch the form submission errors for display.
367377
*

tests/class-site-backup/test-backup-director.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public function setUp() {
88

99
$this->good_backup_engine = new Mock_Backup_Engine;
1010
$this->bad_backup_engine = new Mock_Failing_Backup_Engine;
11-
$this->backup = new Site_Backup( 'backup.zip' );
11+
$this->backup = new Backup( 'backup.zip' );
1212

1313
}
1414

tests/class-site-backup/test-class-site-backup.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class Site_Backup_Tests extends \HM_Backup_UnitTestCase {
66

77
public function setUp() {
8-
$this->backup = new Site_Backup( 'backup.zip' );
8+
$this->backup = new Backup( 'backup.zip' );
99
$this->setup_test_data();
1010
Path::get_instance()->set_path( $this->test_data . '/tmp' );
1111
Path::get_instance()->set_root( $this->test_data );

0 commit comments

Comments
 (0)