tags which act as JS event buttons, will not jump page to top and will deselect the button
$( 'body' ).on( 'click', '.js-action-link', function( e ) {
e.preventDefault();
$( this ).blur();
} );
function enable_pro_licence( data, licence_key ) {
$( '.licence-input, .register-licence' ).remove();
$( '.licence-not-entered' ).prepend( data.masked_licence );
$( '.support-content' ).empty().html( '' + wpmdb_strings.fetching_license + '
' );
check_licence( licence_key );
$( '.migrate-selection label' ).removeClass( 'disabled' );
$( '.migrate-selection input' ).removeAttr( 'disabled' );
}
// registers your licence
$( '.licence-form' ).submit( function( e ) {
e.preventDefault();
if ( doing_licence_registration_ajax ) {
return;
}
$( '.licence-status' ).removeClass( 'notification-message error-notice success-notice' );
var licence_key = $.trim( $( '.licence-input' ).val() );
if ( '' === licence_key ) {
$( '.licence-status' ).addClass( 'notification-message error-notice' );
$( '.licence-status' ).html( wpmdb_strings.enter_license_key );
return;
}
$( '.licence-status' ).empty().removeClass( 'success' );
doing_licence_registration_ajax = true;
$( '.button.register-licence' ).after( '' );
$.ajax( {
url: ajaxurl,
type: 'POST',
dataType: 'JSON',
cache: false,
data: {
action: 'wpmdb_activate_licence',
licence_key: licence_key,
nonce: wpmdb_data.nonces.activate_licence,
context: 'licence'
},
error: function( jqXHR, textStatus, errorThrown ) {
doing_licence_registration_ajax = false;
$( '.register-licence-ajax-spinner' ).remove();
$( '.licence-status' ).html( wpmdb_strings.register_license_problem );
},
success: function( data ) {
doing_licence_registration_ajax = false;
$( '.register-licence-ajax-spinner' ).remove();
if ( 'undefined' !== typeof data.errors ) {
var msg = '';
for ( var key in data.errors ) {
msg += data.errors[ key ];
}
$( '.licence-status' ).html( msg );
if ( 'undefined' !== typeof data.masked_licence ) {
enable_pro_licence( data, licence_key );
$( '.migrate-tab .invalid-licence' ).hide();
}
} else if ( 'undefined' !== typeof data.wpmdb_error && 'undefined' !== typeof data.body ) {
$( '.licence-status' ).html( data.body );
} else {
$( '.licence-status' ).html( wpmdb_strings.license_registered ).delay( 5000 ).fadeOut( 1000 );
$( '.licence-status' ).addClass( 'success notification-message success-notice' );
enable_pro_licence( data, licence_key );
$( '.invalid-licence' ).hide();
}
}
} );
} );
// clears the debug log
$( '.clear-log' ).click( function() {
$( '.debug-log-textarea' ).val( '' );
$.ajax( {
url: ajaxurl,
type: 'POST',
dataType: 'text',
cache: false,
data: {
action: 'wpmdb_clear_log',
nonce: wpmdb_data.nonces.clear_log
},
error: function( jqXHR, textStatus, errorThrown ) {
alert( wpmdb_strings.clear_log_problem );
},
success: function( data ) {
}
} );
} );
// updates the debug log when the user switches to the help tab
function refresh_debug_log() {
$.ajax( {
url: ajaxurl,
type: 'POST',
dataType: 'text',
cache: false,
data: {
action: 'wpmdb_get_log',
nonce: wpmdb_data.nonces.get_log
},
error: function( jqXHR, textStatus, errorThrown ) {
alert( wpmdb_strings.update_log_problem );
},
success: function( data ) {
$( '.debug-log-textarea' ).val( data );
}
} );
}
// select all tables
$( '.multiselect-select-all' ).click( function() {
var multiselect = $( this ).parents( '.select-wrap' ).children( '.multiselect' );
$( 'option', multiselect ).prop( 'selected', 1 );
$( multiselect ).focus().trigger( 'change' );
} );
// deselect all tables
$( '.multiselect-deselect-all' ).click( function() {
var multiselect = $( this ).parents( '.select-wrap' ).children( '.multiselect' );
$( 'option', multiselect ).removeAttr( 'selected' );
$( multiselect ).focus().trigger( 'change' );
} );
// invert table selection
$( '.multiselect-invert-selection' ).click( function() {
var multiselect = $( this ).parents( '.select-wrap' ).children( '.multiselect' );
$( 'option', multiselect ).each( function() {
$( this ).attr( 'selected', !$( this ).attr( 'selected' ) );
} );
$( multiselect ).focus().trigger( 'change' );
} );
// on option select hide all "advanced" option divs and show the correct div for the option selected
$( '.option-group input[type=radio]' ).change( function() {
var group = $( this ).closest( '.option-group' );
$( 'ul', group ).hide();
var parent = $( this ).closest( 'li' );
$( 'ul', parent ).show();
} );
// on page load, expand hidden divs for selected options (browser form cache)
$( '.option-group' ).each( function() {
$( '.option-group input[type=radio]' ).each( function() {
if ( $( this ).is( ':checked' ) ) {
var parent = $( this ).closest( 'li' );
$( 'ul', parent ).show();
}
} );
} );
// expand and collapse content on click
$( '.header-expand-collapse' ).click( function() {
if ( $( '.expand-collapse-arrow', this ).hasClass( 'collapsed' ) ) {
$( '.expand-collapse-arrow', this ).removeClass( 'collapsed' );
$( this ).next().show();
} else {
$( '.expand-collapse-arrow', this ).addClass( 'collapsed' );
$( this ).next().hide();
}
} );
$( '.checkbox-label input[type=checkbox]' ).change( function() {
if ( $( this ).is( ':checked' ) ) {
$( this ).parent().next().show();
} else {
$( this ).parent().next().hide();
}
} );
// special expand and collapse content on click for save migration profile
$( '#save-migration-profile' ).change( function() {
if ( $( this ).is( ':checked' ) ) {
$( '.save-settings-button' ).show();
$( '.migrate-db .button-primary' ).val( wpmdb_strings.migrate_db_save );
} else {
$( '.save-settings-button' ).hide();
$( '.migrate-db .button-primary' ).val( wpmdb_strings.migrate_db );
}
} );
$( '.create-new-profile' ).focus( function() {
$( '#create_new' ).prop( 'checked', true );
} );
if ( $( '#save-migration-profile' ).is( ':checked' ) ) {
$( '.save-settings-button' ).show();
$( '.migrate-db .button-primary' ).val( wpmdb_strings.migrate_db_save );
}
$( '.checkbox-label input[type=checkbox]' ).each( function() {
if ( $( this ).is( ':checked' ) ) {
$( this ).parent().next().show();
}
} );
// AJAX migrate button
$( '.migrate-db-button' ).click( function( event ) {
$( this ).blur();
event.preventDefault();
wpmdb.migration_state_id = '';
if ( false === $.wpmdb.apply_filters( 'wpmdb_migration_profile_ready', true ) ) {
return;
}
// check that they've selected some tables to migrate
if ( $( '#migrate-selected' ).is( ':checked' ) && null === $( '#select-tables' ).val() ) {
alert( wpmdb_strings.please_select_one_table );
return;
}
// check that they've selected some tables to backup
if ( 'savefile' !== wpmdb_migration_type() && $( '#backup-manual-select' ).is( ':checked' ) && null === $( '#select-backup' ).val() ) {
alert( wpmdb_strings.please_select_one_table_backup );
return;
}
var new_url_missing = false;
var new_file_path_missing = false;
if ( $( '#new-url' ).length && !$( '#new-url' ).val() ) {
$( '#new-url-missing-warning' ).show();
$( '#new-url' ).focus();
$( 'html,body' ).scrollTop( 0 );
new_url_missing = true;
}
if ( $( '#new-path' ).length && !$( '#new-path' ).val() ) {
$( '#new-path-missing-warning' ).show();
if ( false === new_url_missing ) {
$( '#new-path' ).focus();
$( 'html,body' ).scrollTop( 0 );
}
new_file_path_missing = true;
}
if ( true === new_url_missing || true === new_file_path_missing ) {
return;
}
// also save profile
if ( $( '#save-migration-profile' ).is( ':checked' ) ) {
save_active_profile();
}
form_data = $( '#migrate-form' ).serialize();
var doc_height = $( document ).height();
$( 'body' ).append( '' );
$( '#overlay' )
.height( doc_height )
.css( {
'position': 'fixed',
'top': 0,
'left': 0,
'width': '100%',
'z-index': 99999,
'display': 'none'
} );
var $progress_content = $progress_content_original.clone();
migration_intent = wpmdb_migration_type();
stage = 'backup';
if ( 'savefile' === migration_intent ) {
stage = 'migrate';
}
if ( false === $( '#create-backup' ).is( ':checked' ) ) {
stage = 'migrate';
}
var table_intent = $( 'input[name=table_migrate_option]:checked' ).val();
var connection_info = $.trim( $( '.pull-push-connection-info' ).val() ).split( '\n' );
var table_rows = '';
remote_site = connection_info[ 0 ];
secret_key = connection_info[ 1 ];
var static_migration_label = '';
$( '#overlay' ).after( $progress_content );
completed_msg = wpmdb_strings.exporting_complete;
if ( 'savefile' === migration_intent ) {
static_migration_label = wpmdb_strings.exporting_please_wait;
} else {
static_migration_label = get_migration_status_label( remote_site, migration_intent, 'migrating' );
completed_msg = get_migration_status_label( remote_site, migration_intent, 'completed' );
}
$( '.progress-title' ).html( static_migration_label );
$( '#overlay' ).show();
var backup_option = $( 'input[name=backup_option]:checked' ).val();
var table_option = $( 'input[name=table_migrate_option]:checked' ).val();
var selected_tables = '';
if ( 'backup' === stage ) {
if ( 'migrate_only_with_prefix' === table_option && 'backup_selected' === backup_option ) {
backup_option = 'backup_only_with_prefix';
}
if ( 'push' === migration_intent ) {
table_rows = wpmdb.common.connection_data.table_rows;
if ( 'backup_only_with_prefix' === backup_option ) {
tables_to_migrate = wpmdb.common.connection_data.prefixed_tables;
} else if ( 'backup_selected' === backup_option ) {
selected_tables = $( '#select-tables' ).val();
tables_to_migrate = get_intersect( selected_tables, wpmdb.common.connection_data.tables );
} else if ( 'backup_manual_select' === backup_option ) {
tables_to_migrate = $( '#select-backup' ).val();
}
} else {
table_rows = wpmdb_data.this_table_rows;
if ( 'backup_only_with_prefix' === backup_option ) {
tables_to_migrate = wpmdb_data.this_prefixed_tables;
} else if ( 'backup_selected' === backup_option ) {
selected_tables = $( '#select-tables' ).val();
tables_to_migrate = get_intersect( selected_tables, wpmdb_data.this_tables );
} else if ( 'backup_manual_select' === backup_option ) {
tables_to_migrate = $( '#select-backup' ).val();
}
}
} else {
tables_to_migrate = get_tables_to_migrate( null, null );
// User is pushing or exporting
if ( 'push' === migration_intent || 'savefile' === migration_intent ) {
// Default value, assuming we're not backing up
table_rows = wpmdb_data.this_table_rows;
} else {
table_rows = wpmdb.common.connection_data.table_rows;
}
}
function decide_tables_to_display_rows( tables_to_migrate, orig_table_rows ) {
var total_size = 0;
var table_rows = JSON.parse( JSON.stringify( orig_table_rows ) );
$.each( tables_to_migrate, function( index, value ) {
total_size += parseInt( table_rows[ value ] );
} );
var max_percent = 0;
var total_percent = 0;
var table_widths = [];
$.each( tables_to_migrate, function( index, value ) {
var percent = Math.round( ( table_rows[ value ] / total_size ) * 100 );
table_widths[ value ] = percent;
if ( percent > max_percent ) {
max_percent = percent;
}
total_percent += percent;
} );
var last_element = '';
var percent_diff = 100 - total_percent;
$.each( tables_to_migrate, function( index, value ) {
var percent = table_widths[ value ];
if ( 0 !== percent_diff && percent === max_percent ) {
percent += percent_diff;
percent_diff = 0;
}
$( '.progress-tables' ).append( '' + value + '
' );
$( '.progress-tables-hover-boxes' ).append( '' );
last_element = value;
} );
// Only enumerate progress-chunk classed elements from core
$( '.progress-tables', '.progress-wrapper-primary' ).find( '.progress-chunk' ).each( function( index ) {
if ( 1 > $( this ).width() ) {
$( this ).hide();
$( '.progress-chunk-hover[data-table=' + tables_to_migrate[ index ] + ']' ).hide();
table_rows[ last_element ] = Number( table_rows[ last_element ] );
table_rows[ last_element ] += Number( table_rows[ tables_to_migrate[ index ] ] );
table_rows[ tables_to_migrate[ index ] ] = 0;
}
var element = this;
setTimeout( function() {
hide_overflowing_elements( element );
}, 0 );
function hide_overflowing_elements( element ) {
if ( $( 'span', element ).innerWidth() > $( element ).width() ) {
$( 'span', element ).hide();
}
}
} );
var return_vals = [ table_rows, total_size ];
return return_vals;
}
var table_details = decide_tables_to_display_rows( tables_to_migrate, table_rows );
table_rows = table_details[ 0 ];
var total_size = table_details[ 1 ];
$( '.progress-title' ).after( '' );
var height = $( '.progress-content' ).outerHeight();
$( '.progress-content' ).css( 'top', '-' + height + 'px' ).show().animate( { 'top': '0px' } );
setup_counter();
currently_migrating = true;
var request_data = {
action: 'wpmdb_initiate_migration',
intent: migration_intent,
url: remote_site,
key: secret_key,
form_data: form_data,
stage: stage,
nonce: wpmdb_data.nonces.initiate_migration
};
if ( 'savefile' !== migration_intent ) {
request_data.temp_prefix = wpmdb.common.connection_data.temp_prefix;
}
doing_ajax = true;
$.ajax( {
url: ajaxurl,
type: 'POST',
dataType: 'json',
cache: false,
data: request_data,
error: function( jqXHR, textStatus, errorThrown ) {
$( '.progress-title' ).html( wpmdb_strings.migration_failed );
$( '.progress-text' ).html( getAjaxErrors( jqXHR.responseText, '(#112)', jqXHR ) );
$( '.progress-text' ).addClass( 'migration-error' );
console.log( jqXHR );
console.log( textStatus );
console.log( errorThrown );
doing_ajax = false;
wpmdb.common.migration_error = true;
wpmdb.functions.migration_complete_events();
return;
},
success: function( data ) {
doing_ajax = false;
if ( 'undefined' !== typeof data && 'undefined' !== typeof data.wpmdb_error && 1 === data.wpmdb_error ) {
wpmdb.common.migration_error = true;
wpmdb.functions.migration_complete_events();
$( '.progress-title' ).html( wpmdb_strings.migration_failed );
$( '.progress-text' ).addClass( 'migration-error' );
$( '.progress-text' ).html( data.body );
return;
}
wpmdb.migration_state_id = data.migration_state_id;
var i = 0;
var progress_size = 0;
overall_percent = 0;
var table_progress = 0;
var temp_progress = 0;
var last_progress = 0;
var overall_table_progress = 0;
// Set delay between requests - use max of local/remote values, 0 if doing export
delay_between_requests = 0;
if ( 'savefile' !== migration_intent && 'undefined' !== typeof wpmdb.common.connection_data && 'undefined' !== typeof wpmdb.common.connection_data.delay_between_requests ) {
delay_between_requests = Math.max( parseInt( wpmdb_data.delay_between_requests ), parseInt( wpmdb.common.connection_data.delay_between_requests ) );
}
wpmdb.functions.migrate_table_recursive = function( current_row, primary_keys ) {
if ( i >= tables_to_migrate.length ) {
if ( 'backup' === stage ) {
stage = 'migrate';
i = 0;
progress_size = 0;
overall_percent = 0;
$( '.progress-bar' ).width( '0px' );
tables_to_migrate = get_tables_to_migrate( null, null );
// User is pushing or exporting
if ( 'push' === migration_intent || 'savefile' === migration_intent ) {
// Default value, assuming we're not backing up
table_rows = wpmdb_data.this_table_rows;
} else {
table_rows = wpmdb.common.connection_data.table_rows;
}
$( '.progress-tables' ).empty();
$( '.progress-tables-hover-boxes' ).empty();
table_details = decide_tables_to_display_rows( tables_to_migrate, table_rows );
table_rows = table_details[ 0 ];
total_size = table_details[ 1 ];
} else {
$( '.progress-label' ).removeClass( 'label-visible' );
wpmdb.common.hooks = $.wpmdb.apply_filters( 'wpmdb_before_migration_complete_hooks', wpmdb.common.hooks );
wpmdb.common.hooks.push( wpmdb.functions.migration_complete );
wpmdb.common.hooks.push( wpmdb.functions.wpmdb_flush );
wpmdb.common.hooks = $.wpmdb.apply_filters( 'wpmdb_after_migration_complete_hooks', wpmdb.common.hooks );
wpmdb.common.hooks.push( wpmdb.functions.migration_complete_events );
wpmdb.common.next_step_in_migration = { fn: wpmdb_call_next_hook };
wpmdb.functions.execute_next_step();
return;
}
}
if ( 'backup' === stage ) {
$( '.progress-text' ).html( overall_percent + '% - ' + wpmdb_strings.backing_up + ' "' + tables_to_migrate[ i ] + '"' );
} else {
$( '.progress-text' ).html( overall_percent + '% - ' + wpmdb_strings.migrating + ' "' + tables_to_migrate[ i ] + '"' );
}
var last_table = 0;
if ( i === ( tables_to_migrate.length - 1 ) ) {
last_table = 1;
}
var gzip = 0;
if ( 'savefile' !== migration_intent && 1 === parseInt( wpmdb.common.connection_data.gzip ) ) {
gzip = 1;
}
var request_data = {
action: 'wpmdb_migrate_table',
migration_state_id: wpmdb.migration_state_id,
table: tables_to_migrate[ i ],
stage: stage,
current_row: current_row,
last_table: last_table,
primary_keys: primary_keys,
gzip: gzip,
nonce: wpmdb_data.nonces.migrate_table
};
if ( 'savefile' !== migration_intent ) {
request_data.bottleneck = wpmdb.common.connection_data.bottleneck;
request_data.prefix = wpmdb.common.connection_data.prefix;
}
if ( wpmdb.common.connection_data && wpmdb.common.connection_data.path_current_site && wpmdb.common.connection_data.domain ) {
request_data.path_current_site = wpmdb.common.connection_data.path_current_site;
request_data.domain_current_site = wpmdb.common.connection_data.domain;
}
doing_ajax = true;
$.ajax( {
url: ajaxurl,
type: 'POST',
dataType: 'text',
cache: false,
timeout: 0,
data: request_data,
error: function( jqXHR, textStatus, errorThrown ) {
$( '.progress-title' ).html( wpmdb_strings.migration_failed );
$( '.progress-text' ).html( wpmdb_strings.table_process_problem + ' ' + tables_to_migrate[ i ] );
$( '.progress-text' ).append( '
' + wpmdb_strings.status + ': ' + jqXHR.status + ' ' + jqXHR.statusText + '
' + wpmdb_strings.response + ':
' + jqXHR.responseText );
$( '.progress-text' ).addClass( 'migration-error' );
doing_ajax = false;
console.log( jqXHR );
console.log( textStatus );
console.log( errorThrown );
wpmdb.common.migration_error = true;
wpmdb.functions.migration_complete_events();
return;
},
success: function( data ) {
doing_ajax = false;
data = $.trim( data );
var row_information = wpmdb_parse_json( data );
if ( false === row_information || null === row_information ) {
$( '.progress-title' ).html( wpmdb_strings.migration_failed );
if ( '' === data || null === data ) {
$( '.progress-text' ).html( wpmdb_strings.table_process_problem_empty_response + ' ' + tables_to_migrate[ i ] );
} else {
$( '.progress-text' ).html( getAjaxErrors( data, null, null ) );
}
$( '.progress-text' ).addClass( 'migration-error' );
wpmdb.common.migration_error = true;
wpmdb.functions.migration_complete_events();
return;
}
if ( 'undefined' !== typeof row_information.wpmdb_error && 1 === row_information.wpmdb_error ) {
$( '.progress-title' ).html( wpmdb_strings.migration_failed );
$( '.progress-text' ).addClass( 'migration-error' );
$( '.progress-text' ).html( row_information.body );
wpmdb.common.migration_error = true;
wpmdb.functions.migration_complete_events();
return;
}
// We need the returned file name for delivery or display to the user.
if ( 1 === last_table && 'savefile' === migration_intent ) {
if ( 'undefined' !== typeof row_information.dump_filename ) {
dump_filename = row_information.dump_filename;
}
if ( 'undefined' !== typeof row_information.dump_path ) {
dump_path = row_information.dump_path;
}
}
if ( -1 === row_information.current_row || '-1' === row_information.current_row ) {
progress_size -= overall_table_progress;
overall_table_progress = 0;
last_progress = 0;
progress_size += parseInt( table_rows[ tables_to_migrate[ i ] ] );
i++;
row_information.current_row = '';
row_information.primary_keys = '';
} else {
temp_progress = parseInt( row_information.current_row );
table_progress = temp_progress - last_progress;
last_progress = temp_progress;
progress_size += table_progress;
overall_table_progress += table_progress;
}
overall_percent = Math.floor( ( progress_size / total_size ) * 100 );
$( '.progress-bar' ).width( overall_percent + '%' );
wpmdb.common.next_step_in_migration = {
fn: wpmdb.functions.migrate_table_recursive,
args: [ row_information.current_row, row_information.primary_keys ]
};
wpmdb.functions.execute_next_step();
}
} );
};
wpmdb.common.next_step_in_migration = {
fn: wpmdb.functions.migrate_table_recursive,
args: [ '-1', '' ]
};
wpmdb.functions.execute_next_step();
}
} ); // end ajax
} );
wpmdb.functions.migration_complete_events = function() {
if ( false === wpmdb.common.migration_error ) {
if ( '' === wpmdb.common.non_fatal_errors ) {
if ( 'savefile' !== migration_intent && true === $( '#save_computer' ).is( ':checked' ) ) {
$( '.progress-text' ).css( 'visibility', 'hidden' );
}
$( '.progress-title' ).html( completed_msg ).append( '' );
} else {
$( '.progress-text' ).html( wpmdb.common.non_fatal_errors );
$( '.progress-text' ).addClass( 'migration-error' );
$( '.progress-title' ).html( wpmdb_strings.completed_with_some_errors );
}
$( '.progress-bar-wrapper' ).hide();
}
$( '.migration-controls' ).hide();
// reset migration variables so consecutive migrations work correctly
wpmdb.common.hooks = [];
wpmdb.common.call_stack = [];
wpmdb.common.migration_error = false;
currently_migrating = false;
migration_completed = true;
migration_paused = false;
migration_cancelled = false;
doing_ajax = false;
wpmdb.common.non_fatal_errors = '';
$( '.progress-label' ).remove();
$( '.migration-progress-ajax-spinner' ).remove();
$( '.close-progress-content' ).show();
$( '#overlay' ).css( 'cursor', 'pointer' );
clearInterval( elapsed_interval );
};
wpmdb.functions.migration_complete = function() {
$( '.migration-controls' ).fadeOut();
if ( 'savefile' === migration_intent ) {
currently_migrating = false;
var migrate_complete_text = wpmdb_strings.migration_complete;
if ( $( '#save_computer' ).is( ':checked' ) ) {
var url = wpmdb_data.this_download_url + encodeURIComponent( dump_filename );
if ( $( '#gzip_file' ).is( ':checked' ) ) {
url += '&gzip=1';
}
window.location = url;
} else {
migrate_complete_text = wpmdb_strings.completed_dump_located_at + ' ' + dump_path;
}
if ( false === wpmdb.common.migration_error ) {
$( '.progress-text' ).html( migrate_complete_text );
wpmdb.functions.migration_complete_events();
$( '.progress-title' ).html( completed_msg );
}
} else { // rename temp tables, delete old tables
$( '.progress-text' ).html( wpmdb_strings.finalizing_migration );
doing_ajax = true;
$.ajax( {
url: ajaxurl,
type: 'POST',
dataType: 'text',
cache: false,
data: {
action: 'wpmdb_finalize_migration',
migration_state_id: wpmdb.migration_state_id,
prefix: wpmdb.common.connection_data.prefix,
tables: tables_to_migrate.join( ',' ),
nonce: wpmdb_data.nonces.finalize_migration
},
error: function( jqXHR, textStatus, errorThrown ) {
doing_ajax = false;
$( '.progress-title' ).html( wpmdb_strings.migration_failed );
$( '.progress-text' ).html( wpmdb_strings.finalize_tables_problem );
$( '.progress-text' ).addClass( 'migration-error' );
alert( jqXHR + ' : ' + textStatus + ' : ' + errorThrown );
wpmdb.common.migration_error = true;
wpmdb.functions.migration_complete_events();
return;
},
success: function( data ) {
doing_ajax = false;
if ( '1' !== $.trim( data ) ) {
$( '.progress-title' ).html( wpmdb_strings.migration_failed );
$( '.progress-text' ).html( data );
$( '.progress-text' ).addClass( 'migration-error' );
wpmdb.common.migration_error = true;
wpmdb.functions.migration_complete_events();
return;
}
wpmdb.common.next_step_in_migration = { fn: wpmdb_call_next_hook };
wpmdb.functions.execute_next_step();
}
} );
}
};
wpmdb.functions.wpmdb_flush = function() {
if ( 'savefile' !== migration_intent ) {
$( '.progress-text' ).html( wpmdb_strings.flushing );
doing_ajax = true;
$.ajax( {
url: ajaxurl,
type: 'POST',
dataType: 'text',
cache: false,
data: {
action: 'wpmdb_flush',
migration_state_id: wpmdb.migration_state_id,
nonce: wpmdb_data.nonces.flush
},
error: function( jqXHR, textStatus, errorThrown ) {
doing_ajax = false;
$( '.progress-title' ).html( wpmdb_strings.migration_failed );
$( '.progress-text' ).html( wpmdb_strings.flush_problem );
$( '.progress-text' ).addClass( 'migration-error' );
alert( jqXHR + ' : ' + textStatus + ' : ' + errorThrown );
wpmdb.common.migration_error = true;
wpmdb.functions.migration_complete_events();
return;
},
success: function( data ) {
doing_ajax = false;
if ( '1' !== $.trim( data ) ) {
$( '.progress-title' ).html( wpmdb_strings.migration_failed );
$( '.progress-text' ).html( data );
$( '.progress-text' ).addClass( 'migration-error' );
wpmdb.common.migration_error = true;
wpmdb.functions.migration_complete_events();
return;
}
wpmdb.common.next_step_in_migration = { fn: wpmdb_call_next_hook };
wpmdb.functions.execute_next_step();
}
} );
}
};
// close progress pop up once migration is completed
$( 'body' ).on( 'click', '.close-progress-content-button', function( e ) {
hide_overlay();
} );
$( 'body' ).on( 'click', '#overlay', function() {
if ( true === migration_completed ) {
hide_overlay();
}
} );
function hide_overlay() {
var height = $( '.progress-content' ).outerHeight();
$( '.progress-content' ).animate( { 'top': '-' + height + 'px' }, 400, 'swing', function() {
$( '#overlay' ).remove();
$( '.progress-content' ).remove();
} );
migration_completed = false;
}
// AJAX save button profile
$( '.save-settings-button' ).click( function( event ) {
event.preventDefault();
if ( '' === $.trim( $( '.create-new-profile' ).val() ) && $( '#create_new' ).is( ':checked' ) ) {
alert( wpmdb_strings.enter_name_for_profile );
$( '.create-new-profile' ).focus();
return;
}
save_active_profile();
} );
function save_active_profile() {
var profile;
$( '.save-settings-button' ).blur();
if ( doing_save_profile ) {
return;
}
// check that they've selected some tables to migrate
if ( $( '#migrate-selected' ).is( ':checked' ) && null === $( '#select-tables' ).val() ) {
alert( wpmdb_strings.please_select_one_table );
return;
}
// check that they've selected some tables to backup
if ( 'savefile' !== wpmdb_migration_type() && $( '#backup-manual-select' ).is( ':checked' ) && null === $( '#select-backup' ).val() ) {
alert( wpmdb_strings.please_select_one_table_backup );
return;
}
var create_new_profile = false;
if ( $( '#create_new' ).is( ':checked' ) ) {
create_new_profile = true;
}
var profile_name = $( '.create-new-profile' ).val();
doing_save_profile = true;
profile = $( '#migrate-form' ).serialize();
$( '.save-settings-button' ).attr( 'disabled', 'disabled' )
.after( '' );
doing_ajax = true;
$.ajax( {
url: ajaxurl,
type: 'POST',
dataType: 'text',
cache: false,
data: {
action: 'wpmdb_save_profile',
profile: profile,
nonce: wpmdb_data.nonces.save_profile
},
error: function( jqXHR, textStatus, errorThrown ) {
doing_ajax = false;
alert( wpmdb_strings.save_profile_problem );
$( '.save-settings-button' ).removeAttr( 'disabled' );
$( '.save-profile-ajax-spinner' ).remove();
$( '.save-settings-button' ).after( '' + wpmdb_strings.saved + '' );
$( '.ajax-success-msg' ).fadeOut( 2000, function() {
$( this ).remove();
} );
doing_save_profile = false;
},
success: function( data ) {
var updated_profile_id = parseInt( $( '#migrate-form input[name=save_migration_profile_option]:checked' ).val(), 10 ) + 1;
doing_ajax = false;
$( '.save-settings-button' ).removeAttr( 'disabled' );
$( '.save-profile-ajax-spinner' ).remove();
$( '.save-settings-button' ).after( '' + wpmdb_strings.saved + '' );
$( '.ajax-success-msg' ).fadeOut( 2000, function() {
$( this ).remove();
} );
doing_save_profile = false;
$( '.create-new-profile' ).val( '' );
if ( create_new_profile ) {
var new_profile_key = parseInt( data, 10 );
var new_profile_id = new_profile_key + 1;
var new_li = $( '' );
new_li.find( 'label' ).append( document.createTextNode( ' ' + profile_name ) );
updated_profile_id = new_profile_id;
$( '#create_new' ).parents( 'li' ).before( new_li );
$( '#profile-' + new_profile_id ).attr( 'checked', 'checked' );
}
// Push updated profile id to history if available
var updatedURL = window.location.href.replace( '#migrate', '' ).replace( /&wpmdb-profile=-?\d+/, '' ) + '&wpmdb-profile=' + updated_profile_id;
var updated_profile_name = $( '#migrate-form input[name=save_migration_profile_option]:checked' ).parent().text().trim();
if ( 'function' === typeof window.history.pushState ) {
if ( $( '#migrate-form .crumbs' ).length ) {
$( '#migrate-form .crumbs .crumb:last' ).text( updated_profile_name );
} else {
var $crumbs = $( '' )
.append( '