normalize_limit( $limit ) ); } public function fetchChatbotActivity( int $limit ): array { global $wpdb; $chatbot_table = $wpdb->prefix . 'aipt_chatbot_messages'; // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( $wpdb->prepare( "SELECT id, status, record_type, user_name, LEFT(message, 160) AS message_excerpt, ai_response IS NOT NULL AS has_ai_response, created_at FROM {$chatbot_table} WHERE record_type IN (%s, %s) ORDER BY created_at DESC LIMIT %d", 'error', 'conversation', $this->normalize_limit( $limit ) ), ARRAY_A ); // phpcs:enable return is_array( $rows ) ? $rows : array(); } public function fetchJobs( int $limit ): array { global $wpdb; $jobs_table = $wpdb->prefix . 'aipt_automation_jobs'; // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching $rows = $wpdb->get_results( $wpdb->prepare( "SELECT id, name, status, created_at FROM {$jobs_table} ORDER BY created_at DESC LIMIT %d", $this->normalize_limit( $limit ) ), ARRAY_A ); // phpcs:enable return is_array( $rows ) ? $rows : array(); } private function normalize_limit( int $limit ): int { return max( 1, min( 10, $limit ) ); } }