A1AI System Prompt Migration Test'; // Check current database version $current_version = get_option('a1ai_db_version', '1.0.0'); echo '

Current Database Version: ' . esc_html($current_version) . '

'; // Check if tables exist $system_prompts_table = $wpdb->prefix . 'a1ai_system_prompts'; $custom_instructions_table = $wpdb->prefix . 'a1ai_custom_instructions'; // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching // Direct database queries are necessary for diagnostic testing // Use prepared statements for table existence check $system_prompts_exists = $wpdb->get_var( $wpdb->prepare('SHOW TABLES LIKE %s', $system_prompts_table) ) === $system_prompts_table; $custom_instructions_exists = $wpdb->get_var( $wpdb->prepare('SHOW TABLES LIKE %s', $custom_instructions_table) ) === $custom_instructions_table; // phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery echo '

System Prompts Table Exists: ' . esc_html($system_prompts_exists ? 'Yes' : 'No') . '

'; echo '

Custom Instructions Table Exists: ' . esc_html($custom_instructions_exists ? 'Yes' : 'No') . '

'; // Check existing system prompts if ($system_prompts_exists) { // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching // Direct database queries are necessary for diagnostic testing // Use direct query with proper escaping for table names (compatible with all WordPress versions) $system_prompts = $wpdb->get_results( 'SELECT * FROM ' . esc_sql($system_prompts_table) . ' WHERE is_active = 1', ARRAY_A ); // phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery echo '

Existing System Prompts (wp_a1ai_system_prompts)

'; if (!empty($system_prompts)) { echo ''; echo ''; foreach ($system_prompts as $prompt) { $content_preview = substr($prompt['prompt_content'], 0, 100) . (strlen($prompt['prompt_content']) > 100 ? '...' : ''); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
IDChatbot IDPrompt NameContent PreviewCreated
' . esc_html($prompt['id']) . '' . esc_html($prompt['chatbot_id']) . '' . esc_html($prompt['prompt_name']) . '' . esc_html($content_preview) . '' . esc_html($prompt['created_at']) . '
'; } else { echo '

No active system prompts found.

'; } } // Check existing custom instructions if ($custom_instructions_exists) { // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching // Direct database queries are necessary for diagnostic testing // Use direct query with proper escaping for table names (compatible with all WordPress versions) $custom_instructions = $wpdb->get_results( 'SELECT * FROM ' . esc_sql($custom_instructions_table) . ' WHERE is_active = 1 ORDER BY instruction_type, priority', ARRAY_A ); // phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery echo '

Active Custom Instructions (wp_a1ai_custom_instructions)

'; if (!empty($custom_instructions)) { echo ''; echo ''; foreach ($custom_instructions as $instruction) { $content_preview = substr($instruction['instruction_content'], 0, 100) . (strlen($instruction['instruction_content']) > 100 ? '...' : ''); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
IDChatbot IDNameTypePriorityContent PreviewCreated
' . esc_html($instruction['id']) . '' . esc_html($instruction['chatbot_id']) . '' . esc_html($instruction['instruction_name']) . '' . esc_html($instruction['instruction_type']) . '' . esc_html($instruction['priority']) . '' . esc_html($content_preview) . '' . esc_html($instruction['created_at']) . '
'; } else { echo '

No active custom instructions found.

'; } // Also show inactive records to check for accumulation // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching // Direct database queries are necessary for diagnostic testing $inactive_instructions = $wpdb->get_results( 'SELECT * FROM ' . esc_sql($custom_instructions_table) . ' WHERE is_active = 0 ORDER BY instruction_type, priority', ARRAY_A ); // phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery if (!empty($inactive_instructions)) { echo '

Inactive Custom Instructions (wp_a1ai_custom_instructions)

'; echo '

These are deactivated records that should be cleaned up periodically:

'; echo ''; echo ''; foreach ($inactive_instructions as $instruction) { $content_preview = substr($instruction['instruction_content'], 0, 100) . (strlen($instruction['instruction_content']) > 100 ? '...' : ''); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
IDChatbot IDNameTypePriorityContent PreviewCreatedStatus
' . esc_html($instruction['id']) . '' . esc_html($instruction['chatbot_id']) . '' . esc_html($instruction['instruction_name']) . '' . esc_html($instruction['instruction_type']) . '' . esc_html($instruction['priority']) . '' . esc_html($content_preview) . '' . esc_html($instruction['created_at']) . 'Inactive
'; } } // Test migration if needed if (version_compare($current_version, '1.2.0', '<')) { echo '

Migration Test

'; echo '

Database version is below 1.2.0. Migration should run automatically when the plugin is updated.

'; // Manually trigger migration for testing if ($nonce_verified && isset($_GET['run_migration']) && $_GET['run_migration'] === '1') { echo '

Running migration manually...

'; // Load the migration class require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-a1ai-migration.php'; require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-a1ai-data-manager.php'; $data_manager = new A1AI_Data_Manager(); $migration = new A1AI_Migration($data_manager); $results = $migration->run_migrations(); echo '

Migration Results:

'; foreach ($results as $version => $result) { echo '

Version ' . esc_html($version) . ':

'; if (isset($result['messages'])) { echo ''; } if (isset($result['errors'])) { echo '
Errors:
'; } } // Refresh the page to show updated data echo '

Refresh to see updated data

'; } else { $nonce = wp_create_nonce('a1ai_run_migration'); echo '

Click here to run migration manually

'; } } else { echo '

Migration Status

'; echo '

Database is already at version 1.2.0 or higher. Migration has been completed.

'; } echo '
'; echo '

Back to A1AI Admin

'; ?>