Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 35 additions & 18 deletions integrations/real-time-collaboration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@

namespace Automattic\VIP\Integrations;

/**
* 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 = '';

/**
* Loads Real-Time Collaboration VIP Integration.
*
Expand Down Expand Up @@ -50,23 +63,36 @@ 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 ( '' === VIP_RTC_GUTENBERG_VERSION ) {
Comment thread
maxschmeling marked this conversation as resolved.
Outdated
$gutenberg_folder = 'gutenberg';
} else {
$gutenberg_folder = 'gutenberg-' . VIP_RTC_GUTENBERG_VERSION;
}

$gutenberg_path = WPVIP_MU_PLUGIN_DIR . '/vip-integrations/' . $gutenberg_folder . '/gutenberg.php';
if ( ! file_exists( $gutenberg_path ) ) {
return 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 ) ) {
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.
$plugin_directory = 'vip-real-time-collaboration-' . VIP_RTC_PLUGIN_VERSION;

$load_path = WPVIP_MU_PLUGIN_DIR . '/vip-integrations/' . $plugin_directory . '/vip-real-time-collaboration.php';
if ( ! file_exists( $load_path ) ) {
return false;
}
Expand Down Expand Up @@ -110,22 +136,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.
*
Expand Down
9 changes: 1 addition & 8 deletions tests/integrations/test-real-time-collaboration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -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
Expand Down
Loading