'ids', 'number' => 0]); foreach ($sites as $blog_id) { switch_to_blog($blog_id); self::activate_for_blog(); restore_current_blog(); } } else { self::activate_for_blog(); } } public static function deactivate($network_wide = false) { if (is_multisite() && $network_wide) { $sites = get_sites(['fields' => 'ids', 'number' => 0]); foreach ($sites as $blog_id) { switch_to_blog($blog_id); self::deactivate_for_blog(); restore_current_blog(); } } else { self::deactivate_for_blog(); } } public static function activate_for_blog() { global $wpdb; $table_name = $wpdb->prefix . 'shoponix_product_vectors'; $charset_collate = $wpdb->get_charset_collate(); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $sql = "CREATE TABLE IF NOT EXISTS $table_name ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, product_id BIGINT(20) UNSIGNED NOT NULL, content TEXT NOT NULL, embedding TEXT NOT NULL, -- JSON array of floats created_at DATETIME DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY product_id (product_id) ) $charset_collate;"; $transcripts_table = $wpdb->prefix . 'shoponix_chat_transcripts'; // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $sql2 = "CREATE TABLE IF NOT EXISTS $transcripts_table ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, session_id VARCHAR(128) NOT NULL, user_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, user_ip VARCHAR(45) NOT NULL DEFAULT '', messages LONGTEXT NOT NULL, status VARCHAR(20) NOT NULL DEFAULT 'active', ab_variation VARCHAR(10) DEFAULT '', last_user_message TEXT DEFAULT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY session_id (session_id) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); dbDelta($sql2); add_option('shoponix_mistral_api_key', ''); add_option('shoponix_embedding_model', 'mistral-embed'); add_option('shoponix_chat_model', 'mistral-tiny'); add_option('shoponix_top_k', 5); add_option('shoponix_system_prompt', 'You are a helpful WooCommerce assistant. Answer based only on the provided product information. Be concise.'); add_option('shoponix_enabled', 'yes'); add_option('shoponix_widget_position', 'bottom-right'); add_option('shoponix_primary_color', '#7c3aed'); // Schedule daily reindex if (!wp_next_scheduled('shoponix_daily_reindex')) { wp_schedule_event(time(), 'daily', 'shoponix_daily_reindex'); } } public static function deactivate_for_blog() { wp_clear_scheduled_hook('shoponix_daily_reindex'); if (function_exists('as_unschedule_all_actions')) { as_unschedule_all_actions('shoponix_process_single_product_index'); } } }