(int) $step['left'] ) ); } public function ajax_collation_whole() { AIEO_DMM::verify_ajax_request(); require_once AIEO_DIR . 'includes/sql/class-aieo-analytics-collation.php'; $started = AIEO_Analytics_Collation::start_whole_database(); if ( ! $started['ok'] ) { wp_send_json_error( array( 'message' => __( 'This database does not offer utf8mb4_uca1400_ai_ci.', 'ai-eshop-optimizer' ) ) ); } wp_send_json_success( array( 'left' => (int) $started['left'], 'message' => $started['left'] > 0 ? sprintf( _n( 'Started. %s table goes on in the background; this screen shows what is left.', 'Started. %s tables go on in the background; this screen shows what is left.', (int) $started['left'], 'ai-eshop-optimizer' ), number_format_i18n( (int) $started['left'] ) ) : __( 'Done: the whole database is in utf8mb4_uca1400_ai_ci.', 'ai-eshop-optimizer' ), ) ); } public function enqueue_admin_assets() { $css = 'assets/css/aieo-db-performance-admin.css'; wp_enqueue_style( 'aieo-db-performance-admin', AIEO_URI . $css, array(), file_exists( AIEO_DIR . $css ) ? (string) filemtime( AIEO_DIR . $css ) : '1' ); wp_enqueue_script( 'aieo-data-storage', AIEO_URI . 'assets/js/aieo-data-storage.js', array(), AIEO_VERSION, true ); wp_localize_script( 'aieo-data-storage', 'aieoDataStorage', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( AIEO_DMM::NONCE_ACTION ), 'i18n' => array( 'deleting' => __( 'Deleting old rows: %s so far', 'ai-eshop-optimizer' ), 'deleted' => __( 'rows deleted', 'ai-eshop-optimizer' ), 'busy' => __( 'The clean-up is already running in the background. Look again in a few minutes.', 'ai-eshop-optimizer' ), 'rebuilding' => __( 'Rebuilding %s', 'ai-eshop-optimizer' ), 'freed' => __( 'MB given back to the disk', 'ai-eshop-optimizer' ), 'failed' => __( 'The request failed. Try again.', 'ai-eshop-optimizer' ), 'tablesLeft' => __( 'Converting: %s tables left', 'ai-eshop-optimizer' ), 'wholeDone' => __( 'Done: the whole database is in utf8mb4_uca1400_ai_ci.', 'ai-eshop-optimizer' ), ), ) ); } public function ajax_retention_save() { AIEO_DMM::verify_ajax_request(); AIEO_Retention_Bootstrap::load_storage_classes(); $preset = isset( $_POST['preset'] ) ? sanitize_key( wp_unslash( $_POST['preset'] ) ) : 'balanced'; $days = array(); foreach ( AIEO_Data_Retention::KINDS as $kind ) { if ( isset( $_POST[ 'days_' . $kind ] ) ) { $days[ $kind ] = absint( wp_unslash( $_POST[ 'days_' . $kind ] ) ); } } $hour = isset( $_POST['hour'] ) ? absint( wp_unslash( $_POST['hour'] ) ) : AIEO_Data_Retention::HOUR; $saved = AIEO_Data_Retention::save( $preset, $days, $hour ); wp_send_json_success( array( 'message' => __( 'Saved. The next clean-up keeps each kind of data for its days.', 'ai-eshop-optimizer' ), 'days' => $saved['days'], ) ); } public function ajax_retention_run() { AIEO_DMM::verify_ajax_request(); AIEO_Retention_Bootstrap::load_storage_classes(); if ( ! empty( $_POST['first'] ) && class_exists( 'AIEO_Archive_Handlers' ) ) { AIEO_Archive_Handlers::handle( gmdate( 'Y-m-d H:i:s' ) ); } $state = AIEO_Data_Retention::run( 15.0 ); if ( ! empty( $state['busy'] ) ) { wp_send_json_success( array( 'busy' => true, 'deleted' => 0, 'more' => false ) ); } $deleted = 0; $held = array(); foreach ( (array) ( $state['targets'] ?? array() ) as $t ) { $deleted += (int) ( $t['deleted'] ?? 0 ); if ( '' !== (string) ( $t['held'] ?? '' ) ) { $held[] = (string) $t['held']; } } wp_send_json_success( array( 'deleted' => $deleted, 'more' => ! empty( $state['more'] ), 'held' => array_values( array_unique( $held ) ) ) ); } public function ajax_reclaim_save() { AIEO_DMM::verify_ajax_request(); AIEO_Retention_Bootstrap::load_storage_classes(); $schedule = isset( $_POST['schedule'] ) ? sanitize_key( wp_unslash( $_POST['schedule'] ) ) : 'monthly'; AIEO_Space_Reclaim::save( $schedule ); wp_send_json_success( array( 'message' => __( 'Saved.', 'ai-eshop-optimizer' ) ) ); } public function ajax_reclaim_run() { AIEO_DMM::verify_ajax_request(); AIEO_Retention_Bootstrap::load_storage_classes(); $tried = isset( $_POST['tried'] ) ? array_map( 'sanitize_text_field', (array) wp_unslash( $_POST['tried'] ) ) : array(); wp_send_json_success( AIEO_Space_Reclaim::step( $tried ) ); } public function render_subtab() { $this->render_template( 'db-performance.php', array() ); } }