From 5d7daee9b9735dc8858ae79038e8cbac41439dc0 Mon Sep 17 00:00:00 2001 From: Dylan Thomas Date: Mon, 17 Jun 2013 11:29:01 -0600 Subject: [PATCH 1/5] Added 3 stage development environment settings for Migration. --- wordpress-move.php | 488 +++++++++++++++++++++++++++++++++------------ 1 file changed, 366 insertions(+), 122 deletions(-) diff --git a/wordpress-move.php b/wordpress-move.php index b0c3484..e608c14 100644 --- a/wordpress-move.php +++ b/wordpress-move.php @@ -12,7 +12,7 @@ /* Copyright 2011 Mert Yazicioglu (email : mert@mertyazicioglu.com) This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2, as + it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, @@ -87,7 +87,7 @@ function load_language_file() { function add_migration_assistant_js() { ?> - - - - get_admin_options(); - } - - /** - * Returns settings of the plugin. - * - * @param void - * @return void - */ - function get_admin_options() { - - // Define options and their default values - $wpmove_admin_options = array( 'db_chunk_size' => 0, - 'fs_chunk_size' => 100, - - 'ftp_dev_hostname' => '', - 'ftp_dev_port' => 21, - 'ftp_dev_username' => '', - 'ftp_dev_passive_mode' => 1, - 'ftp_dev_remote_path' => '/www/wp-content/plugins/wordpress-move/backup/', - 'ftp_dev_url' => 'http://dev.example.com', - - 'ftp_staging_hostname' => '', - 'ftp_staging_port' => 21, - 'ftp_staging_username' => '', - 'ftp_staging_passive_mode' => 1, - 'ftp_staging_remote_path' => '/www/wp-content/plugins/wordpress-move/backup/', - 'ftp_staging_url' => 'http://staging.example.com', - - 'ftp_production_hostname' => '', - 'ftp_production_port' => 21, - 'ftp_production_username' => '', - 'ftp_production_passive_mode' => 1, - 'ftp_production_remote_path' => '/www/wp-content/plugins/wordpress-move/backup/', - 'ftp_production_url' => 'http://production.example.com', - ); - - // Try retrieving options from the database - $wpmove_options = get_option( $this->admin_options_name ); - - // Deletes the FTP Password stored in the database - if ( is_array( $wpmove_options ) && array_key_exists( 'ftp_password', $wpmove_options ) ) - unset( $wpmove_options['ftp_password'] ); - - // If the option set already exists in the database, reset their values - if ( ! empty( $wpmove_options ) ) - foreach ( $wpmove_options as $key => $value ) - $wpmove_admin_options[$key] = $value; - - // Update the database - update_option( $this->admin_options_name, $wpmove_admin_options ); - - // Return options - return $wpmove_admin_options; - } - - /** - * Generates the settings page of the plugin. - * - * @param void - * @return void - */ - function print_settings_page() { - - // Get plugin's settings - $wpmove_options = $this->get_admin_options(); - - // If the form is submitted successfully... - if ( $_POST && check_admin_referer( 'wpmove_update_settings' ) ) { - - // If the user was redirected from the migration assistant, redirect him/her back once all necessary fields are filled - //if ( isset( $_POST['wpmove_ref'] ) && $_POST['wpmove_ftp_dev_hostname'] !== '' && $_POST['wpmove_ftp_dev_username'] !== '' && $_POST['wpmove_ftp_dev_port'] !== 0 ) - // echo ''; - - // Store the changes made... - $wpmove_options['db_chunk_size'] = intval( $_POST['wpmove_db_chunk_size'] ); - $wpmove_options['fs_chunk_size'] = intval( $_POST['wpmove_fs_chunk_size'] ); - - $wpmove_options['ftp_dev_hostname'] = sanitize_text_field( $_POST['wpmove_ftp_dev_hostname'] ); - $wpmove_options['ftp_dev_port'] = intval( $_POST['wpmove_ftp_dev_port'] ); - $wpmove_options['ftp_dev_username'] = sanitize_text_field( $_POST['wpmove_ftp_dev_username'] ); - $wpmove_options['ftp_dev_passive_mode'] = intval( $_POST['wpmove_ftp_dev_passive_mode'] ); - $wpmove_options['ftp_dev_remote_path'] = sanitize_text_field( $_POST['wpmove_ftp_dev_remote_path'] ); - $wpmove_options['ftp_dev_url'] = sanitize_text_field( $_POST['wpmove_ftp_dev_url'] ); - - $wpmove_options['ftp_staging_hostname'] = sanitize_text_field( $_POST['wpmove_ftp_staging_hostname'] ); - $wpmove_options['ftp_staging_port'] = intval( $_POST['wpmove_ftp_staging_port'] ); - $wpmove_options['ftp_staging_username'] = sanitize_text_field( $_POST['wpmove_ftp_staging_username'] ); - $wpmove_options['ftp_staging_passive_mode'] = intval( $_POST['wpmove_ftp_staging_passive_mode'] ); - $wpmove_options['ftp_staging_remote_path'] = sanitize_text_field( $_POST['wpmove_ftp_staging_remote_path'] ); - $wpmove_options['ftp_staging_url'] = sanitize_text_field( $_POST['wpmove_ftp_staging_url'] ); - - $wpmove_options['ftp_production_hostname'] = sanitize_text_field( $_POST['wpmove_ftp_production_hostname'] ); - $wpmove_options['ftp_production_port'] = intval( $_POST['wpmove_ftp_production_port'] ); - $wpmove_options['ftp_production_username'] = sanitize_text_field( $_POST['wpmove_ftp_production_username'] ); - $wpmove_options['ftp_production_passive_mode'] = intval( $_POST['wpmove_ftp_production_passive_mode'] ); - $wpmove_options['ftp_production_remote_path'] = sanitize_text_field( $_POST['wpmove_ftp_production_remote_path'] ); - $wpmove_options['ftp_production_url'] = sanitize_text_field( $_POST['wpmove_ftp_production_url'] ); - - // Update plugin settings - update_option( $this->admin_options_name, $wpmove_options ); - - ?> -

-

' . __( 'Please fill in FTP Connection Details in order to start the migration process.', 'WPMove' ) . '

'; - - ?> -
-
-
-
-

-

- -

-
- -
- -
- '; - - // Display the submit button - submit_button(); - - ?> -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - - -
- - -
- - - - /var/www/wp-content/plugins/wordpress-move2/backup/
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - - -
- - -
- - - - /var/www/wp-content/plugins/wordpress-move2/backup/
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - - -
- - -
- - - - /var/www/wp-content/plugins/wordpress-move2/backup/
- -
-
- -

- -

- - - - - - - -
- - - MB -
- -

- -

- - - - - - - -
- - - MB -
- print_change_domain_name_page(); - break; - case 'migrate': $this->print_migration_page(); - break; - case 'complete': $this->print_complete_migration_page(); - break; - } - } else { - ?> -
-
-
-
-

-

- -

- -
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-

- -

-

-    
-

-

- -

-

-    
-    
-    
-    
-    
-

-
-
-
- -
-
- -
-
-

- -

-

-    
-    
-    
-

-

- -

-

-    
-

-

- -

-

-    
-    
-    
-

-
-
-
- -
-
- -
-
-

- -

-

-    
-    
-

-

- -

-

-    
-

-

- -

-

-    
-

-
-
-
- -
-
- get_admin_options(); - - // Apply filters to the given domain names - $old_domain_name = esc_url_raw( $_POST['old_domain_name'] ); - $new_domain_name = esc_url_raw( $_POST['new_domain_name'] ); - - // Create a backup of the database in case the operation fails - $db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'] ); - - // Create a backup of the database by changing instances of the old domain name with the newer one - $new_db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'], count( $db_backups ) + 1, $old_domain_name, $new_domain_name ); - - // Set error counter to zero - $errors_occured = 0; - - // Import databsae backups we've just created - foreach ( $new_db_backups as $backup ) - if ( TRUE !== wpmove_import_db_backup( $backup ) ) - $errors_occured++; - - // If everything went well... - if ( ! $errors_occured ) { - - // Move the backup files we created "just in case" to the old backup directory - foreach ( $db_backups as $backup ) - rename( trailingslashit( WPMOVE_BACKUP_DIR ) . $backup, trailingslashit( WPMOVE_OLD_BACKUP_DIR ) . $backup ); - - // Remove the backup files we've just imported as we won't need them anymore - foreach ( $new_db_backups as $backup ) - wpmove_remove_db_backup( $backup ); - - // Prepare the new homepage URL - $new_home_url = str_replace( $old_domain_name, $new_domain_name, home_url( '/' ) ); - - // Display a success message - ?> -
-
-
-
-

-

- - Click here to go to your site using your new domain.', 'WPMove' ), $new_home_url ); ?> -

-
- -
-
-
-
-

-

- -

-
- -
-
-
-
-
- -

-

- -

- - - - - - - - - - - -
- - - -
- - - -
-

- -

-
-
- get_admin_options(); - - // If the FTP details are not on file, redirect the user to the settings page - //if ( $wpmove_options['ftp_dev_hostname'] == '' || $wpmove_options['ftp_dev_username'] == '' || $wpmove_options['ftp__dev_port'] == 0 ) { - // echo ''; - //} - - if ( $_POST && check_admin_referer( 'wpmove_advanced_migration_start' ) ) { - - ?> -
-
-
-
-

-

- get_admin_options(); - - // Create an array to hold backup files that will be uploaded - $backups = array(); - - // If changing the current domain name is also requested... - if ( ! empty( $_POST['old_domain_name'] ) && ! empty( $_POST['new_domain_name'] ) ) { - - // Apply filters to the given domain names - $old_domain_name = esc_url_raw( $_POST['old_domain_name'] ); - $new_domain_name = esc_url_raw( $_POST['new_domain_name'] ); - - // Create a backup of the database by changing instances of the old domain name with the newer one - $db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'], 1, $old_domain_name, $new_domain_name ); - - } else { - - // Create a backup of the database - $db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'] ); - - } - - // Add names of database backup files to the array of backup files - $backups = array_merge( $backups, $db_backups ); - - // Check whether an array is actually posted or not - if ( isset( $_POST['files'] ) && is_array( $_POST['files'] ) ) { - - // Use the POST data directly, if the fallback method is being used - $files = array_map( 'sanitize_text_field', $_POST['files'] ); - - // Remove non-empty directories from the array - $files = array_filter( $files ); - - // Create chunks from the selected files - $chunks = wpmove_divide_into_chunks( $files, $wpmove_options['fs_chunk_size'] ); - - // To prevent overwriting archives created in the same second - $chunk_id = 1; - - // Create an archive of the each chunk - foreach ( $chunks as $chunk ) - array_push( $backups, wpmove_create_archive( $chunk, ABSPATH, $chunk_id++ ) ); - } - - // Check whether creating backups files succeeded or not - if ( ! file_exists( trailingslashit( WPMOVE_BACKUP_DIR ) . $backups['0'] ) ) { - _e( 'Could not create backup files. Please make sure the backup directory is writable. For further info, please refer to the documentation.', 'WPMove' ); - } else { - - // Upload files and display a success message on success - if ( $this->upload_files( $backups, sanitize_text_field( $_POST['ftp_password'] ) ) ) { - - ?> -
- -

-
- -
- -

- - -
-
-
-
-

-

- -

-
-
- -
-
-
-
- -

-
-

-
-
-

- get_admin_options(); - - ?> -

-
-

- - - - - - - - - - - -
- - - -
- - - -
- - -
- - - - -
- get_admin_options(); - - // Instantiate the FTP class - $ftp = new ftp(); - - // Enter Passive Mode if enabled - if ( $wpmove_options['ftp_'.$server.'_passive_mode'] ) - $ftp->Passive( TRUE ); - - echo ''; - - printf( __( 'Connecting to %s:%d...', 'WPMove' ), $wpmove_options['ftp_'.$server.'_hostname'], $wpmove_options['ftp_'.$server.'_port'] ); - $this->flush_output(); - - // Set the hostname and the port - $ftp->SetServer( $wpmove_options['ftp_'.$server.'_hostname'], intval( $wpmove_options['ftp_'.$server.'_port'] ) ); - - // Try connecting to the server - if ( $ftp->connect() ) { - - echo ' ' . __( 'Success!', 'WPMove' ) . '
'; - $this->flush_output(); - - // Display a different message if no password is given - if ( '' !== $ftp_password ) - printf( __( 'Logging in as %s using password...', 'WPMove' ), $wpmove_options['ftp_'.$server.'_username'] ); - else - printf( __( 'Logging in as %s without a password...', 'WPMove' ), $wpmove_options['ftp_'.$server.'_username'] ); - - $this->flush_output(); - - // Login to the server using the supplied credentials - if ( $ftp->login( $wpmove_options['ftp_'.$server.'_username'], $ftp_password ) ) { - - echo ' ' . __( 'Success!', 'WPMove' ) . '
' . __( 'Starting uploading files...', 'WPMove' ) . '
'; - - $this->flush_output(); - - // Changes the present working directory to the backup directory on the remote server - $ftp->chdir( $wpmove_options['ftp_'.$server.'_remote_path'] ); - - // Start counting errors during the file upload - $error_count = 0; - - // Upload the given backup files under the backup folder to the server - foreach ( $files as $file ) { - printf( __( '%s is being uploaded...', 'WPMove' ), basename( $file ) ); - $this->flush_output(); - if ( FALSE !== ( $ftp->put( trailingslashit( WPMOVE_BACKUP_DIR ) . $file, basename( $file ) ) ) ) { - echo '' . __( ' Success!', 'WPMove' ) . '
'; - } else { - echo '' . __( ' Failed!', 'WPMove' ) . '
'; - $error_count++; - } - $this->flush_output(); - } - - // Notify the user about the errors occured - if ( $error_count ) - printf( _n( 'Uploading files is completed with %d error...', 'Uploading files is completed with %d errors...', $error_count, 'WPMove' ), $error_count ); - else - _e( 'Uploading files is completed without an error...', 'WPMove' ); - - $this->flush_output(); - - echo '
'; - _e( 'Closing the FTP connection...', 'WPMove' ); - echo '

'; - - // Close the connection - $ftp->quit(); - - // Return TRUE on success - return TRUE; - } - - // Close the connection - $ftp->quit(); - } - - echo ' ' . __( ' Failed!', 'WPMove' ) . '
' . __( 'Operation terminated...', 'WPMove' ) . '
'; - - // If it reaches here, apparently it failed - return FALSE; - } - - /** - * Handles the migration completing process. - * - * @param void - * @return void - */ - function print_complete_migration_page() { - - // If the user clicks the proceed link... - if ( $_POST && check_admin_referer( 'wpmove_complete_migration_start' ) ) { - - ?> -
-
-
-
-

-
- '; - printf( __( '%s is being imported...', 'WPMove' ), basename( $file ) ); - - $this->flush_output(); - - echo ' '; - - if ( wpmove_import_db_backup( basename( $file ) ) ) { - _e( 'Success!', 'WPMove' ); - } else { - $errors_occured++; - _e( 'Failed!', 'WPMove' ); - if ( ! is_readable( $file ) ) - echo ' ' . __( 'Check file permissions...', 'WPMove' ); - } - - echo '
'; - - } else if ( 'zip' == $ext ) { - - echo ''; - printf( __( '%s is being extracted...', 'WPMove' ), basename( $file ) ); - - $this->flush_output(); - - echo ' '; - - if ( wpmove_extract_archive( basename( $file ), ABSPATH ) ) { - _e( 'Success!', 'WPMove' ); - } else { - $errors_occured++; - _e( 'Failed!', 'WPMove' ); - if ( ! is_readable( $file ) ) - echo ' ' . __( 'Check file permissions...', 'WPMove' ); - } - - echo '
'; - } - } - } - - // If there were errors, notify the user - if ( ! isset( $errors_occured ) ) - _e( 'Please select files to migrate before proceeding!', 'WPMove' ); - else { - echo '
'; - if ( $errors_occured > 0 ) - printf( _n( 'Migration has been completed but with %d error.', 'Migration has been completed but with %d errors.', $errors_occured, 'WPMove' ), $errors_occured ); - else - _e( 'Migration has been completed successfully!', 'WPMove' ); - } - - ?> -
- -
-
-
-
-

-
- 1 ) { - - ?> - -

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - '; - - // Increase the counter for zebra striping - $i++; - } - - ?> - -
- - - - - - - - - -
- - - - - - - - - -
- - - - ' . esc_html( basename( $file ) ) . ' - - - ' . esc_html( $type ) . ' - - ' . esc_html( round( filesize( $file ) / 1024, 2 ) ) . ' KB - - ' . esc_html( date( 'd.m.Y H:i:s', substr( $timestamp['1'], 0, 10 ) ) ) . ' -
-
- - -
- -
- get_admin_options(); - - // An array to hold backup files that will be uploaded - $backups = array(); - - // Create a backup of the database - wpmove_create_db_backup( $wpmove_options['db_chunk_size'] ); - - if ( isset( $_POST['wpmove_create_full_backup'] ) ) { - - // List all of the files inside the main directory - $abspath = substr( ABSPATH, 0, strlen( ABSPATH ) - 1 ); - $files = wpmove_list_all_files( $abspath, FALSE, array( WPMOVE_DIR, WPMOVE_BACKUP_DIR, WPMOVE_OLD_BACKUP_DIR ) ); - - // Create chunks from the selected files - $chunks = wpmove_divide_into_chunks( $files, $wpmove_options['fs_chunk_size'] ); - - // To prevent overwriting archives created in the same second - $chunk_id = 1; - - // Create an archive of the each chunk - foreach ( $chunks as $chunk ) - wpmove_create_archive( $chunk, ABSPATH, $chunk_id++ ); - - } - - } - - ?> -
-
-
-
-

-

-

- -

-
- - -
-
-

-

- -

- -
- - -
-
- - -
-
- - - - - - - - - - - - - - - - - - - - - 1 ) { - - // For zebra striping - $i = 0; - - // Display all current backups starting with database backups - foreach ( $current_backups as $file ) { - - // Get the file extension - $ext = substr( $file, -3, 3 ); - - // Decide the type of the backup - if ( 'sql' == $ext ) { - preg_match( '/DBBackup-([0-9]*).sql/', basename( $file ), $timestamp ); - $type = __( 'Database Backup', 'WPMove' ); - } else if ( 'zip' == $ext ) { - preg_match( '/Backup-([0-9]*).zip/', basename( $file ), $timestamp ); - $type = __( 'Filesystem Backup', 'WPMove' ); - } else { - continue; - } - - // For zebra striping - if ( $i % 2 !== 0 ) - $class = ' class="alternate"'; - else - $class = ''; - - // Display the row - echo ' - - - - - - '; - - // Increase the counter for zebra striping - $i++; - } - - } else { - - echo ' - - '; - } - ?> - -
- - - - - - - - - -
- - - - - - - - - -
- - - - ' . esc_html( basename( $file ) ) . ' - - - ' . esc_html( $type ) . ' - - ' . esc_html( round( filesize( $file ) / 1024, 2 ) ) . ' KB - - ' . esc_html( date( 'Y-m-d H:i:s', substr( $timestamp['1'], 0, 10 ) ) ) . ' -
- ' . __( 'No backup files found.', 'WPMove' ) . ' -
-
-
-

-

- -

-
- - -
-
- - -
-
- - - - - - - - - - - - - - - - - - - - - 1 ) { - - // For zebra striping - $i = 0; - - // Display all old backups starting with database backups - foreach ( $old_backups as $file ) { - - // Get the file extension - $ext = substr( $file, -3, 3 ); - - // Decide the backup type - if ( $ext == 'sql' ) { - preg_match( '/DBBackup-([0-9]*).sql/', basename( $file ), $timestamp ); - $type = __( 'Database Backup', 'WPMove' ); - } else if ( $ext == 'zip' ) { - preg_match( '/Backup-([0-9]*).zip/', basename( $file ), $timestamp ); - $type = __( 'Filesystem Backup', 'WPMove' ); - } else { - continue; - } - - // For zebra striping - if ( $i % 2 !== 0 ) - $class = ' class="alternate"'; - else - $class = ''; - - // Display the row - echo ' - - - - - - '; - - // For zebra striping - $i++; - } - - } else { - - echo ' - - '; - } - ?> - -
- - - - - - - - - -
- - - - - - - - - -
- - - - ' . esc_html( basename( $file ) ) . ' - - - ' . esc_html( $type ) . ' - - ' . esc_html( round( filesize( $file ) / 1024, 2 ) ) . ' KB - - ' . esc_html( date( 'Y-m-d H:i:s', substr( $timestamp['1'], 0, 10 ) ) ) . ' -
- ' . __( 'No backup files found.', 'WPMove' ) . ' -
-
-
-

-

- -

-
- - -
-
- - -
-
- - - - - - - - - - - - - - - - - - - - - 1 ) { - - // For zebra striping - $i = 0; - - // Display all current backups starting with database backups - foreach ( $converted_backups as $file ) { - - // Get the file extension - $ext = substr( $file, -3, 3 ); - - // Decide the type of the backup - if ( $ext == 'sql' ) { - preg_match( '/DBBackup-([0-9]*).sql/', basename( $file ), $timestamp ); - $type = __( 'Database Backup', 'WPMove' ); - } else { - continue; - } - - // For zebra striping - if ( $i % 2 !== 0 ) - $class = ' class="alternate"'; - else - $class = ''; - - // Display the row - echo ' - - - - - - '; - - // Increase the counter for zebra striping - $i++; - } - } else { - - echo ' - - '; - } - ?> - -
- - - - - - - - - -
- - - - - - - - - -
- - - - ' . esc_html( basename( $file ) ) . ' - - - ' . esc_html( $type ) . ' - - ' . esc_html( round( filesize( $file ) / 1024, 2 ) ) . ' KB - - ' . esc_html( date( 'Y-m-d H:i:s', substr( $timestamp['1'], 0, 10 ) ) ) . ' -
- ' . __( 'No converted database backup files found. You can convert a database backup file using the Convert option from the dropdown lists above.', 'WPMove' ) . ' -
-
-
- +load_language_file(); + } + + /** + * Loads the language file. + * + * @param void + * @return void + */ + function load_language_file() { + load_plugin_textdomain( 'WPMove', FALSE, basename( dirname( __FILE__ ) ) . '/lang/' ); + } + + /** + * Adds the script to the head for Migration Assistant. + * + * @param void + * @return void + */ + function add_migration_assistant_js() { + + ?> + + + + get_admin_options(); + } + + /** + * Returns settings of the plugin. + * + * @param void + * @return void + */ + function get_admin_options() { + + // Define options and their default values + $wpmove_admin_options = array( 'db_chunk_size' => 0, + 'fs_chunk_size' => 100, + + 'ftp_dev_hostname' => '', + 'ftp_dev_port' => 21, + 'ftp_dev_username' => '', + 'ftp_dev_passive_mode' => 1, + 'ftp_dev_remote_path' => '/www/wp-content/plugins/wordpress-move/backup/', + 'ftp_dev_url' => 'http://dev.example.com', + + 'ftp_staging_hostname' => '', + 'ftp_staging_port' => 21, + 'ftp_staging_username' => '', + 'ftp_staging_passive_mode' => 1, + 'ftp_staging_remote_path' => '/www/wp-content/plugins/wordpress-move/backup/', + 'ftp_staging_url' => 'http://staging.example.com', + + 'ftp_production_hostname' => '', + 'ftp_production_port' => 21, + 'ftp_production_username' => '', + 'ftp_production_passive_mode' => 1, + 'ftp_production_remote_path' => '/www/wp-content/plugins/wordpress-move/backup/', + 'ftp_production_url' => 'http://production.example.com', + ); + + // Try retrieving options from the database + $wpmove_options = get_option( $this->admin_options_name ); + + // Deletes the FTP Password stored in the database + if ( is_array( $wpmove_options ) && array_key_exists( 'ftp_password', $wpmove_options ) ) + unset( $wpmove_options['ftp_password'] ); + + // If the option set already exists in the database, reset their values + if ( ! empty( $wpmove_options ) ) + foreach ( $wpmove_options as $key => $value ) + $wpmove_admin_options[$key] = $value; + + // Update the database + update_option( $this->admin_options_name, $wpmove_admin_options ); + + // Return options + return $wpmove_admin_options; + } + + /** + * Generates the settings page of the plugin. + * + * @param void + * @return void + */ + function print_settings_page() { + + // Get plugin's settings + $wpmove_options = $this->get_admin_options(); + + // If the form is submitted successfully... + if ( $_POST && check_admin_referer( 'wpmove_update_settings' ) ) { + + // If the user was redirected from the migration assistant, redirect him/her back once all necessary fields are filled + //if ( isset( $_POST['wpmove_ref'] ) && $_POST['wpmove_ftp_dev_hostname'] !== '' && $_POST['wpmove_ftp_dev_username'] !== '' && $_POST['wpmove_ftp_dev_port'] !== 0 ) + // echo ''; + + // Store the changes made... + $wpmove_options['db_chunk_size'] = intval( $_POST['wpmove_db_chunk_size'] ); + $wpmove_options['fs_chunk_size'] = intval( $_POST['wpmove_fs_chunk_size'] ); + + $wpmove_options['ftp_dev_hostname'] = sanitize_text_field( $_POST['wpmove_ftp_dev_hostname'] ); + $wpmove_options['ftp_dev_port'] = intval( $_POST['wpmove_ftp_dev_port'] ); + $wpmove_options['ftp_dev_username'] = sanitize_text_field( $_POST['wpmove_ftp_dev_username'] ); + $wpmove_options['ftp_dev_passive_mode'] = intval( $_POST['wpmove_ftp_dev_passive_mode'] ); + $wpmove_options['ftp_dev_remote_path'] = sanitize_text_field( $_POST['wpmove_ftp_dev_remote_path'] ); + $wpmove_options['ftp_dev_url'] = sanitize_text_field( $_POST['wpmove_ftp_dev_url'] ); + + $wpmove_options['ftp_staging_hostname'] = sanitize_text_field( $_POST['wpmove_ftp_staging_hostname'] ); + $wpmove_options['ftp_staging_port'] = intval( $_POST['wpmove_ftp_staging_port'] ); + $wpmove_options['ftp_staging_username'] = sanitize_text_field( $_POST['wpmove_ftp_staging_username'] ); + $wpmove_options['ftp_staging_passive_mode'] = intval( $_POST['wpmove_ftp_staging_passive_mode'] ); + $wpmove_options['ftp_staging_remote_path'] = sanitize_text_field( $_POST['wpmove_ftp_staging_remote_path'] ); + $wpmove_options['ftp_staging_url'] = sanitize_text_field( $_POST['wpmove_ftp_staging_url'] ); + + $wpmove_options['ftp_production_hostname'] = sanitize_text_field( $_POST['wpmove_ftp_production_hostname'] ); + $wpmove_options['ftp_production_port'] = intval( $_POST['wpmove_ftp_production_port'] ); + $wpmove_options['ftp_production_username'] = sanitize_text_field( $_POST['wpmove_ftp_production_username'] ); + $wpmove_options['ftp_production_passive_mode'] = intval( $_POST['wpmove_ftp_production_passive_mode'] ); + $wpmove_options['ftp_production_remote_path'] = sanitize_text_field( $_POST['wpmove_ftp_production_remote_path'] ); + $wpmove_options['ftp_production_url'] = sanitize_text_field( $_POST['wpmove_ftp_production_url'] ); + + // Update plugin settings + update_option( $this->admin_options_name, $wpmove_options ); + + ?> +

+

' . __( 'Please fill in FTP Connection Details in order to start the migration process.', 'WPMove' ) . '

'; + + ?> +
+
+
+
+

+

+ +

+
+ +
+ +
+ '; + + // Display the submit button + submit_button(); + + ?> +
+
+ get_admin_options(); + + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + +
+ + + + /var/www/wp-content/plugins/wordpress-move2/backup/
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + +
+ + + + /var/www/wp-content/plugins/wordpress-move2/backup/
+ +
+
+get_admin_options(); + + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + +
+ + + + /var/www/wp-content/plugins/wordpress-move2/backup/
+ +
+
+ +

+ +

+ + + + + + + +
+ + + MB +
+ +

+ +

+ + + + + + + +
+ + + MB +
+ print_change_domain_name_page(); + break; + case 'migrate': $this->print_migration_page(); + break; + case 'complete': $this->print_complete_migration_page(); + break; + } + } else { + ?> +
+
+
+
+

+

+ +

+ +
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+

+ +

+

+    
+

+

+ +

+

+    
+    
+    
+    
+    
+

+
+
+
+ +
+
+ +
+
+

+ +

+

+    
+    
+    
+

+

+ +

+

+    
+

+

+ +

+

+    
+    
+    
+

+
+
+
+

+

+ + + +
+
+ +
+
+

+ +

+

+    
+    
+

+

+ +

+

+    
+

+

+ +

+

+    
+

+
+
+
+ +
+
+ get_admin_options(); + + // Apply filters to the given domain names + $old_domain_name = esc_url_raw( $_POST['old_domain_name'] ); + $new_domain_name = esc_url_raw( $_POST['new_domain_name'] ); + + // Create a backup of the database in case the operation fails + $db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'] ); + + // Create a backup of the database by changing instances of the old domain name with the newer one + $new_db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'], count( $db_backups ) + 1, $old_domain_name, $new_domain_name ); + + // Set error counter to zero + $errors_occured = 0; + + // Import databsae backups we've just created + foreach ( $new_db_backups as $backup ) + if ( TRUE !== wpmove_import_db_backup( $backup ) ) + $errors_occured++; + + // If everything went well... + if ( ! $errors_occured ) { + + // Move the backup files we created "just in case" to the old backup directory + foreach ( $db_backups as $backup ) + rename( trailingslashit( WPMOVE_BACKUP_DIR ) . $backup, trailingslashit( WPMOVE_OLD_BACKUP_DIR ) . $backup ); + + // Remove the backup files we've just imported as we won't need them anymore + foreach ( $new_db_backups as $backup ) + wpmove_remove_db_backup( $backup ); + + // Prepare the new homepage URL + $new_home_url = str_replace( $old_domain_name, $new_domain_name, home_url( '/' ) ); + + // Display a success message + ?> +
+
+
+
+

+

+ + Click here to go to your site using your new domain.', 'WPMove' ), $new_home_url ); ?> +

+
+ +
+
+
+
+

+

+ +

+
+ get_admin_options(); + $server= sanitize_text_field($_GET['server']); + + ?> +
+
+
+
+
+ +

+

+ +

+ + + + + + + + + + + +
+ + + +
+ + + +
+

+ +

+
+
+ get_admin_options(); + + // If the FTP details are not on file, redirect the user to the settings page + //if ( $wpmove_options['ftp_dev_hostname'] == '' || $wpmove_options['ftp_dev_username'] == '' || $wpmove_options['ftp__dev_port'] == 0 ) { + // echo ''; + //} + + if ( $_POST && check_admin_referer( 'wpmove_advanced_migration_start' ) ) { + + ?> +
+
+
+
+

+

+ get_admin_options(); + + // Create an array to hold backup files that will be uploaded + $backups = array(); + + // If changing the current domain name is also requested... + if ( ! empty( $_POST['old_domain_name'] ) && ! empty( $_POST['new_domain_name'] ) ) { + + // Apply filters to the given domain names + $old_domain_name = esc_url_raw( $_POST['old_domain_name'] ); + $new_domain_name = esc_url_raw( $_POST['new_domain_name'] ); + + // Create a backup of the database by changing instances of the old domain name with the newer one + $db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'], 1, $old_domain_name, $new_domain_name ); + + } else { + + // Create a backup of the database + $db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'] ); + + } + + // Add names of database backup files to the array of backup files + $backups = array_merge( $backups, $db_backups ); + + // Check whether an array is actually posted or not + if ( isset( $_POST['files'] ) && is_array( $_POST['files'] ) ) { + + // Use the POST data directly, if the fallback method is being used + $files = array_map( 'sanitize_text_field', $_POST['files'] ); + + // Remove non-empty directories from the array + $files = array_filter( $files ); + + // Create chunks from the selected files + $chunks = wpmove_divide_into_chunks( $files, $wpmove_options['fs_chunk_size'] ); + + // To prevent overwriting archives created in the same second + $chunk_id = 1; + + // Create an archive of the each chunk + foreach ( $chunks as $chunk ) + array_push( $backups, wpmove_create_archive( $chunk, ABSPATH, $chunk_id++ ) ); + } + + // Check whether creating backups files succeeded or not + if ( ! file_exists( trailingslashit( WPMOVE_BACKUP_DIR ) . $backups['0'] ) ) { + _e( 'Could not create backup files. Please make sure the backup directory is writable. For further info, please refer to the documentation.', 'WPMove' ); + } else { + + // Upload files and display a success message on success + if ( $this->upload_files( $backups, sanitize_text_field( $_POST['ftp_password'] ) ) ) { + + ?> +
+ +

+
+ +
+ +

+ + +
+
+
+
+

+

+ +

+
+
+ +
+
+
+
+ +

+
+

+
+
+

+ get_admin_options(); + $server= sanitize_text_field($_GET['server']); + + ?> +

+
+

+ + + + + + + + + + + +
+ + + +
+ + + +
+ + +
+ + + + +
+ get_admin_options(); + + // Instantiate the FTP class + $ftp = new ftp(); + + // Enter Passive Mode if enabled + if ( $wpmove_options['ftp_'.$server.'_passive_mode'] ) + $ftp->Passive( TRUE ); + + echo ''; + + printf( __( 'Connecting to %s:%d...', 'WPMove' ), $wpmove_options['ftp_'.$server.'_hostname'], $wpmove_options['ftp_'.$server.'_port'] ); + $this->flush_output(); + + // Set the hostname and the port + $ftp->SetServer( $wpmove_options['ftp_'.$server.'_hostname'], intval( $wpmove_options['ftp_'.$server.'_port'] ) ); + + // Try connecting to the server + if ( $ftp->connect() ) { + + echo ' ' . __( 'Success!', 'WPMove' ) . '
'; + $this->flush_output(); + + // Display a different message if no password is given + if ( '' !== $ftp_password ) + printf( __( 'Logging in as %s using password...', 'WPMove' ), $wpmove_options['ftp_'.$server.'_username'] ); + else + printf( __( 'Logging in as %s without a password...', 'WPMove' ), $wpmove_options['ftp_'.$server.'_username'] ); + + $this->flush_output(); + + // Login to the server using the supplied credentials + if ( $ftp->login( $wpmove_options['ftp_'.$server.'_username'], $ftp_password ) ) { + + echo ' ' . __( 'Success!', 'WPMove' ) . '
' . __( 'Starting uploading files...', 'WPMove' ) . '
'; + + $this->flush_output(); + + // Changes the present working directory to the backup directory on the remote server + $ftp->chdir( $wpmove_options['ftp_'.$server.'_remote_path'] ); + + // Start counting errors during the file upload + $error_count = 0; + + // Upload the given backup files under the backup folder to the server + foreach ( $files as $file ) { + printf( __( '%s is being uploaded...', 'WPMove' ), basename( $file ) ); + $this->flush_output(); + if ( FALSE !== ( $ftp->put( trailingslashit( WPMOVE_BACKUP_DIR ) . $file, basename( $file ) ) ) ) { + echo '' . __( ' Success!', 'WPMove' ) . '
'; + } else { + echo '' . __( ' Failed!', 'WPMove' ) . '
'; + $error_count++; + } + $this->flush_output(); + } + + // Notify the user about the errors occured + if ( $error_count ) + printf( _n( 'Uploading files is completed with %d error...', 'Uploading files is completed with %d errors...', $error_count, 'WPMove' ), $error_count ); + else + _e( 'Uploading files is completed without an error...', 'WPMove' ); + + $this->flush_output(); + + echo '
'; + _e( 'Closing the FTP connection...', 'WPMove' ); + echo '

'; + + // Close the connection + $ftp->quit(); + + // Return TRUE on success + return TRUE; + } + + // Close the connection + $ftp->quit(); + } + + echo ' ' . __( ' Failed!', 'WPMove' ) . '
' . __( 'Operation terminated...', 'WPMove' ) . '
'; + + // If it reaches here, apparently it failed + return FALSE; + } + + /** + * Handles the migration completing process. + * + * @param void + * @return void + */ + function print_complete_migration_page() { + + // If the user clicks the proceed link... + if ( $_POST && check_admin_referer( 'wpmove_complete_migration_start' ) ) { + + ?> +
+
+
+
+

+
+ '; + printf( __( '%s is being imported...', 'WPMove' ), basename( $file ) ); + + $this->flush_output(); + + echo ' '; + + if ( wpmove_import_db_backup( basename( $file ) ) ) { + _e( 'Success!', 'WPMove' ); + } else { + $errors_occured++; + _e( 'Failed!', 'WPMove' ); + if ( ! is_readable( $file ) ) + echo ' ' . __( 'Check file permissions...', 'WPMove' ); + } + + echo '
'; + + } else if ( 'zip' == $ext ) { + + echo ''; + printf( __( '%s is being extracted...', 'WPMove' ), basename( $file ) ); + + $this->flush_output(); + + echo ' '; + + if ( wpmove_extract_archive( basename( $file ), ABSPATH ) ) { + _e( 'Success!', 'WPMove' ); + } else { + $errors_occured++; + _e( 'Failed!', 'WPMove' ); + if ( ! is_readable( $file ) ) + echo ' ' . __( 'Check file permissions...', 'WPMove' ); + } + + echo '
'; + } + } + } + + // If there were errors, notify the user + if ( ! isset( $errors_occured ) ) + _e( 'Please select files to migrate before proceeding!', 'WPMove' ); + else { + echo '
'; + if ( $errors_occured > 0 ) + printf( _n( 'Migration has been completed but with %d error.', 'Migration has been completed but with %d errors.', $errors_occured, 'WPMove' ), $errors_occured ); + else + _e( 'Migration has been completed successfully!', 'WPMove' ); + } + + ?> +
+ +
+
+
+
+

+
+ 1 ) { + + ?> + +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + '; + + // Increase the counter for zebra striping + $i++; + } + + ?> + +
+ + + + + + + + + +
+ + + + + + + + + +
+ + + + ' . esc_html( basename( $file ) ) . ' + + + ' . esc_html( $type ) . ' + + ' . esc_html( round( filesize( $file ) / 1024, 2 ) ) . ' KB + + ' . esc_html( date( 'd.m.Y H:i:s', substr( $timestamp['1'], 0, 10 ) ) ) . ' +
+
+ + +
+ +
+ get_admin_options(); + + // An array to hold backup files that will be uploaded + $backups = array(); + + // Create a backup of the database + wpmove_create_db_backup( $wpmove_options['db_chunk_size'] ); + + if ( isset( $_POST['wpmove_create_full_backup'] ) ) { + + // List all of the files inside the main directory + $abspath = substr( ABSPATH, 0, strlen( ABSPATH ) - 1 ); + $files = wpmove_list_all_files( $abspath, FALSE, array( WPMOVE_DIR, WPMOVE_BACKUP_DIR, WPMOVE_OLD_BACKUP_DIR ) ); + + // Create chunks from the selected files + $chunks = wpmove_divide_into_chunks( $files, $wpmove_options['fs_chunk_size'] ); + + // To prevent overwriting archives created in the same second + $chunk_id = 1; + + // Create an archive of the each chunk + foreach ( $chunks as $chunk ) + wpmove_create_archive( $chunk, ABSPATH, $chunk_id++ ); + + } + + } + + ?> +
+
+
+
+

+

+

+ +

+
+ + +
+
+

+

+ +

+ +
+ + +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + 1 ) { + + // For zebra striping + $i = 0; + + // Display all current backups starting with database backups + foreach ( $current_backups as $file ) { + + // Get the file extension + $ext = substr( $file, -3, 3 ); + + // Decide the type of the backup + if ( 'sql' == $ext ) { + preg_match( '/DBBackup-([0-9]*).sql/', basename( $file ), $timestamp ); + $type = __( 'Database Backup', 'WPMove' ); + } else if ( 'zip' == $ext ) { + preg_match( '/Backup-([0-9]*).zip/', basename( $file ), $timestamp ); + $type = __( 'Filesystem Backup', 'WPMove' ); + } else { + continue; + } + + // For zebra striping + if ( $i % 2 !== 0 ) + $class = ' class="alternate"'; + else + $class = ''; + + // Display the row + echo ' + + + + + + '; + + // Increase the counter for zebra striping + $i++; + } + + } else { + + echo ' + + '; + } + ?> + +
+ + + + + + + + + +
+ + + + + + + + + +
+ + + + ' . esc_html( basename( $file ) ) . ' + + + ' . esc_html( $type ) . ' + + ' . esc_html( round( filesize( $file ) / 1024, 2 ) ) . ' KB + + ' . esc_html( date( 'Y-m-d H:i:s', substr( $timestamp['1'], 0, 10 ) ) ) . ' +
+ ' . __( 'No backup files found.', 'WPMove' ) . ' +
+
+
+

+

+ +

+
+ + +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + 1 ) { + + // For zebra striping + $i = 0; + + // Display all old backups starting with database backups + foreach ( $old_backups as $file ) { + + // Get the file extension + $ext = substr( $file, -3, 3 ); + + // Decide the backup type + if ( $ext == 'sql' ) { + preg_match( '/DBBackup-([0-9]*).sql/', basename( $file ), $timestamp ); + $type = __( 'Database Backup', 'WPMove' ); + } else if ( $ext == 'zip' ) { + preg_match( '/Backup-([0-9]*).zip/', basename( $file ), $timestamp ); + $type = __( 'Filesystem Backup', 'WPMove' ); + } else { + continue; + } + + // For zebra striping + if ( $i % 2 !== 0 ) + $class = ' class="alternate"'; + else + $class = ''; + + // Display the row + echo ' + + + + + + '; + + // For zebra striping + $i++; + } + + } else { + + echo ' + + '; + } + ?> + +
+ + + + + + + + + +
+ + + + + + + + + +
+ + + + ' . esc_html( basename( $file ) ) . ' + + + ' . esc_html( $type ) . ' + + ' . esc_html( round( filesize( $file ) / 1024, 2 ) ) . ' KB + + ' . esc_html( date( 'Y-m-d H:i:s', substr( $timestamp['1'], 0, 10 ) ) ) . ' +
+ ' . __( 'No backup files found.', 'WPMove' ) . ' +
+
+
+

+

+ +

+
+ + +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + 1 ) { + + // For zebra striping + $i = 0; + + // Display all current backups starting with database backups + foreach ( $converted_backups as $file ) { + + // Get the file extension + $ext = substr( $file, -3, 3 ); + + // Decide the type of the backup + if ( $ext == 'sql' ) { + preg_match( '/DBBackup-([0-9]*).sql/', basename( $file ), $timestamp ); + $type = __( 'Database Backup', 'WPMove' ); + } else { + continue; + } + + // For zebra striping + if ( $i % 2 !== 0 ) + $class = ' class="alternate"'; + else + $class = ''; + + // Display the row + echo ' + + + + + + '; + + // Increase the counter for zebra striping + $i++; + } + } else { + + echo ' + + '; + } + ?> + +
+ + + + + + + + + +
+ + + + + + + + + +
+ + + + ' . esc_html( basename( $file ) ) . ' + + + ' . esc_html( $type ) . ' + + ' . esc_html( round( filesize( $file ) / 1024, 2 ) ) . ' KB + + ' . esc_html( date( 'Y-m-d H:i:s', substr( $timestamp['1'], 0, 10 ) ) ) . ' +
+ ' . __( 'No converted database backup files found. You can convert a database backup file using the Convert option from the dropdown lists above.', 'WPMove' ) . ' +
+
+
+ From dfd7193388884be3435f43bf7ec879630e104fa2 Mon Sep 17 00:00:00 2001 From: Dylan Thomas Date: Tue, 18 Jun 2013 09:17:43 -0600 Subject: [PATCH 3/5] Reverted Copyright Block. Fixed typo. --- wordpress-move.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/wordpress-move.php b/wordpress-move.php index 33546e6..c5f4716 100644 --- a/wordpress-move.php +++ b/wordpress-move.php @@ -1,14 +1,12 @@



- + @@ -1466,7 +1464,7 @@ function print_complete_migration_page() { - + @@ -1485,7 +1483,7 @@ function print_complete_migration_page() { - + From f1ac6b6570221b6eaad6429b684c1f3ad9c11e82 Mon Sep 17 00:00:00 2001 From: Dylan Thomas Date: Tue, 18 Jun 2013 13:06:08 -0600 Subject: [PATCH 4/5] Generalized Settings Pane Function Settings panes can now be made just by adding an 'add_meta_box()' function in the following format: add_meta_box( 'wpmove-NAME-settings', __( 'NAME Settings', 'WPMove' ), array($this, 'metabox_settings'), 'wpmove-settings',$context = 'advanced', $priority = 'default', $callback_args='NAME'); --- wordpress-move.php | 241 ++++++--------------------------------------- 1 file changed, 28 insertions(+), 213 deletions(-) diff --git a/wordpress-move.php b/wordpress-move.php index c5f4716..169ca15 100644 --- a/wordpress-move.php +++ b/wordpress-move.php @@ -1,12 +1,14 @@ get_admin_options(); + $server=$metabox['args']; ?> - - - - - - - - - @@ -400,28 +403,28 @@ function metabox_dev_settings( $wpmove_options ) { - - - @@ -432,194 +435,6 @@ function metabox_dev_settings( $wpmove_options ) { } - /** - * Callback function for the STAGING Connection Details meta box. - * - * @param $wpmove_options Plugin settings array - * @return void - */ - function metabox_staging_settings( $wpmove_options ) { - - ?> - -
+
+
+
+
+ /var/www/wp-content/plugins/wordpress-move2/backup/

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - - -
- - -
- - - - /var/www/wp-content/plugins/wordpress-move2/backup/
- -
-
-get_admin_options(); - - ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - -
- - - -
- - - -
- - -
- - - - /var/www/wp-content/plugins/wordpress-move2/backup/
- -
-
-



- + From b7a413b5dbfc6c24559054354d2e5ff09ad57074 Mon Sep 17 00:00:00 2001 From: Dylan Thomas Date: Mon, 12 Aug 2013 14:21:58 -0600 Subject: [PATCH 5/5] updated plugin info. -DHT --- wordpress-move.php | 136 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 6 deletions(-) diff --git a/wordpress-move.php b/wordpress-move.php index 169ca15..ae8121f 100644 --- a/wordpress-move.php +++ b/wordpress-move.php @@ -2,8 +2,7 @@ /* Plugin Name: WordPress Move - Multi-Tier Development Version Plugin URI: https://github.com/dylanhthomas/wordpress-move -OLDPlugin URI: http://www.mertyazicioglu.com/wordpress-move/ -Description: This is a fork of the popular WordPress Move plugin, which is a migration assistant for Wordpress. This version adds multiple target servers to facilitate a multi-tier development and review workflow without changing FTP settings at every step. After activating the plugin, please navigate to WordPress Move page under the Settings menu to configure it. Then, you can start using the Migration Assistant under the Tools menu. +Description: This is a fork of the popular WordPress Move plugin (http://www.mertyazicioglu.com/wordpress-move/), which is a migration assistant for Wordpress. This version adds multiple target servers to facilitate a multi-tier development and review workflow without changing FTP settings at every step. Additionally, a "Quick Deploy" option has been added for database-only transfers. After activating the plugin, please navigate to WordPress Move page under the Settings menu to configure it. Then, you can start using the Migration Assistant under the Tools menu. Version: 1.3.2 Author: Dylan Thomas (this version) / Mert Yazicioglu (Original) Author URI: http://www.mertyazicioglu.com @@ -140,6 +139,7 @@ function load_migration_assistant_scripts() { add_meta_box( 'wpmove-ma-migrate-ftp', __( 'FTP Settings', 'WPMove' ), array( $this, 'metabox_ma_migrate_ftp' ), 'wpmove-ma-migrate' ); add_meta_box( 'wpmove-ma-migrate-domain', __( 'Change Domain Name (Optional)', 'WPMove' ), array( $this, 'metabox_ma_migrate_domain' ), 'wpmove-ma-migrate' ); add_meta_box( 'wpmove-ma-migrate-filetree', __( 'Files to Transfer', 'WPMove' ), array( $this, 'metabox_ma_migrate_filetree' ), 'wpmove-ma-migrate' ); + } /** @@ -210,6 +210,8 @@ function get_admin_options() { 'ftp_dev_passive_mode' => 1, 'ftp_dev_remote_path' => '/www/wp-content/plugins/wordpress-move/backup/', 'ftp_dev_url' => 'http://dev.example.com', + 'ftp_dev_password' => 'password', + 'ftp_staging_hostname' => '', 'ftp_staging_port' => 21, @@ -217,6 +219,7 @@ function get_admin_options() { 'ftp_staging_passive_mode' => 1, 'ftp_staging_remote_path' => '/www/wp-content/plugins/wordpress-move/backup/', 'ftp_staging_url' => 'http://staging.example.com', + 'ftp_staging_password' => 'password', 'ftp_production_hostname' => '', 'ftp_production_port' => 21, @@ -224,6 +227,7 @@ function get_admin_options() { 'ftp_production_passive_mode' => 1, 'ftp_production_remote_path' => '/www/wp-content/plugins/wordpress-move/backup/', 'ftp_production_url' => 'http://production.example.com', + 'ftp_production_password' => 'password', ); // Try retrieving options from the database @@ -273,6 +277,7 @@ function print_settings_page() { $wpmove_options['ftp_dev_passive_mode'] = intval( $_POST['wpmove_ftp_dev_passive_mode'] ); $wpmove_options['ftp_dev_remote_path'] = sanitize_text_field( $_POST['wpmove_ftp_dev_remote_path'] ); $wpmove_options['ftp_dev_url'] = sanitize_text_field( $_POST['wpmove_ftp_dev_url'] ); + $wpmove_options['ftp_dev_password'] = sanitize_text_field( $_POST['wpmove_ftp_dev_password'] ); $wpmove_options['ftp_staging_hostname'] = sanitize_text_field( $_POST['wpmove_ftp_staging_hostname'] ); $wpmove_options['ftp_staging_port'] = intval( $_POST['wpmove_ftp_staging_port'] ); @@ -280,6 +285,7 @@ function print_settings_page() { $wpmove_options['ftp_staging_passive_mode'] = intval( $_POST['wpmove_ftp_staging_passive_mode'] ); $wpmove_options['ftp_staging_remote_path'] = sanitize_text_field( $_POST['wpmove_ftp_staging_remote_path'] ); $wpmove_options['ftp_staging_url'] = sanitize_text_field( $_POST['wpmove_ftp_staging_url'] ); + $wpmove_options['ftp_staging_password'] = sanitize_text_field( $_POST['wpmove_ftp_staging_password'] ); $wpmove_options['ftp_production_hostname'] = sanitize_text_field( $_POST['wpmove_ftp_production_hostname'] ); $wpmove_options['ftp_production_port'] = intval( $_POST['wpmove_ftp_production_port'] ); @@ -287,6 +293,8 @@ function print_settings_page() { $wpmove_options['ftp_production_passive_mode'] = intval( $_POST['wpmove_ftp_production_passive_mode'] ); $wpmove_options['ftp_production_remote_path'] = sanitize_text_field( $_POST['wpmove_ftp_production_remote_path'] ); $wpmove_options['ftp_production_url'] = sanitize_text_field( $_POST['wpmove_ftp_production_url'] ); + $wpmove_options['ftp_production_password'] = sanitize_text_field( $_POST['wpmove_ftp_production_password'] ); + // Update plugin settings update_option( $this->admin_options_name, $wpmove_options ); @@ -398,7 +406,8 @@ function metabox_settings( $wpmove_options, $metabox ) { - + + @@ -509,6 +518,10 @@ function print_migration_assistant_page() { break; case 'migrate': $this->print_migration_page(); break; + + case 'quick-migrate': $this->print_quick_migration_page(); + break; + case 'complete': $this->print_complete_migration_page(); break; } @@ -623,11 +636,37 @@ function metabox_ma_migrate() {
+

Files and DB - With Options





+

+

DB Only - No Options

+ DB will be immediately uploaded (but not published) + + + + Dev', 'WPMove' ); ?>

+ Staging', 'WPMove' ); ?>

+ Production', 'WPMove' ); ?>

+ +
get_admin_options(); + + $server= sanitize_text_field($_GET['server']); + + $ftp_password = $wpmove_options['ftp_'.$server.'_password']; + + + // Create an array to hold backup files that will be uploaded + $backups = array(); + + // Apply filters to the given domain names + $old_domain_name = home_url(); + $new_domain_name = $wpmove_options['ftp_'.$server.'_url']; + + // Create a backup of the database by changing instances of the old domain name with the newer one + $db_backups = wpmove_create_db_backup( $wpmove_options['db_chunk_size'], 1, $old_domain_name, $new_domain_name ); + + + // Add names of database backup files to the array of backup files + $backups = array_merge( $backups, $db_backups ); + + // Check whether an array is actually posted or not + if ( isset( $_POST['files'] ) && is_array( $_POST['files'] ) ) { + + // Use the POST data directly, if the fallback method is being used + $files = array_map( 'sanitize_text_field', $_POST['files'] ); + + // Remove non-empty directories from the array + $files = array_filter( $files ); + + // Create chunks from the selected files + $chunks = wpmove_divide_into_chunks( $files, $wpmove_options['fs_chunk_size'] ); + + // To prevent overwriting archives created in the same second + $chunk_id = 1; + + // Create an archive of the each chunk + foreach ( $chunks as $chunk ) + array_push( $backups, wpmove_create_archive( $chunk, ABSPATH, $chunk_id++ ) ); + } + + // Check whether creating backups files succeeded or not + if ( ! file_exists( trailingslashit( WPMOVE_BACKUP_DIR ) . $backups['0'] ) ) { + _e( 'Could not create backup files. Please make sure the backup directory is writable. For further info, please refer to the documentation.', 'WPMove' ); + } else { + + // Upload files and display a success message on success + if ( $this->upload_files( $backups, sanitize_text_field( $ftp_password ) ) ) { + + ?> +
+ The database has been uploaded to '.$server.'.
Log in to '.$server.' to complete migration.', 'WPMove' ); ?> +

+ + +
+ +

+ + get_admin_options(); + $server= sanitize_text_field($_GET['server']); ?>

-
+

-
+