Added dependency plugins

This commit is contained in:
Moris Zen
2018-06-25 00:00:37 +02:00
parent 720a1c31a4
commit f069f6782f
698 changed files with 289637 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
<?php
class WPMDBPro_CLI_Addon extends WPMDBPro_Addon {
function __construct( $plugin_file_path ) {
parent::__construct( $plugin_file_path );
$this->plugin_slug = 'wp-migrate-db-pro-cli';
$this->plugin_version = $GLOBALS['wpmdb_meta']['wp-migrate-db-pro-cli']['version'];
$this->php_version_required = $GLOBALS['wpmdb_meta']['wp-migrate-db-pro-cli']['required-php-version'];
if ( ! version_compare( PHP_VERSION, $this->php_version_required, '>=' ) ) {
return;
}
if ( ! $this->meets_version_requirements( '1.7' ) ) {
return;
}
}
}

View File

@@ -0,0 +1,454 @@
<?php
/**
* Migrate your DB using WP Migrate DB Pro.
*/
//require wpmdbpro-command.php from wp-migrate-db-pro
require_once $GLOBALS['wpmdb_meta']['wp-migrate-db-pro']['abspath'] . '/class/wpmdbpro-command.php';
class WPMDBPro_CLI_Command extends WPMDBPro_Command {
/**
* Push local DB up to remote.
*
* ## OPTIONS
*
* <url>
* : The URL of the remote site. Should include the URL encoded basic
* authentication credentials (if required). e.g. http://user:password@example.com
*
* Must include the WordPress directory if WordPress is stored in a subdirectory.
* e.g. http://example.com/wp
*
* <secret-key>
* : The remote site's secret key.
*
* [--find=<strings>]
* : A comma separated list of strings to find when performing a string find
* and replace across the database.
*
* Table names should be quoted as needed, i.e. when using a comma in the
* find/replace string.
*
* The --replace=<strings> argument should be used in conjunction to specify
* the replace values for the strings found using this argument. The number
* of strings specified in this argument should match the number passed into
* --replace=<strings> argument.
*
* If omitted, a set of 2 find and replace pairs will be performed by default:
*
* 1. Strings containing URLs referencing the source site will be replace
* by the destination URL.
*
* 2. Strings containing root file paths referencing the source site will
* be replaced by the destination root file path.
*
* [--replace=<strings>]
* : A comma separated list of replace value strings to implement when
* performing a string find & replace across the database.
*
* Should be used in conjunction with the --find=<strings> argument, see it's
* documentation for further explanation of the find & replace functionality.
*
* [--include-tables=<tables>]
* : The comma separated list of tables to migrate. Excluding this parameter
* will migrate all tables in your database that begin with your
* installation's table prefix, e.g. wp_.
*
* [--exclude-post-types=<post-types>]
* : A comma separated list of post types to exclude. Excluding this parameter
* will migrate all post types.
*
* [--skip-replace-guids]
* : Do not perform a find & replace on the guid column in the wp_posts table.
*
* [--exclude-spam]
* : Exclude spam comments.
*
* [--preserve-active-plugins]
* : Preserves the active_plugins option (which plugins are activated/deactivated).
*
* [--include-transients]
* : Include transients (temporary cached data).
*
* [--backup=<prefix|selected|table_one,table_two,table_etc>]
* : Perform a backup of the destination site's database tables before replacing it.
*
* Accepted values:
*
* * prefix - Backup only tables that begin with your installation's
* table prefix (e.g. wp_)
* * selected - Backup only tables selected for migration (as in --include-tables)
* * A comma separated list of the tables to backup.
*
* [--media=<compare|compare-and-remove|remove-and-copy>]
* : Perform a migration of the media files. Requires the Media Files addon.
*
* Accepted values:
*
* * compare - compares remote and local media files and only uploads
* those missing or updated
* * compare-and-remove - compares remote and local media files and only
* uploads those missing or updated. Removes remote
* media files that are not found on the local site
* * remove-and-copy - removes all remote media files and uploads all local
* media files (skips comparison)
*
* [--media-subsites=<blog-id|subsite-url>]
* : Only transfer media files for selected subsites
*
* * Only applies to multisite installs
* * Separate multiple subsites with commas
* * Use Blog ID or URL of *local* subsites
*
* [--subsite=<blog-id|subsite-url>]
* : Push the given subsite to the remote single site install.
* Requires the Multisite Tools addon.
*
* Overrides the --media-subsites option.
*
* ## EXAMPLES
*
* wp migratedb push http://bradt.ca LJPmq3t8h6uuN7aqQ3YSnt7C88Wzzv5BVPlgLbYE \
* --find=http://dev.bradt.ca,/Users/bradt/home/bradt.ca
* --replace=http://bradt.ca,/home/bradt.ca
* --include-tables=wp_posts,wp_postmeta
*
* @param array $args
* @param array $assoc_args
*
* @since 1.1
*/
public function push( $args, $assoc_args ) {
$assoc_args['action'] = 'push';
$profile = $this->_get_profile_data_from_args( $args, $assoc_args );
if ( is_wp_error( $profile ) ) {
WP_CLI::error( WPMDBPro_CLI::cleanup_message( $profile->get_error_message() ) );
}
$this->_perform_cli_migration( $profile );
}
/**
* Pull remote DB down to local.
*
* ## OPTIONS
*
* <url>
* : The URL of the remote site. Should include the URL encoded basic
* authentication credentials (if required). e.g. http://user:password@example.com
*
* Must include the WordPress directory if WordPress is stored in a subdirectory.
* e.g. http://example.com/wp
*
* <secret-key>
* : The remote site's secret key.
*
* [--find=<strings>]
* : A comma separated list of strings to find when performing a string find
* and replace across the database.
*
* Table names should be quoted as needed, i.e. when using a comma in the
* find/replace string.
*
* The --replace=<strings> argument should be used in conjunction to specify
* the replace values for the strings found using this argument. The number
* of strings specified in this argument should match the number passed into
* --replace=<strings> argument.
*
* If omitted, a set of 2 find and replace pairs will be performed by default:
*
* 1. Strings containing URLs referencing the source site will be replace
* by the destination URL.
*
* 2. Strings containing root file paths referencing the source site will
* be replaced by the destination root file path.
*
* [--replace=<strings>]
* : A comma separated list of replace value strings to implement when
* performing a string find & replace across the database.
*
* Should be used in conjunction with the --find=<strings> argument, see it's
* documentation for further explanation of the find & replace functionality.
*
* [--include-tables=<tables>]
* : The comma separated list of tables to migrate. Excluding this parameter
* will migrate all tables in your database that begin with your
* installation's table prefix, e.g. wp_.
*
* [--exclude-post-types=<post-types>]
* : A comma separated list of post types to exclude. Excluding this parameter
* will migrate all post types.
*
* [--skip-replace-guids]
* : Do not perform a find & replace on the guid column in the wp_posts table.
*
* [--exclude-spam]
* : Exclude spam comments.
*
* [--preserve-active-plugins]
* : Preserves the active_plugins option (which plugins are activated/deactivated).
*
* [--include-transients]
* : Include transients (temporary cached data).
*
* [--backup=<prefix|selected|table_one,table_two,table_etc>]
* : Perform a backup of the destination site's database tables before replacing it.
*
* Accepted values:
*
* * prefix - Backup only tables that begin with your installation's
* table prefix (e.g. wp_)
* * selected - Backup only tables selected for migration (as in --include-tables)
* * A comma separated list of the tables to backup.
*
* [--media=<compare|compare-and-remove|remove-and-copy>]
* : Perform a migration of the media files. Requires the Media Files addon.
*
* Accepted values:
*
* * compare - compares remote and local media files and only downloads
* those missing or updated
* * compare-and-remove - compares remote and local media files and only
* downloads those missing or updated. Removes local
* media files that are not found on the remote site
* * remove-and-copy - removes all local media files and downloads all remote
* media files (skips comparison)
*
* [--media-subsites=<blog-id|subsite-url>]
* : Only transfer media files for selected subsites
*
* * Only applies to multisite installs
* * Separate multiple subsites with commas
* * Use Blog ID or URL of *remote* subsites
*
* [--subsite=<blog-id|subsite-url>]
* : Pull the remote single site install into the given subsite.
* Requires the Multisite Tools addon.
*
* Overrides the --media-subsites option.
*
* ## EXAMPLES
*
* wp migratedb pull http://bradt.ca LJPmq3t8h6uuN7aqQ3YSnt7C88Wzzv5BVPlgLbYE \
* --find=http://dev.bradt.ca,/Users/bradt/home/bradt.ca
* --replace=http://bradt.ca,/home/bradt.ca
* --include-tables=wp_posts,wp_postmeta
*
* @param array $args
* @param array $assoc_args
*
* @since 1.1
*/
public function pull( $args, $assoc_args ) {
$assoc_args['action'] = 'pull';
$profile = $this->_get_profile_data_from_args( $args, $assoc_args );
if ( is_wp_error( $profile ) ) {
WP_CLI::error( WPMDBPro_CLI::cleanup_message( $profile->get_error_message() ) );
}
$this->_perform_cli_migration( $profile );
}
/**
* Run a migration.
*
* ## OPTIONS
*
* <profile>
* : ID of the profile to use for the migration.
*
* ## EXAMPLES
*
* wp migratedb migrate 1
*
* @synopsis <profile>
*
* @param array $args
* @param array $assoc_args
*
* @since 1.0
*/
public function migrate( $args, $assoc_args ) {
$profile = $args[0];
$this->_perform_cli_migration( $profile );
}
/**
* Returns a list of profiles.
*
* @since 1.2.4
*/
public function profiles() {
$wpmdb_settings = get_site_option( 'wpmdb_settings' );
// Display error if no profiles are present
if ( ! isset( $wpmdb_settings['profiles'] ) || ! is_array( $wpmdb_settings['profiles'] ) || empty( $wpmdb_settings['profiles'] ) ) {
WP_CLI::error( __( 'There are no saved profiles for this site.', 'wp-migrate-db-pro-cli' ) );
return;
}
// Get profile information in CLI format
$cli_items = array();
foreach ( $wpmdb_settings['profiles'] as $key => $profile ) {
++ $key;
// Get remote and set empty if action is export/safefile
$connection_info = $profile['connection_info'];
$connection_info = explode( "\n", $connection_info );
$remote = '---';
if ( is_array( $connection_info ) && 2 === count( $connection_info ) ) {
$remote = esc_url_raw( $connection_info[0] );
}
// Allow actions to be translated for output
$action_strings = array(
'push' => _x( 'push', 'Export data to remote database', 'wp-migrate-db-pro-cli' ),
'pull' => _x( 'pull', 'Import data from remote database', 'wp-migrate-db-pro-cli' ),
'savefile' => _x( 'export', 'Export file from local database', 'wp-migrate-db-pro-cli' ),
'find_replace' => _x( 'find & replace', 'Run a find & replace on local database', 'wp-migrate-db-pro-cli' ),
);
if ( isset( $action_strings[ $profile['action'] ] ) ) {
$profile['action'] = $action_strings[ $profile['action'] ];
} else {
$profile['action'] = '---';
}
$profile['action'] = strtoupper( $profile['action'] );
//Populate CLI items with saved profile information
$cli_items[] = array(
_x( 'ID', 'Profile list column heading', 'wp-migrate-db-pro-cli' ) => $key,
_x( 'NAME', 'Profile list column heading', 'wp-migrate-db-pro-cli' ) => $profile['name'],
_x( 'ACTION', 'Profile list column heading', 'wp-migrate-db-pro-cli' ) => $profile['action'],
_x( 'REMOTE', 'Profile list column heading', 'wp-migrate-db-pro-cli' ) => $remote,
);
}
// Set CLI column headers. Must match `cli_items` keys
$cli_keys = array_keys( reset( $cli_items ) );
WP_CLI\Utils\format_items( 'table', $cli_items, $cli_keys );
}
/**
* Run a migration.
*
* ## OPTIONS
*
* <profile>
* : ID of the profile to use for the migration.
*
* ## EXAMPLES
*
* wp migratedb profile 1
*
* @synopsis <profile>
*
* @param array $args
* @param array $assoc_args
*
* @since 1.1
*/
public function profile( $args, $assoc_args ) {
// uses migrate method
$this->migrate( $args, $assoc_args );
}
/**
* Update settings for migratedb.
*
* ## OPTIONS
*
* <action>
* : Either get or update
*
* <setting_name>
* : Name of setting to update or get.
* Available settings: push | pull | connection-key | license
*
* [<value>]
* : Value of new setting
*
* ## EXAMPLES
*
* wp migratedb setting update license xxx-xxx-xxx-xxxxx
*
* wp migratedb setting get license
*
* wp migratedb setting update pull on
*
* wp migratedb setting get pull
*
* @param array $args
*
* @return bool
* @since 1.2.5
*/
public function setting( $args ) {
require_once dirname( __FILE__ ) . '/wpmdbpro-cli-settings.php';
$wpmdb_cli_settings = new WPMDBPro_CLI_Settings( __FILE__ );
// Handle settings logic in dedicated class
$wpmdb_cli_settings->handle_setting( $args );
}
// overrides _perform_cli_migration from WPMDB_Command
protected function _perform_cli_migration( $profile ) {
$wpmdbpro_cli = null;
if ( function_exists( 'wp_migrate_db_pro_cli_addon' ) ) {
$wpmdbpro_cli = wp_migrate_db_pro_cli_addon();
}
if ( empty( $wpmdbpro_cli ) ) {
WP_CLI::error( __( 'WP Migrate DB Pro CLI class not available.', 'wp-migrate-db-pro-cli' ) );
return;
}
$result = $wpmdbpro_cli->cli_migration( $profile );
if ( true === $result ) {
WP_CLI::success( __( 'Migration successful.', 'wp-migrate-db-pro-cli' ) );
} elseif ( ! is_wp_error( $result ) ) {
WP_CLI::success( sprintf( __( 'Export saved to: %s', 'wp-migrate-db-pro-cli' ), $result ) );
} elseif ( is_wp_error( $result ) ) {
WP_CLI::error( WPMDBPro_CLI::cleanup_message( $result->get_error_message() ) );
}
}
}
/**
* Deprecated WP Migrate DB Pro command. Use migratedb instead.
*/
class WPMDBCLI_Deprecated extends WPMDBPro_CLI_Command {
/**
* Run a migration.
*
* ## OPTIONS
*
* <profile>
* : ID of the profile to use for the migration.
*
* ## EXAMPLES
*
* wp wpmdb migrate 1
*
* @synopsis <profile>
*
* @param array $args
* @param array $assoc_args
*
* @since 1.0
*/
public function migrate( $args, $assoc_args ) {
parent::migrate( $args, $assoc_args );
}
}
WP_CLI::add_command( 'wpmdb', 'WPMDBCLI_Deprecated' ); // deprecated older command
WP_CLI::add_command( 'migratedb', 'WPMDBPro_CLI_Command' );

View File

@@ -0,0 +1,188 @@
<?php
/**
* Wrapper for handling WP Migrate DB Pro options via the CLI
*/
require_once $GLOBALS['wpmdb_meta']['wp-migrate-db-pro']['abspath'] . '/class/wpmdb-cli.php';
class WPMDBPro_CLI_Settings extends WPMDB_CLI {
protected $allowed_actions;
protected $allowed_settings;
protected $allowed_push_pull_values;
protected $options_map;
function __construct( $plugin_file_path ) {
$this->doing_cli_migration = true;
$this->is_addon = true;
parent::__construct( $plugin_file_path );
$this->allowed_actions = array( 'get', 'update' );
$this->allowed_settings = array( 'license', 'push', 'pull', 'connection-key' );
$this->allowed_push_pull_values = array( 'off', 'on' );
//Map command line args to option keys
$this->options_map = array(
'push' => 'allow_push',
'pull' => 'allow_pull',
'connection-key' => 'key',
'license' => 'licence',
);
}
/**
*
* Main method for handling the getting and updating of settings
*
* @param $args
*
* @return bool|void
*/
public function handle_setting( $args ) {
/**
*
* $arg[0] = update | get
* $arg[1] = <push|pull|license|key>
* $arg[2] = <new value> - optional if 'update' is action
*
*/
$current_settings = $this->settings;
$allowed_actions = $this->allowed_actions;
$allowed_settings = $this->allowed_settings;
$allowed_push_pull_values = $this->allowed_push_pull_values;
$options_map = $this->options_map;
// Either the action or setting name aren't passed
if ( ! isset( $args[0] ) || ! isset( $args[1] ) ) {
return false;
}
if ( ! in_array( $args[0], $allowed_actions ) ) {
WP_CLI::error( sprintf( __( 'Invalid action parameter - `%s`', 'wp-migrate-db-pro-cli' ), $args[0] ) );
return;
}
if ( ! in_array( $args[1], $allowed_settings ) ) {
WP_CLI::error( sprintf( __( 'Invalid setting parameter - `%s`', 'wp-migrate-db-pro-cli' ), $args[1] ) );
return;
}
// Handle updating of settings
if ( 'update' == $args[0] ) {
// $args[2] is the value to update the settings object with. If it's not set, stop.
if ( ! isset( $args[2] ) ) {
WP_CLI::error( __( 'Please pass a value to update.', 'wp-migrate-db-pro-cli' ) );
}
if ( 'push' == $args[1] || 'pull' == $args[1] ) {
// Only allow valid push/pull values
if ( ! in_array( $args[2], $allowed_push_pull_values ) ) {
WP_CLI::error( sprintf( __( 'Invalid parameter for push/push settings. Value must be `on` or `off`.', 'wp-migrate-db-pro-cli' ), $args[1] ) );
return;
}
$option_name = $options_map[ $args[1] ];
$update = $this->_cli_save_setting( $option_name, $args[2] );
if ( $update ) {
WP_CLI::success( sprintf( __( '%s setting updated.', 'wp-migrate-db-pro-cli' ), $args[1] ) );
} else {
WP_CLI::warning( sprintf( __( 'Setting unchanged.', 'wp-migrate-db-pro-cli' ), $args[1] ) );
}
} elseif ( 'connection-key' == $args[1] ) {
WP_CLI::error( __( 'The connection-key cannot be set via the CLI.', 'wp-migrate-db-pro-cli' ) );
} elseif ( 'license' == $args[1] ) {
// Validates licence against dbrains api
$licence = $this->_handle_licence( $args[2] );
if ( $licence ) {
$update = $this->_cli_save_setting( 'licence', $licence );
// Message only required if setting a new license.
if ( $update ) {
WP_CLI::success( __( 'License updated.', 'wp-migrate-db-pro-cli' ) );
}
}
}
// Handle getting of settings
} elseif ( 'get' == $args[0] ) {
// Because the options arguments are different format than the options keys, use the array map to get the option key
$key = $options_map[ $args[1] ];
// No need to pass the 3rd positional argument to a get command.
if ( isset( $args[2] ) ) {
WP_CLI::error( sprintf( __( 'Too many positional arguments: %s', 'wp-migrate-db-pro-cli' ), $args[2] ) );
}
// If there is a value stored for the given key...
if ( isset( $current_settings[ $key ] ) && '' !== $current_settings[ $key ] ) {
$setting = $current_settings[ $key ];
if ( is_bool( $setting ) ) {
$val = $allowed_push_pull_values[ $setting ];
} else {
$val = $setting;
}
WP_CLI::log( $val );
} else {
WP_CLI::warning( sprintf( __( 'No setting `%s` currently saved in the database.', 'wp-migrate-db-pro-cli' ), $key ) );
}
}
}
/**
*
* Save a WP Migrate DB Pro setting.
* If passing in a license, be sure to pass the value through _handle_license() first to verify the license.
*
* @param $setting_name
* @param $value
*
* @return mixed
*/
protected function _cli_save_setting( $setting_name, $value ) {
$settings = $this->settings;
$new_setting = $value;
if ( 'allow_push' === $setting_name || 'allow_pull' === $setting_name ) {
$new_setting = ( 'on' == $value ) ? true : false;
}else{
$new_setting = sanitize_text_field( $new_setting ); //Sanitize value as update_site_option() doesn't sanitize non-core options.
}
$settings[ $setting_name ] = $new_setting;
$update = update_site_option( 'wpmdb_settings', $settings );
return $update;
}
/**
*
* Validates licence against dbrains api
*
* @param $licence
*
* @return bool
*/
protected function _handle_licence( $licence ) {
$existing_licence = $this->get_licence_key();
if ( $licence == $existing_licence ) {
WP_CLI::warning( __( 'WP Migrate DB Pro already locally activated. No need to set the license.', 'wp-migrate-db-pro-cli' ) );
return false;
}
WP_CLI::log( __( 'Checking license key...', 'wp-migrate-db-pro-cli' ) );
$response = $this->check_licence( $licence );
$decoded_response = json_decode( $response, true );
$licence_valid = isset( $decoded_response['errors'] ) ? false : true;
if ( ! $licence_valid ) {
WP_CLI::error( __( 'Please provide a valid license key.', 'wp-migrate-db-pro-cli' ) );
return false;
}
return $licence;
}
}

View File

@@ -0,0 +1,761 @@
<?php
require_once $GLOBALS['wpmdb_meta']['wp-migrate-db-pro']['abspath'] . '/class/wpmdbpro-cli-export.php';
class WPMDBPro_CLI extends WPMDBPro_CLI_Export {
/**
* Instance of WPMDBPro.
*
* @var WPMDBPro
*/
protected $wpmdbpro;
/**
* Delay Between Requests
*
* @var delay_between_requests
*/
protected $delay_between_requests = 0;
/* remote connection info */
protected $remote;
protected $migration;
function __construct( $plugin_file_path ) {
parent::__construct( $plugin_file_path );
if ( ! version_compare( PHP_VERSION, $this->php_version_required, '>=' ) ) {
return;
}
global $wpmdbpro;
$this->wpmdb = &$this->wpmdbpro;
$this->wpmdbpro = $wpmdbpro;
// announce extra args
add_filter( 'wpmdb_cli_filter_get_extra_args', array( $this, 'filter_extra_args' ), 10, 1 );
// process push/pull profile args
add_filter( 'wpmdb_cli_filter_get_profile_data_from_args', array( $this, 'add_extra_args_for_addon_migrations' ), 10, 3 );
// add backup tables
add_filter( 'wpmdb_cli_filter_before_migrate_tables', array( $this, 'backup_before_migrate_tables' ), 10, 1 );
// extend cli_migration with push/pull functionality
add_filter( 'wpmdb_cli_filter_before_cli_initiate_migration', array( $this, 'extend_cli_migration' ), 10, 1 );
// extend get_tables to migrate with push/pull functionality
add_filter( 'wpmdb_cli_tables_to_migrate', array( $this, 'extend_tables_to_migrate' ), 10, 1 );
//extend get_row_counts_from_table_list with remote tables if necessary
add_filter( 'wpmdb_cli_get_row_counts_from_table_list', array( $this, 'get_push_pull_row_counts' ), 10, 2 );
// check for wpmdbpro version
add_filter( 'wpmdb_cli_profile_before_migration', array( $this, 'check_wpmdbpro_version_before_migration' ), 10, 1 );
// enable profile migrations
add_filter( 'wpmdb_cli_profile_before_migration', array( $this, 'get_wpmdbpro_profile_before_migration' ), 10, 1 );
// check for MF plugin locally
add_filter( 'wpmdb_cli_profile_before_migration', array( $this, 'check_local_wpmdbpro_media_files_before_migration' ), 20, 1 );
// check remote for MF plugin after remote connection has been made
add_filter( 'wpmdb_cli_filter_before_cli_initiate_migration', array( $this, 'check_remote_wpmdbpro_media_files_before_migration' ), 20, 1 );
// flush rewrite rules
add_filter( 'wpmdb_cli_finalize_migration_response', array( $this, 'finalize_flush' ), 20, 1 );
// add backup stage
add_filter( 'wpmdb_cli_initiate_migration_args', array( $this, 'initate_migration_enable_backup' ), 10, 2 );
// use remote tables for pull migration
add_filter( 'wpmdb_cli_filter_source_tables', array( $this, 'set_remote_source_tables_for_pull' ), 10, 1 );
// filter progress label for backup/migration
add_filter( 'wpmdb_cli_progress_label', array( $this, 'modify_progress_label' ), 10, 2 );
// pass through pro filter including remote
add_filter( 'wpmdb_cli_finalize_migration', array( $this, 'apply_pro_cli_finalize_migration_filter' ), 10, 0 );
// add delay between requests
add_action( 'wpmdb_before_remote_post', array( $this, 'do_delay_between_requests' ), 10, 0 );
add_action( 'wpmdb_media_files_cli_before_migrate_media', array( $this, 'do_delay_between_requests' ), 10, 0 );
// Compare table prefixes and display error if mismatch
add_action( 'wpmdb_cli_before_migration', array( $this, 'handle_prefix_mismatch' ), 10, 2 );
}
/**
* Get profile by key.
*
* @since 1.1
*
* @param int $key Profile key
*
* @return array|WP_Error If profile exists return array, otherwise WP_Error.
*/
public function get_profile_by_key( $key ) {
$wpmdb_settings = get_site_option( 'wpmdb_settings' );
--$key;
if ( ! isset( $wpmdb_settings['profiles'][ $key ] ) ) {
return $this->cli_error( __( 'Profile ID not found.', 'wp-migrate-db-pro-cli' ) );
}
return $wpmdb_settings['profiles'][ $key ];
}
/**
* Retrieve information from the remote machine, e.g. tables, prefix, bottleneck, gzip, etc
*
* @return array
*/
function verify_remote_connection() {
do_action( 'wpmdb_cli_before_verify_connection_to_remote_site', $this->profile );
WP_CLI::log( __( 'Verifying connection...', 'wp-migrate-db-pro-cli' ) );
$connection_info = preg_split( '/\s+/', $this->profile['connection_info'] );
$remote_site_args = $this->post_data;
$remote_site_args['intent'] = $this->profile['action'];
$remote_site_args['url'] = trim( $connection_info[0] );
$remote_site_args['key'] = trim( $connection_info[1] );
$this->post_data = apply_filters( 'wpmdb_cli_verify_connection_to_remote_site_args', $remote_site_args, $this->profile );
$response = $this->verify_connection_to_remote_site( $this->post_data );
$verified_response = $this->verify_cli_response( $response, 'ajax_verify_connection_to_remote_site()' );
if ( ! is_wp_error( $verified_response ) ) {
$verified_response = apply_filters( 'wpmdbpro_cli_verify_connection_response', $verified_response );
}
return $verified_response;
}
/**
* Determine which tables to backup (if required)
*
* @return mixed|void
*/
function get_tables_to_backup() {
$tables_to_backup = array();
$action = $this->profile['action'];
if ( ! in_array( $action, array( 'push', 'pull' ) ) ) {
$action = 'pull';
}
if ( 'push' === $action ) {
$all_tables = $this->remote['tables'];
$prefixed_tables = $this->remote['prefixed_tables'];
} else {
$all_tables = $this->get_tables();
$prefixed_tables = $this->get_tables( 'prefix' );
}
switch ( $this->profile['backup_option'] ) {
case 'backup_only_with_prefix':
$tables_to_backup = $prefixed_tables;
break;
case 'backup_selected':
//
// When tables to migrate is tables with prefix, select_tables
// might be empty. Intersecting it with remote/local tables
// throws notice/warning and won't backup the file either.
//
if ( 'migrate_only_with_prefix' === $this->profile['table_migrate_option'] ) {
$tables_to_backup = $prefixed_tables;
} else {
$tables_to_backup = array_intersect( $this->profile['select_tables'], $all_tables );
}
break;
case 'backup_manual_select':
$tables_to_backup = array_intersect( $this->profile['select_backup'], $all_tables );
break;
}
return apply_filters( 'wpmdb_cli_tables_to_backup', $tables_to_backup, $this->profile, $this->remote, $this->migration );
}
/**
* Stub for ajax_verify_connection_to_remote_site()
*
* @param array|bool $args
*
* @return array
*/
function verify_connection_to_remote_site( $args = false ) {
$_POST = $args;
$response = $this->wpmdbpro->ajax_verify_connection_to_remote_site();
return $response;
}
/**
* Stub for ajax_flush()
*
* @param array|bool $args
*
* @return bool|null
*/
function flush( $args = false ) {
$_POST = $args;
$response = $this->wpmdbpro->ajax_flush();
return $response;
}
/**
* Add extra CLI args used by this plugin.
*
* @param array $args
*
* @return array
*/
public function filter_extra_args( $args = array() ) {
$args[] = 'preserve-active-plugins';
$args[] = 'include-transients';
$args[] = 'backup';
// TODO: Move following to WPMDBPro_Media_Files_CLI along with Media Files args parsing.
$args[] = 'media';
$args[] = 'media-subsites';
return $args;
}
/**
* Extend get_profile_data_from_args with options for push/pull
* hooks on: wpmdb_cli_filter_get_profile_data_from_args
*
* @param array $profile
* @param array $args
* @param array $assoc_args
*
* @return array|WP_Error
*/
function add_extra_args_for_addon_migrations( $profile, $args, $assoc_args ) {
if ( ! is_array( $profile ) ) {
return $profile;
}
if ( ! in_array( $assoc_args['action'], array( 'find_replace', 'savefile' ) ) ) {
if ( empty( $args[0] ) || empty( $args[1] ) ) {
return $this->cli_error( __( 'URL and secret-key are required', 'wp-migrate-db-pro-cli' ) );
}
$connection_info = sprintf( '%s %s', $args[0], $args[1] );
}
// --preserve-active-plugins
$keep_active_plugins = intval( isset( $assoc_args['preserve-active-plugins'] ) );
// --include-transients.
$exclude_transients = intval( ! isset( $assoc_args['include-transients'] ) );
// --backup.
$create_backup = 0;
$backup_option = 'backup_only_with_prefix';
$select_backup = array( '' );
if ( ! empty( $assoc_args['backup'] ) ) {
$create_backup = 1;
if ( ! in_array( $assoc_args['backup'], array( 'prefix', 'selected' ) ) ) {
$backup_option = 'backup_manual_select';
$select_backup = explode( ',', $assoc_args['backup'] );
} elseif ( 'selected' === $assoc_args['backup'] ) {
$backup_option = 'backup_selected';
}
}
// TODO: move this to the media files cli codebase
// --media
$media_vars = array();
if ( ! empty( $assoc_args['media'] ) ) {
if ( ! class_exists( 'WPMDBPro_Media_Files' ) ) {
return $this->cli_error( __( 'The Media Files addon needs to be installed and activated to make use of this option', 'wp-migrate-db-pro-cli' ) );
} else {
if ( ! in_array( $assoc_args['media'], array( 'remove-and-copy', 'compare-and-remove', 'compare' ) ) ) {
return $this->cli_error( __( '--media must be set to an acceptable value, see: wp help migratedb ' . $assoc_args['action'], 'wp-migrate-db-pro-cli' ) );
}
$media_files = 1;
$remove_local_media = 0;
$media_migration_option = ( 'remove-and-copy' == $assoc_args['media'] ) ? 'entire' : 'compare';
if ( 'compare-and-remove' == $assoc_args['media'] ) {
$remove_local_media = 1;
}
$media_vars = array( 'media_files', 'media_migration_option', 'remove_local_media' );
}
}
// --media-subsites
if ( isset( $assoc_args['media-subsites'] ) ) {
if ( ! is_multisite() ) {
return $this->cli_error( __( 'The --media-subsites option can only be used on a multisite install', 'wp-migrate-db-pro-cli' ) );
}
if ( empty( $assoc_args['media'] ) ) {
return $this->cli_error( __( 'The --media-subsites option can only be used in conjunction with the --media option', 'wp-migrate-db-pro-cli' ) );
}
if ( empty( $assoc_args['media-subsites'] ) ) {
return $this->cli_error( __( 'One or more valid Blog IDs or Subsite URLs must be supplied to make use of the --media-subsites option', 'wp-migrate-db-pro-cli' ) );
}
$mf_select_subsites = 1;
$mf_selected_subsites = str_getcsv( $assoc_args['media-subsites'] );
$media_vars[] = 'mf_select_subsites';
$media_vars[] = 'mf_selected_subsites';
}
$filtered_profile = compact(
'connection_info',
'exclude_transients',
'keep_active_plugins',
'create_backup',
'backup_option',
'select_backup',
$media_vars
);
return array_merge( $profile, $filtered_profile );
}
/**
* Add backup stage when selected
* hooks on: wpmdb_cli_filter_before_migrate_tables
*
* @param array $filter_vars
*
* @return array|WP_Error
*/
function backup_before_migrate_tables( $filter_vars ) {
// No good reason this should happen, but lets not risk an undefined index warning
if ( ! array_key_exists( 'tables', $filter_vars ) ) {
return $filter_vars;
}
$tables = $filter_vars['tables'];
$tables_to_backup = $this->get_tables_to_backup();
if ( 'backup' == $this->post_data['stage'] &&
'backup_manual_select' == $this->profile['backup_option'] &&
array_diff( $this->profile['select_backup'], $tables_to_backup )
) {
return $this->cli_error( __( 'Invalid backup option or non-existent table selected for backup.', 'wp-migrate-db-pro-cli' ) );
}
$tables = ( 'backup' == $this->post_data['stage'] ) ? $tables_to_backup : $tables;
$stage_iterator = ( 'backup' == $this->post_data['stage'] ) ? 1 : 2;
return compact( 'tables', 'stage_iterator' );
}
/**
* Extend cli_migration with push/pull
* hooks on: wpmdb_cli_filter_before_cli_initiate_migration
*
* @param array $profile
*
* @return array
*/
function extend_cli_migration( $profile ) {
if ( ! in_array( $profile['action'], array( 'find_replace', 'savefile' ) ) ) {
$this->remote = $this->verify_remote_connection();
if ( is_wp_error( $this->remote ) ) {
return $this->remote;
}
$this->post_data['gzip'] = ( '1' == $this->remote['gzip'] ) ? 1 : 0;
$this->post_data['bottleneck'] = $this->remote['bottleneck'];
$this->post_data['prefix'] = $this->remote['prefix'];
$this->post_data['site_details']['remote'] = $this->remote['site_details'];
// set delay between requests if remote has a delay
if ( isset( $this->remote['delay_between_requests'] ) ) {
$this->delay_between_requests = $this->remote['delay_between_requests'];
}
if ( ! empty( $this->remote['temp_prefix'] ) ) {
$this->post_data['temp_prefix'] = $this->remote['temp_prefix'];
}
// Default the find/replace pairs if nothing specified so that we don't break the target.
if ( empty( $profile['replace_old'] ) && empty( $profile['replace_new'] ) ) {
$local = array(
'',
preg_replace( '#^https?:#', '', home_url() ),
$this->get_absolute_root_file_path(),
);
$remote = array(
'',
preg_replace( '#^https?:#', '', $this->remote['url'] ),
$this->remote['path'],
);
if ( 'push' == $profile['action'] ) {
$profile['replace_old'] = $local;
$profile['replace_new'] = $remote;
} else {
$profile['replace_old'] = $remote;
$profile['replace_new'] = $local;
}
unset( $local, $remote );
$profile = apply_filters( 'wpmdb_cli_default_find_and_replace', $profile, $this->post_data );
}
}
return $profile;
}
/**
* Return correct set of tables to migrate on push/pull migrations
* hooks on: wpmdb_cli_tables_to_migrate
*
* @param array $tables_to_migrate
*
* @return array
*/
function extend_tables_to_migrate( $tables_to_migrate ) {
if ( 'push' == $this->profile['action'] ) {
if ( 'migrate_only_with_prefix' == $this->profile['table_migrate_option'] ) {
$tables_to_migrate = $this->get_tables( 'prefix' );
} elseif ( 'migrate_select' == $this->profile['table_migrate_option'] ) {
$tables_to_migrate = array_intersect( $this->profile['select_tables'], $this->get_tables() );
}
} elseif ( 'pull' == $this->profile['action'] ) {
if ( 'migrate_only_with_prefix' == $this->profile['table_migrate_option'] ) {
$tables_to_migrate = $this->remote['prefixed_tables'];
} elseif ( 'migrate_select' == $this->profile['table_migrate_option'] ) {
$tables_to_migrate = array_intersect( $this->profile['select_tables'], $this->remote['tables'] );
}
}
return $tables_to_migrate;
}
/**
* Return correct row counts for stage/migration type
* hooks on: wpmdb_cli_get_row_counts_from_table_list
*
* @param array $cached_stage_results
* @param int $stage
*
* @return array
*/
function get_push_pull_row_counts( $cached_stage_results, $stage ) {
$migration_type = $this->profile['action'];
$local_table_rows = $cached_stage_results;
$remote_table_rows = $this->remote['table_rows'];
if ( 1 === $stage ) { // 1 = backup stage, 2 = migration stage
$cached_stage_results = ( 'pull' === $migration_type ) ? $local_table_rows : $remote_table_rows;
} else {
$cached_stage_results = ( 'pull' === $migration_type ) ? $remote_table_rows : $local_table_rows;
}
return $cached_stage_results;
}
/**
* Error if WPMDBPro version is not compatible
* hooks on: wpmdb_cli_profile_before_migration
*
* @param array $profile
*
* @return array|WP_Error
*/
function check_wpmdbpro_version_before_migration( $profile ) {
// TODO: maybe instantiate WPMDBPro_CLI_Addon to make WPMDBPro_Addon::meets_version_requirements() available here
$wpmdb_pro_version = $GLOBALS['wpmdb_meta']['wp-migrate-db-pro']['version'];
if ( ! version_compare( $wpmdb_pro_version, '1.7', '>=' ) ) {
return $this->cli_error( __( 'Please update WP Migrate DB Pro.', 'wp-migrate-db-pro-cli' ) );
}
return $profile;
}
/**
* Get profile by key
* hooks on: wpmdb_cli_profile_before_migration
*
* @param array $profile
*
* @return array|WP_Error
*/
function get_wpmdbpro_profile_before_migration( $profile ) {
if ( is_wp_error( $profile ) ) {
return $profile;
}
if ( empty( $profile ) ) {
return $this->cli_error( __( 'Profile ID missing.', 'wp-migrate-db-pro-cli' ) );
} elseif ( ! is_array( $profile ) ) {
$profile = $this->get_profile_by_key( absint( $profile ) );
// don't exclude post types if the option isn't checked
if( ! is_wp_error( $profile ) && ! $profile['exclude_post_types'] ) {
$profile['select_post_types'] = array();
}
}
return $profile;
}
/**
* Check if MF option enabled in profile but plugin not active locally.
* hooks on: wpmdb_cli_profile_before_migration
*
* @param array $profile
*
* @return array|WP_Error
*/
function check_local_wpmdbpro_media_files_before_migration( $profile ) {
if ( is_wp_error( $profile ) ) {
return $profile;
}
if ( isset( $profile['media_files'] ) && true == $profile['media_files'] ) {
if ( false === class_exists( 'WPMDBPro_Media_Files' ) ) {
return $this->cli_error( __( 'The profile is set to migrate media files, however WP Migrate DB Pro Media Files does not seem to be installed/active on the local website.', 'wp-migrate-db-pro-cli' ) );
}
}
return $profile;
}
/**
* Check if MF option enabled in profile but plugin not active on remote and that selected subsites make sense if being used.
* hooks on: wpmdb_cli_filter_before_cli_initiate_migration
*
* @param array $profile
*
* @return array|WP_Error
*/
function check_remote_wpmdbpro_media_files_before_migration( $profile ) {
if ( is_wp_error( $profile ) ) {
return $profile;
}
if ( isset( $this->profile['media_files'] ) && true == $this->profile['media_files'] ) {
if ( ! isset( $this->remote['media_files_max_file_uploads'] ) ) {
return $this->cli_error( __( 'The profile is set to migrate media files, however WP Migrate DB Pro Media Files does not seem to be installed/active on the remote website.', 'wp-migrate-db-pro-cli' ) );
}
}
if ( is_multisite() && ! empty( $profile['mf_select_subsites'] ) && 'savefile' !== $profile['action'] ) {
if ( 'pull' === $profile['action'] ) {
if ( empty( $this->remote['subsites'] ) || ! is_array( $this->remote['subsites'] ) ) {
return $this->cli_error( __( 'One or more subsites should exist on the remote to make use of the --media-subsites option', 'wp-migrate-db-pro-cli' ) );
}
$subsites_list = $this->remote['subsites'];
} else {
$subsites_list = $this->subsites_list();
}
$mf_selected_subsites = $this->get_subsite_ids( $profile['mf_selected_subsites'], $subsites_list );
if ( empty( $mf_selected_subsites ) || in_array( false, $mf_selected_subsites ) ) {
return $this->cli_error( __( 'One or more valid Blog IDs or Subsite URLs must be supplied to make use of the --media-subsites option', 'wp-migrate-db-pro-cli' ) );
}
// We now have a validated and clean set of blog ids to use.
$profile['mf_selected_subsites'] = $mf_selected_subsites;
}
return $profile;
}
/**
* Flush rewrite rules
* hooks on: wpmdb_cli_finalize_migration_response
*
* @param string $response
*
* @return string
*/
function finalize_flush( $response ) {
WP_CLI::log( _x( 'Flushing caches and rewrite rules...', 'The caches and rewrite rules for the target are being flushed', 'wp-migrate-db-pro-cli' ) );
$args = $this->filter_post_elements( $this->post_data, array( 'action', 'migration_state_id' ) );
$response = $this->flush( $args );
return trim( $response );
}
/**
* Check profile for backup option and set stage appropriately
* hooks on: wpmdb_cli_initiate_migration_args
*
* @param array $migration_args
* @param array $profile
*
* @return array
*/
function initate_migration_enable_backup( $migration_args, $profile ) {
if ( '0' != $profile['create_backup'] ) {
$migration_args['stage'] = 'backup';
}
return $migration_args;
}
/**
* Use remote tables for pull migration
* hooks on: wpmdb_cli_filter_source_tables
*
* @param $source_tables
*
* @return array
*/
function set_remote_source_tables_for_pull( $source_tables ) {
if ( 'pull' == $this->profile['action'] ) {
$source_tables = $this->remote['tables'];
}
return $source_tables;
}
/**
* Update progress label for migrations / backups
* hooks on: 'wpmdb_cli_progress_label
*
* @param string $progress_label
* @param int $stage
*
* @return string
*/
function modify_progress_label( $progress_label, $stage ) {
if ( 'savefile' !== $this->profile['action'] && 'find_replace' !== $this->profile['action'] ) {
if ( 1 === $stage ) { // 1 = backup stage, 2 = migration stage
$progress_label = __( 'Performing backup', 'wp-migrate-db-pro-cli' );
} else {
$progress_label = __( 'Migrating tables', 'wp-migrate-db-pro-cli' );
}
}
return $progress_label;
}
/**
* Apply pro only finalize migration filter
* hooks on: wpmdb_cli_finalize_migration
*
* @return mixed
*/
function apply_pro_cli_finalize_migration_filter() {
return apply_filters( 'wpmdb_pro_cli_finalize_migration', true, $this->profile, $this->remote, $this->migration );
}
function do_delay_between_requests() {
if ( 0 < $this->delay_between_requests ) {
sleep( $this->delay_between_requests / 1000 );
}
}
/**
*
* Detects a database prefix mismatch and displays a CLI message about it. Does not interrupt the migration.
*
* @param $post_data
*
* @return bool
*/
public function handle_prefix_mismatch( $post_data, $profile ) {
global $wpdb;
$local_prefix = $wpdb->base_prefix;
$remote_prefix = $this->get_remote_prefix( $post_data );
$mismatch = null;
$message = '';
if ( ! empty( $local_prefix ) && ! empty( $remote_prefix ) ) {
$mismatch = false;
if ( $local_prefix !== $remote_prefix ) {
$mismatch = true;
}
}
$subsite_prefix_mismatch = $this->is_multisite_prefix_mismatch( $post_data, $profile, $mismatch );
if ( true === $mismatch ) {
if ( isset( $post_data['intent'] ) ) {
$message = "%Y" . __( "Database table prefix differs between installations.", 'wp-migrate-db-cli' );
$message .= "%n \n%R";
if ( true === $subsite_prefix_mismatch ) {
$message .= sprintf( __( "We have detected you have table prefix \"%s\" at %s but have \"%s\" here. Multisite Tools currently only supports migrating subsites between sites with the same base table prefix.", 'wp-migrate-db-cli' ), $remote_prefix, $post_data['site_details']['remote']['site_url'], $wpdb->base_prefix );
} else {
if ( 'push' == $post_data['intent'] ) {
$message .= sprintf( __( "The remote database uses a prefix of \"%s\". This migration will create new tables in the remote database with a prefix of \"%s\". \nTo use these new tables, AFTER the migration is complete, you will need to edit the wp-config.php file on the remote server and change the \$table_prefix variable to \"%s\"", 'wp-migrate-db-cli' ), $remote_prefix, $wpdb->base_prefix, $wpdb->base_prefix );
} else if ( 'pull' == $post_data['intent'] ) {
$message .= sprintf( __( "The local database uses a prefix of \"%s\". This migration will create new tables in the local database with a prefix of \"%s\". \nTo use these new tables, AFTER the migration is complete, you will need to edit your wp-config.php file in your local environment and change the \$table_prefix variable to \"%s\"", 'wp-migrate-db-cli' ), $wpdb->base_prefix, $remote_prefix, $remote_prefix );
}
}
$message .= "%n";
}
// Only display the CLI warning if invoked manually.
if ( ! defined( 'DOING_WPMDB_TESTS' ) ) {
if ( false === $subsite_prefix_mismatch ) {
WP_CLI::warning( WP_CLI::colorize( $message ) );
} else {
WP_CLI::error( WP_CLI::colorize( $message ) );
}
}
}
return $mismatch;
}
/**
*
* Returns the remote database prefix, based on global $_POST data
*
* @param $post_data
*
* @return string
*/
public function get_remote_prefix( $post_data ) {
$remote_prefix = '';
if ( isset( $post_data['site_details']['remote']['prefix'] ) ) {
$remote_prefix = $post_data['site_details']['remote']['prefix'];
}
return $remote_prefix;
}
/**
*
* Detects if a CLI migration is attempted from a multisite, with the --subsite option, and where the table prefixes do no match
*
* @param $post_data
* @param $profile
* @param $is_mismatch
*
* @return bool
*/
public function is_multisite_prefix_mismatch( $post_data, $profile, $is_mismatch ) {
$subsite_prefix_mismatch = false;
$migration_details = $post_data['site_details'];
if ( true === $is_mismatch ) {
if ( isset( $migration_details['local']['is_multisite'] ) && 'true' === $migration_details['local']['is_multisite'] ) {
$mst_select_subsite = isset( $profile['mst_select_subsite'] ) ? $profile['mst_select_subsite'] : 0;
if ( '1' == $mst_select_subsite ) {
$subsite_prefix_mismatch = true; //If there is a selected subsite, and it's multisite, and there's a prefix mistmatch
}
}
}
return $subsite_prefix_mismatch;
}
}

View File

@@ -0,0 +1,260 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the wp-migrate-db-pro-cli package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: wp-migrate-db-pro-cli\n"
"Report-Msgid-Bugs-To: nom@deliciousbrains.com\n"
"POT-Creation-Date: 2016-11-01 09:12-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: class/wpmdbpro-cli-command.php:290
msgid "There are no saved profiles for this site."
msgstr ""
#: class/wpmdbpro-cli-command.php:309
msgctxt "Export data to remote database"
msgid "push"
msgstr ""
#: class/wpmdbpro-cli-command.php:310
msgctxt "Import data from remote database"
msgid "pull"
msgstr ""
#: class/wpmdbpro-cli-command.php:311
msgctxt "Export file from local database"
msgid "export"
msgstr ""
#: class/wpmdbpro-cli-command.php:312
msgctxt "Run a find & replace on local database"
msgid "find & replace"
msgstr ""
#: class/wpmdbpro-cli-command.php:324
msgctxt "Profile list column heading"
msgid "ID"
msgstr ""
#: class/wpmdbpro-cli-command.php:325
msgctxt "Profile list column heading"
msgid "NAME"
msgstr ""
#: class/wpmdbpro-cli-command.php:326
msgctxt "Profile list column heading"
msgid "ACTION"
msgstr ""
#: class/wpmdbpro-cli-command.php:327
msgctxt "Profile list column heading"
msgid "REMOTE"
msgstr ""
#: class/wpmdbpro-cli-command.php:407
msgid "WP Migrate DB Pro CLI class not available."
msgstr ""
#: class/wpmdbpro-cli-command.php:414
msgid "Migration successful."
msgstr ""
#: class/wpmdbpro-cli-command.php:416
#, php-format
msgid "Export saved to: %s"
msgstr ""
#: class/wpmdbpro-cli-settings.php:61
#, php-format
msgid "Invalid action parameter - `%s`"
msgstr ""
#: class/wpmdbpro-cli-settings.php:67
#, php-format
msgid "Invalid setting parameter - `%s`"
msgstr ""
#: class/wpmdbpro-cli-settings.php:76
msgid "Please pass a value to update."
msgstr ""
#: class/wpmdbpro-cli-settings.php:82
msgid "Invalid parameter for push/push settings. Value must be `on` or `off`."
msgstr ""
#: class/wpmdbpro-cli-settings.php:90
#, php-format
msgid "%s setting updated."
msgstr ""
#: class/wpmdbpro-cli-settings.php:92
msgid "Setting unchanged."
msgstr ""
#: class/wpmdbpro-cli-settings.php:95
msgid "The connection-key cannot be set via the CLI."
msgstr ""
#: class/wpmdbpro-cli-settings.php:103
msgid "License updated."
msgstr ""
#: class/wpmdbpro-cli-settings.php:114
#, php-format
msgid "Too many positional arguments: %s"
msgstr ""
#: class/wpmdbpro-cli-settings.php:127
#, php-format
msgid "No setting `%s` currently saved in the database."
msgstr ""
#: class/wpmdbpro-cli-settings.php:170
msgid ""
"WP Migrate DB Pro already locally activated. No need to set the license."
msgstr ""
#: class/wpmdbpro-cli-settings.php:175
msgid "Checking license key..."
msgstr ""
#: class/wpmdbpro-cli-settings.php:181
msgid "Please provide a valid license key."
msgstr ""
#: class/wpmdbpro-cli.php:103
msgid "Profile ID not found."
msgstr ""
#: class/wpmdbpro-cli.php:117
msgid "Verifying connection..."
msgstr ""
#: class/wpmdbpro-cli.php:246
msgid "URL and secret-key are required"
msgstr ""
#: class/wpmdbpro-cli.php:276
msgid ""
"The Media Files addon needs to be installed and activated to make use of "
"this option"
msgstr ""
#: class/wpmdbpro-cli.php:279
msgid "--media must be set to an acceptable value, see: wp help migratedb "
msgstr ""
#: class/wpmdbpro-cli.php:296
msgid "The --media-subsites option can only be used on a multisite install"
msgstr ""
#: class/wpmdbpro-cli.php:299
msgid ""
"The --media-subsites option can only be used in conjunction with the --media "
"option"
msgstr ""
#: class/wpmdbpro-cli.php:302
#: class/wpmdbpro-cli.php:562
msgid ""
"One or more valid Blog IDs or Subsite URLs must be supplied to make use of "
"the --media-subsites option"
msgstr ""
#: class/wpmdbpro-cli.php:346
msgid "Invalid backup option or non-existent table selected for backup."
msgstr ""
#: class/wpmdbpro-cli.php:475
msgid "Please update WP Migrate DB Pro."
msgstr ""
#: class/wpmdbpro-cli.php:495
msgid "Profile ID missing."
msgstr ""
#: class/wpmdbpro-cli.php:523
msgid ""
"The profile is set to migrate media files, however WP Migrate DB Pro Media "
"Files does not seem to be installed/active on the local website."
msgstr ""
#: class/wpmdbpro-cli.php:545
msgid ""
"The profile is set to migrate media files, however WP Migrate DB Pro Media "
"Files does not seem to be installed/active on the remote website."
msgstr ""
#: class/wpmdbpro-cli.php:552
msgid ""
"One or more subsites should exist on the remote to make use of the --media-"
"subsites option"
msgstr ""
#: class/wpmdbpro-cli.php:582
msgctxt "The caches and rewrite rules for the target are being flushed"
msgid "Flushing caches and rewrite rules..."
msgstr ""
#: class/wpmdbpro-cli.php:635
msgid "Performing backup"
msgstr ""
#: class/wpmdbpro-cli.php:637
msgid "Migrating tables"
msgstr ""
#: class/wpmdbpro-cli.php:688
msgid "Database table prefix differs between installations."
msgstr ""
#: class/wpmdbpro-cli.php:692
#, php-format
msgid ""
"We have detected you have table prefix \"%s\" at %s but have \"%s\" here. "
"Multisite Tools currently only supports migrating subsites between sites "
"with the same base table prefix."
msgstr ""
#: class/wpmdbpro-cli.php:695
#, php-format
msgid ""
"The remote database uses a prefix of \"%s\". This migration will create new "
"tables in the remote database with a prefix of \"%s\". \n"
"To use these new tables, AFTER the migration is complete, you will need to "
"edit the wp-config.php file on the remote server and change the "
"$table_prefix variable to \"%s\""
msgstr ""
#: class/wpmdbpro-cli.php:697
#, php-format
msgid ""
"The local database uses a prefix of \"%s\". This migration will create new "
"tables in the local database with a prefix of \"%s\". \n"
"To use these new tables, AFTER the migration is complete, you will need to "
"edit your wp-config.php file in your local environment and change the "
"$table_prefix variable to \"%s\""
msgstr ""
#: template/php-version-requirement-warning.php:7
msgid "CLI Addon Disabled"
msgstr ""
#: template/php-version-requirement-warning.php:9
#, php-format
msgid ""
"The CLI addon follows the requirements of WP-CLI, which requires %1$s+. You "
"are currently running PHP %2$s. You will need to update PHP to use WP-CLI "
"and the CLI addon. <strong><a href=\"%3$s\">Deactivate</a></strong> the CLI "
"addon to get rid of this message."
msgstr ""

View File

@@ -0,0 +1,11 @@
<?php
$required = $GLOBALS['wpmdb_meta']['wp-migrate-db-pro-cli']['required-php-version'];
$wpmdb_basename = sprintf( '%s/%s.php', $GLOBALS['wpmdb_meta']['wp-migrate-db-pro-cli']['folder'], 'wp-migrate-db-pro-cli' );
$deactivate = wp_nonce_url( network_admin_url( 'plugins.php?action=deactivate&plugin=' . urlencode( $wpmdb_basename ) ), 'deactivate-plugin_' . $wpmdb_basename );
?>
<div class="updated warning inline-message below-h2">
<strong><?php _e( 'CLI Addon Disabled', 'wp-migrate-db' ); ?></strong> &mdash;
<?php
printf( __( 'The CLI addon follows the requirements of WP-CLI, which requires %1$s+. You are currently running PHP %2$s. You will need to update PHP to use WP-CLI and the CLI addon. <strong><a href="%3$s">Deactivate</a></strong> the CLI addon to get rid of this message.', 'wp-migrate-db' ), $required, PHP_VERSION, $deactivate );
?>
</div>

View File

@@ -0,0 +1,3 @@
<?php
$GLOBALS['wpmdb_meta']['wp-migrate-db-pro-cli']['version'] = '1.3';
$GLOBALS['wpmdb_meta']['wp-migrate-db-pro-cli']['required-php-version'] = '5.3.2';

View File

@@ -0,0 +1,93 @@
<?php
/*
Plugin Name: WP Migrate DB Pro CLI
Plugin URI: http://deliciousbrains.com/wp-migrate-db-pro/
Description: An extension to WP Migrate DB Pro, allows you to execute migrations using a function call or via WP-CLI
Author: Delicious Brains
Version: 1.3
Author URI: http://deliciousbrains.com
Network: True
*/
// Copyright (c) 2013 Delicious Brains. All rights reserved.
//
// Released under the GPL license
// http://www.opensource.org/licenses/gpl-license.php
//
// **********************************************************************
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// **********************************************************************
require_once 'version.php';
$GLOBALS['wpmdb_meta']['wp-migrate-db-pro-cli']['folder'] = basename( plugin_dir_path( __FILE__ ) );
function wp_migrate_db_pro_cli_addon_loaded() {
// register with wp-cli if it's running, command hasn't already been defined elsewhere, and WPMDBPro is active
if ( defined( 'WP_CLI' ) && WP_CLI && ! class_exists( 'WPMDBPro_CLI_Command' ) && class_exists( 'WPMDBPro' ) ) {
require_once dirname( __FILE__ ) . '/class/wpmdbpro-cli-command.php';
}
// register plugin with wordpress
if ( class_exists( 'WPMDBPro_Addon' ) ) {
require_once dirname( __FILE__ ) . '/class/wpmdbpro-cli-addon.php';
}
load_plugin_textdomain( 'wp-migrate-db-pro-cli', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
cli_version_requirement_check();
}
add_action( 'plugins_loaded', 'wp_migrate_db_pro_cli_addon_loaded', 20 );
/**
* Populate the $wpmdbpro_cli global with an instance of the WPMDBPro_CLI class and return it.
*
* @return WPMDBPro_CLI The one true global instance of the WPMDBPro_CLI class.
*/
function wp_migrate_db_pro_cli_addon() {
global $wpmdbpro_cli;
if ( ! is_null( $wpmdbpro_cli ) ) {
return $wpmdbpro_cli;
}
if ( function_exists( 'wp_migrate_db_pro' ) ) {
wp_migrate_db_pro();
} else {
return false;
}
do_action( 'wp_migrate_db_pro_cli_before_load' );
require_once dirname( __FILE__ ) . '/class/wpmdbpro-cli.php';
$wpmdbpro_cli = new WPMDBPro_CLI( __FILE__ );
do_action( 'wp_migrate_db_pro_cli_after_load' );
return $wpmdbpro_cli;
}
/**
* Check if php version meets requirements to run cli addon
* Display notice on options page if it doesn't.
*
* @return void
*/
function cli_version_requirement_check() {
$required_php_version = $GLOBALS['wpmdb_meta']['wp-migrate-db-pro-cli']['required-php-version'];
if ( ! version_compare( PHP_VERSION, $required_php_version, '>=' ) ) {
add_action( 'wpmdb_notices', 'show_php_version_requirement_warning');
}
}
/**
* Display php version requirement warning message.
*
* @return void
*/
function show_php_version_requirement_warning() {
$template_dir_path = plugin_dir_path( __FILE__ ) . 'template/' ;
$warning_template_path = $template_dir_path . 'php-version-requirement-warning.php';
include( $warning_template_path );
}