diff --git a/wordpress-move.php b/wordpress-move.php index b0c3484..ae8121f 100644 --- a/wordpress-move.php +++ b/wordpress-move.php @@ -1,1845 +1,2040 @@ -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' => 10, - 'ftp_hostname' => '', - 'ftp_port' => 21, - 'ftp_username' => '', - 'ftp_passive_mode' => 1, - 'ftp_remote_path' => '', - ); - - // 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_hostname'] !== '' && $_POST['wpmove_ftp_username'] !== '' && $_POST['wpmove_ftp_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_hostname'] = sanitize_text_field( $_POST['wpmove_ftp_hostname'] ); - $wpmove_options['ftp_port'] = intval( $_POST['wpmove_ftp_port'] ); - $wpmove_options['ftp_username'] = sanitize_text_field( $_POST['wpmove_ftp_username'] ); - $wpmove_options['ftp_passive_mode'] = intval( $_POST['wpmove_ftp_passive_mode'] ); - $wpmove_options['ftp_remote_path'] = sanitize_text_field( $_POST['wpmove_ftp_remote_path'] ); - - // 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-move/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_hostname'] == '' || $wpmove_options['ftp_username'] == '' || $wpmove_options['ftp_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(); - - // Instantiate the FTP class - $ftp = new ftp(); - - // Enter Passive Mode if enabled - if ( $wpmove_options['ftp_passive_mode'] ) - $ftp->Passive( TRUE ); - - echo ''; - - printf( __( 'Connecting to %s:%d...', 'WPMove' ), $wpmove_options['ftp_hostname'], $wpmove_options['ftp_port'] ); - $this->flush_output(); - - // Set the hostname and the port - $ftp->SetServer( $wpmove_options['ftp_hostname'], intval( $wpmove_options['ftp_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_username'] ); - else - printf( __( 'Logging in as %s without a password...', 'WPMove' ), $wpmove_options['ftp_username'] ); - - $this->flush_output(); - - // Login to the server using the supplied credentials - if ( $ftp->login( $wpmove_options['ftp_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_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( 'd.m.Y 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( 'd.m.Y 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( 'd.m.Y 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_dev_password' => 'password', + + + '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_staging_password' => 'password', + + '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', + 'ftp_production_password' => 'password', + ); + + // 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_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'] ); + $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_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'] ); + $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'] ); + $wpmove_options['ftp_production_password'] = sanitize_text_field( $_POST['wpmove_ftp_production_password'] ); + + + // 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/
+ +
+
+ +

+ +

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

+ +

+ + + + + + + +
+ + + MB +
+ print_change_domain_name_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; + } + } else { + ?> +
+
+
+
+

+

+ +

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

+ +

+

+    
+

+

+ +

+

+    
+    
+    
+    
+    
+

+
+
+
+ +
+
+ +
+
+

+ +

+

+    
+    
+    
+

+

+ +

+

+    
+

+

+ +

+

+    
+    
+    
+

+
+
+
+

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(); + + // 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']); + + $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']); + ?> +

+
+

+
+
+

+ 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' ) . ' +
+
+
+