Skip to content

Commit

Permalink
Fixes fatal error while reading config file of the integration (#4857)
Browse files Browse the repository at this point in the history
* 🐛 FIX: fatal error while updating configmap

* 👌 IMPROVE: use clearstatcache to clear the cache of a specific file instead whole cache

* 🐛 FIX: use @file_get_contents to suppress warning if file does not exist
  • Loading branch information
mehmoodak authored Sep 13, 2023
1 parent 41d9212 commit 10fb30f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions integrations/integration-vip-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,29 @@ private function set_config( string $slug ): void {
* @return null|mixed
*/
protected function get_vip_config_from_file( string $slug ) {
$config_file_path = ABSPATH . 'config/integrations-config/' . $slug . '-config.php';
$config_file_directory = ABSPATH . 'config/integrations-config';
$config_file_name = $slug . '-config.php';
$config_file_path = $config_file_directory . '/' . $config_file_name;

/**
* Clear cache to always read data from latest config file.
*
* Kubernetes ConfigMap updates the file via symlink instead of actually replacing the file and
* PHP cache can hold a reference to the old symlink that can cause fatal if we use require
* on it.
*/
if ( false === @file_get_contents( $config_file_path ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
clearstatcache( true, $config_file_directory . '/' . $config_file_name );
// Clears cache for files created by k8s ConfigMap.
clearstatcache( true, $config_file_directory . '/..data' );
clearstatcache( true, $config_file_directory . '/..data/' . $config_file_name );
}

if ( ! is_readable( $config_file_path ) ) {
return null;
}

return require_once $config_file_path;
return require $config_file_path;
}

/**
Expand Down

0 comments on commit 10fb30f

Please sign in to comment.