Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.3 refactoring fun-time party land #667

Merged
merged 13 commits into from
Jan 27, 2015
Merged

5.3 refactoring fun-time party land #667

merged 13 commits into from
Jan 27, 2015

Conversation

willmot
Copy link
Contributor

@willmot willmot commented Jan 5, 2015

First bash at a major re-factor to introduce some more modern design patterns and conventions that are available to us now we support PHP 5.3 as a minimum.

What have we here?

  • Moves HM Backup into this repo and renames it class-backup.php
  • Moves the HM Backup tests into the BackUpWordPress tests directory
  • Includes the changes introduced in Add support for copying and updating an existing backups #666 & Add support for updating an existing archive instead of always creating a new one humanmade/hm-backup#77
  • Switches to using Namespaces (HM\BackUpWordPress\) instead of class prefixes throughout
  • Rename some files and classes for consistency, split each class into it's own file
  • De-couple Scheduled_Backup from Backup, the former no longer extends the latter, instead relying on dependancy injection.
  • Required re-factoring several aspects of both classes so they could work together without being so tightly coupled, specifically
    • Correctly set Backup properties using the saved options in Scheduled_Backup::__construct
    • Update all calls to Backup methods that were being called directly through Scheduled_Backup relying on the fact it was a child, instead just call Backup directly
    • Backup::do_action now requires callbacks to be registered by the caller (which Scheduled_Backup has been updaed to do)
    • Get rid of the Backup::set_path && Scheduled_Backup::set_path methods as they were simply duplicating the functionality of Path::set_path
  • Update all tests, they all pass!
  • Also fixes up the issue where some tests were causing each other to fail becuase they weren't properly cleaning up after themselves (see Introduce a HMBKP_Path class to replace hmbkp_path(); #612 (comment))

Other ideas

Backup and Scheduled_Backup are both still large classes that should be modularised, some ways we could go are:

  • Split filesystem stuff (get_files, excludes, filesize stuff) into it's own class
  • Split the handling of the root path into it's own class (ala Path)
  • We'd likely then have Backup_Path and Root_Path both extend a base class Path
  • Move conform_dir to Path from Backup and probably rename it to normalise
  • Split out the various archive and database dump methods into separate classes, each extending a base Backup_Archive & Database_Dump class
  • Feels like Services should be renamed Extensions as that's really what they are
  • Each Service should handle it's own do_action hooking instead of that being coupled in with Scheduled_Backup::do_action
  • Potentially merge Setup into Plugin.

Before we merge

  • Premium extensions will need updating as things have changed in non-backwards compatible ways, not sure how we handle that
  • Moar testing.
  • Fix up as much of the scrutinizer.io complaints
  • Improve code coverage
  • Move github issues from HM-Backup repo over to this repo.

- Requires the delta-zip branch on HM_Backup
- Simply passes the most recent previous backup from the same schedule
- A couple of options weren't correctly specified in the docblock which means they no longer worked since WP_CLI now requires that
- The --path arg conflicted with the existing WP_CLI global path arg
- Removed some backup path cruft that is now handled by HMBKP_Path
It's no longer going to be a separate submodule
First bash at a major re-factor to introduce some more modern design patterns and conventions

- Switches to using Namespaces (`HM\BackUpWordPress\`) instead of class prefixes
- Rename some files and classes for consistency, split each class into it's own file
- De-couple `Scheduled_Backup` from `Backup`, the former no longer extends the latter, instead relying on dependancy injection.
- Required re-factoring several aspects of both classes so they could work together without being so tightly coupled, specifically
 - Correctly set `Backup` properties using the saved options in `Scheduled_Backup::__construct`
 - Update all calls to `Backup` methods that were being called directly through `Scheduled_Backup` relying on the fact it was a child, instead just call `Backup` directly
 - `Backup::do_action` now requires callbacks to be registered by the caller (which `Scheduled_Backup` has been updaed to do)
 - Get rid of the `Backup::set_path` && `Scheduled_Backup::set_path` methods as they were simply duplicating the functionality of `Path::set_path`
- Update all tests, they all pass!
- Also fixup the issue where some tests were causing each other to fail becuase they weren't properly cleaning up after themselves (see #612 (comment))
Stop including backup type and date / time in the database dump filename, it's pointless information and the fact that it caused each dump to be unique was causing issues with the delta backups
@willmot willmot added this to the Future Release milestone Jan 5, 2015
@willmot
Copy link
Contributor Author

willmot commented Jan 5, 2015

Fix up as much of the scrutinizer.io complaints

Fixed up all the major issues reported, still a ton of minor issues.

@pdewouters
Copy link
Contributor

Love this! There are a few in there that were also bothering me, others that I hadn't thought of at all...great stuff

Potentially merge Setup into Plugin.

What would be the benefit?

I agree Service classes can do with some re-architecturing, can be handled in separate PR. Take for example the empty Intercom methods that are just there to satisfy the subclassing

@pdewouters
Copy link
Contributor

Instead of calling

    $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $_GET['hmbkp_schedule_id'] ) ) );

to run a schedule. can't we just do something like

Schedules->get_schedule( $id )->run();

@willmot
Copy link
Contributor Author

willmot commented Jan 21, 2015

Yeah that would be neater although would hit the DB twice instead of once.

@willmot
Copy link
Contributor Author

willmot commented Jan 26, 2015

I've moved all the issue over from HM Backup

parent::set_excludes( HMBKP_EXCLUDE, true );
}
// Setup The Backup class
$this->backup = new Backup();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De-couple Scheduled_Backup from Backup, the former no longer extends the latter, instead relying on dependancy injection.

As I understand it, dependency injection would require the BackUp instance to be passed as a parameter to the constructor

public function __construct( Backup $backup ) {
  $this->backup = $backup;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I ended up not doing that as I hadn't actually run into a situation where I needed to pass something different.

(One of the main reasons for dependancy injection is it means you can pass in mock objects for unit testing purposes)

paul de wouters added 5 commits January 26, 2015 11:02
Conflicts:
	backupwordpress.php
	classes/class-backupwordpress-wp-cli-command.php
	classes/class-path.php
	classes/class-requirements.php
Conflicts:
	classes/class-path.php
pdewouters added a commit that referenced this pull request Jan 27, 2015
5.3 refactoring fun-time party land
@pdewouters pdewouters merged commit d4c215e into master Jan 27, 2015
@pdewouters pdewouters deleted the crazy-refactor branch January 27, 2015 11:03
@willmot willmot mentioned this pull request Jan 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants