diff --git a/integrations/real-time-collaboration.php b/integrations/real-time-collaboration.php index 0580517ccb..f31062dafa 100644 --- a/integrations/real-time-collaboration.php +++ b/integrations/real-time-collaboration.php @@ -14,6 +14,19 @@ * @private */ class RealTimeCollaborationIntegration extends Integration { + /** + * Version of the vip-real-time-collaboration plugin to load. + * Used to control staged rollouts (e.g., staging gets new version first). + */ + const VIP_RTC_PLUGIN_VERSION = '0.1'; + + /** + * Version of the Gutenberg plugin to load. + * Empty string means load from the unversioned 'gutenberg' folder. + * A version number (e.g., '1.0') loads from 'gutenberg-1.0' folder. + */ + const VIP_RTC_GUTENBERG_VERSION = ''; + /** * Enable Pendo tracking for this integration. * @@ -50,8 +63,22 @@ private function can_load(): bool { return true; } + /** + * Get the path to the Gutenberg plugin. + * + * @return string|false The path to the Gutenberg plugin, or false if not found. + */ private function get_gutenberg_path(): string|false { - $gutenberg_path = WPVIP_MU_PLUGIN_DIR . '/vip-integrations/gutenberg/gutenberg.php'; + // Empty string means use the unversioned folder + if ( defined( 'VIP_RTC_GUTENBERG_VERSION' ) && '' === constant( 'VIP_RTC_GUTENBERG_VERSION' ) ) { + $gutenberg_folder = 'gutenberg'; + } elseif ( defined( 'VIP_RTC_GUTENBERG_VERSION' ) && '' !== constant( 'VIP_RTC_GUTENBERG_VERSION' ) ) { + $gutenberg_folder = 'gutenberg-' . constant( 'VIP_RTC_GUTENBERG_VERSION' ); + } else { + return false; + } + + $gutenberg_path = WPVIP_MU_PLUGIN_DIR . '/vip-integrations/' . $gutenberg_folder . '/gutenberg.php'; if ( ! file_exists( $gutenberg_path ) ) { return false; } @@ -59,14 +86,19 @@ private function get_gutenberg_path(): string|false { return $gutenberg_path; } + /** + * Get the path to the RTC plugin. + * + * @return string|false The path to the RTC plugin, or false if not found. + */ private function get_plugin_path(): string|false { - $latest_directory = $this->get_latest_version(); - if ( empty( $latest_directory ) ) { + if ( defined( 'VIP_RTC_PLUGIN_VERSION' ) ) { + $plugin_directory = 'vip-real-time-collaboration-' . constant( 'VIP_RTC_PLUGIN_VERSION' ); + } else { return false; } - // Load the plugin. - $load_path = WPVIP_MU_PLUGIN_DIR . '/vip-integrations/' . $latest_directory . '/vip-real-time-collaboration.php'; - // This check isn't strictly necessary, but better safe than sorry. + + $load_path = WPVIP_MU_PLUGIN_DIR . '/vip-integrations/' . $plugin_directory . '/vip-real-time-collaboration.php'; if ( ! file_exists( $load_path ) ) { return false; } @@ -110,22 +142,13 @@ public function load(): void { /** * Load the custom build of Gutenberg from vip-integrations - * and the latest version of the vip-real-time-collaboration plugin. + * and the configured version of the vip-real-time-collaboration plugin. */ require_once $gutenberg_path; require_once $load_path; }, 1); } - /** - * Get the latest version of Real-Time Collaboration. - * - * @return string|null The latest version of Real-Time Collaboration or null if no versions are found. - */ - public function get_latest_version() { - return get_latest_version( WPVIP_MU_PLUGIN_DIR . '/vip-integrations/', 'vip-real-time-collaboration', 'vip-real-time-collaboration.php' ); - } - /** * Configure Real-Time Collaboration for VIP Platform. * diff --git a/tests/integrations/test-real-time-collaboration.php b/tests/integrations/test-real-time-collaboration.php index e05fc19115..1cb4e15660 100644 --- a/tests/integrations/test-real-time-collaboration.php +++ b/tests/integrations/test-real-time-collaboration.php @@ -55,7 +55,7 @@ public function test_load_returns_early_if_plugin_already_loaded(): void { do_action( 'plugins_loaded' ); } - public function test_load_sets_inactive_if_no_versions_found(): void { + public function test_load_sets_inactive_if_plugin_file_not_found(): void { // Set up required constants Constant_Mocker::define( 'VIP_RTC_WS_AUTH_SECRET', 'test-secret' ); Constant_Mocker::define( 'VIP_RTC_WS_URL', 'wss://test.example.com' ); @@ -150,13 +150,6 @@ public function test_configure_handles_missing_config_values(): void { $this->assertFalse( defined( 'VIP_RTC_WS_URL' ) ); } - public function test_get_latest_version_returns_null_when_no_versions_are_found(): void { - $rtc_integration = new RealTimeCollaborationIntegration( $this->slug ); - $latest_version = $rtc_integration->get_latest_version(); - - $this->assertNull( $latest_version ); - } - public function test_load_sets_inactive_when_ws_auth_secret_missing(): void { Constant_Mocker::define( 'VIP_RTC_WS_URL', 'wss://test.example.com' ); // VIP_RTC_WS_AUTH_SECRET is intentionally not defined