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 '| ID | Chatbot ID | Prompt Name | Content Preview | Created |
|---|---|---|---|---|
| ' . esc_html($prompt['id']) . ' | '; echo '' . esc_html($prompt['chatbot_id']) . ' | '; echo '' . esc_html($prompt['prompt_name']) . ' | '; echo '' . esc_html($content_preview) . ' | '; echo '' . esc_html($prompt['created_at']) . ' | '; 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 '| ID | Chatbot ID | Name | Type | Priority | Content Preview | Created |
|---|---|---|---|---|---|---|
| ' . esc_html($instruction['id']) . ' | '; echo '' . esc_html($instruction['chatbot_id']) . ' | '; echo '' . esc_html($instruction['instruction_name']) . ' | '; echo '' . esc_html($instruction['instruction_type']) . ' | '; echo '' . esc_html($instruction['priority']) . ' | '; echo '' . esc_html($content_preview) . ' | '; echo '' . esc_html($instruction['created_at']) . ' | '; 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 'These are deactivated records that should be cleaned up periodically:
'; echo '| ID | Chatbot ID | Name | Type | Priority | Content Preview | Created | Status |
|---|---|---|---|---|---|---|---|
| ' . esc_html($instruction['id']) . ' | '; echo '' . esc_html($instruction['chatbot_id']) . ' | '; echo '' . esc_html($instruction['instruction_name']) . ' | '; echo '' . esc_html($instruction['instruction_type']) . ' | '; echo '' . esc_html($instruction['priority']) . ' | '; echo '' . esc_html($content_preview) . ' | '; echo '' . esc_html($instruction['created_at']) . ' | '; echo 'Inactive | '; 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 'Click here to run migration manually
'; } } else { echo 'Database is already at version 1.2.0 or higher. Migration has been completed.
'; } echo '