Skip to content

Commit 46bfeaa

Browse files
authored
Merge pull request #4877 from Automattic/develop
Staging release: v20230919.0
2 parents b2cc828 + bbecfd8 commit 46bfeaa

File tree

11 files changed

+198
-82
lines changed

11 files changed

+198
-82
lines changed

.github/workflows/changelog-summary-prod.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
uses: actions/[email protected]
6565

6666
- name: Setup PHP
67-
uses: shivammathur/setup-php@2.25.5
67+
uses: shivammathur/setup-php@2.26.0
6868
with:
6969
php-version: '7.4'
7070

.github/workflows/changelog-summary-staging.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions/[email protected]
2020

2121
- name: Setup PHP
22-
uses: shivammathur/setup-php@2.25.5
22+
uses: shivammathur/setup-php@2.26.0
2323
with:
2424
php-version: '7.4'
2525

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
uses: actions/[email protected]
2929

3030
- name: Set up PHP
31-
uses: shivammathur/setup-php@2.25.5
31+
uses: shivammathur/setup-php@2.26.0
3232
with:
3333
coverage: none
3434
php-version: "8.0"

__tests__/e2e/package-lock.json

+29-35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integrations/integration-vip-config.php

+18-2
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,29 @@ private function set_config( string $slug ): void {
7878
* @return null|mixed
7979
*/
8080
protected function get_vip_config_from_file( string $slug ) {
81-
$config_file_path = ABSPATH . 'config/integrations-config/' . $slug . '-config.php';
81+
$config_file_directory = ABSPATH . 'config/integrations-config';
82+
$config_file_name = $slug . '-config.php';
83+
$config_file_path = $config_file_directory . '/' . $config_file_name;
84+
85+
/**
86+
* Clear cache to always read data from latest config file.
87+
*
88+
* Kubernetes ConfigMap updates the file via symlink instead of actually replacing the file and
89+
* PHP cache can hold a reference to the old symlink that can cause fatal if we use require
90+
* on it.
91+
*/
92+
if ( false === @file_get_contents( $config_file_path ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
93+
clearstatcache( true, $config_file_directory . '/' . $config_file_name );
94+
// Clears cache for files created by k8s ConfigMap.
95+
clearstatcache( true, $config_file_directory . '/..data' );
96+
clearstatcache( true, $config_file_directory . '/..data/' . $config_file_name );
97+
}
8298

8399
if ( ! is_readable( $config_file_path ) ) {
84100
return null;
85101
}
86102

87-
return require_once $config_file_path;
103+
return require $config_file_path;
88104
}
89105

90106
/**

integrations/integration.php

+40
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Automattic\VIP\Integrations;
99

10+
use Automattic\VIP\Integrations\IntegrationVipConfig;
11+
1012
/**
1113
* Abstract base class for all integration implementations.
1214
*
@@ -45,13 +47,26 @@ abstract class Integration {
4547
*/
4648
protected bool $is_active = false;
4749

50+
/**
51+
* Instance of VipIntegrationConfig. It's useful to have full configuration info
52+
* available inside each integration, we can use it for cases like multisite,
53+
* tracking etc.
54+
*
55+
* Note: We don't use this property for activation of the integration.
56+
*
57+
* @var IntegrationVipConfig
58+
*/
59+
private IntegrationVipConfig $vip_config;
60+
4861
/**
4962
* Constructor.
5063
*
5164
* @param string $slug Slug of the integration.
5265
*/
5366
public function __construct( string $slug ) {
5467
$this->slug = $slug;
68+
69+
add_action( 'switch_blog', array( $this, 'switch_blog_callback' ), 10, 2 );
5570
}
5671

5772
/**
@@ -80,6 +95,16 @@ public function activate( array $options = [] ): void {
8095
$this->options = $options;
8196
}
8297

98+
/**
99+
* Callback for `switch_blog` filter.
100+
*/
101+
public function switch_blog_callback(): void {
102+
// Updating config to make sure `get_config()` returns config of current blog instead of main site.
103+
if ( isset( $this->vip_config ) ) {
104+
$this->options['config'] = $this->vip_config->get_site_config();
105+
}
106+
}
107+
83108
/**
84109
* Returns true if this integration has been activated.
85110
*
@@ -109,6 +134,21 @@ public function get_slug(): string {
109134
return $this->slug;
110135
}
111136

137+
/**
138+
* Set vip_config property.
139+
*
140+
* @param IntegrationVipConfig $vip_config Instance of IntegrationVipConfig.
141+
*
142+
* @return void
143+
*/
144+
public function set_vip_config( IntegrationVipConfig $vip_config ): void {
145+
if ( ! $this->is_active() ) {
146+
trigger_error( sprintf( 'Configuration info can only assigned if integration is active.' ), E_USER_WARNING ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
147+
}
148+
149+
$this->vip_config = $vip_config;
150+
}
151+
112152
/**
113153
* Returns `true` if the integration is already available e.g. via customer code. We will use
114154
* this function to prevent activating of integration again.

integrations/integrations.php

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function activate_platform_integrations() {
7373
// If integration is activated successfully without any error then configure.
7474
if ( $integration->is_active() ) {
7575
$integration->configure();
76+
$integration->set_vip_config( $vip_config );
7677
}
7778
}
7879
}

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)