diff --git a/core/includes/install.inc b/core/includes/install.inc index 74d8e39..49c6c64 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -162,6 +162,44 @@ function drupal_get_database_types() { } /** + * Flushes a PHP file from any active opcode cache. + * + * If it is not possible to flush an individual file, the whole cache will be + * flushed. + * + * @param string $filepath + * Filepath of PHP file to be flushed. + */ +function drupal_clear_opcode_cache($filepath) { + // Do nothing if the file does not exist or it stat fails. + clearstatcache(TRUE, $filepath); + if (!file_exists($filepath) || !@stat($filepath)) { + return; + } + + try { + if (function_exists('opcache_invalidate')) { + opcache_invalidate($filepath); + } + if (function_exists('apc_delete_file')) { + apc_delete_file($filepath); + } + if (function_exists('wincache_refresh_if_changed')) { + wincache_refresh_if_changed(array($filepath)); + } + if (function_exists('xcache_clear_cache')) { + xcache_clear_cache(XC_TYPE_PHP); + } + if (function_exists('eaccelerator_clear')) { + eaccelerator_clear(); + } + } + catch (Exception $e) { + throw new Exception(t('Failed to clear the opcode cache for %settings. For the duration of the installation it is recommended to either disable the opcode cache, or reconfigure it to allow code changes to be seen immediately.', array('%settings' => $settings_file))); + } +} + +/** * Replaces values in settings.php with values in the submitted array. * * This function replaces values in place if possible, even for @@ -194,6 +232,7 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { if (!isset($settings_file)) { $settings_file = conf_path(FALSE) . '/settings.php'; } + $filepath = DRUPAL_ROOT . '/' . $settings_file; // Build list of setting names and insert the values into the global namespace. $variable_names = array(); $settings_settings = array(); @@ -206,7 +245,7 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { } $variable_names['$'. $setting] = $setting; } - $contents = file_get_contents(DRUPAL_ROOT . '/' . $settings_file); + $contents = file_get_contents($filepath); if ($contents !== FALSE) { // Step through each token in settings.php and replace any variables that // are in the passed-in array. @@ -307,7 +346,7 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { } // Write the new settings file. - if (file_put_contents(DRUPAL_ROOT . '/' . $settings_file, $buffer) === FALSE) { + if (file_put_contents($filepath, $buffer) === FALSE) { throw new Exception(t('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file))); } else { @@ -322,6 +361,8 @@ function drupal_rewrite_settings($settings = array(), $settings_file = NULL) { else { throw new Exception(t('Failed to open %settings. Verify the file permissions.', array('%settings' => $settings_file))); } + // Remove settings.php from any active opcode cache. + drupal_clear_opcode_cache($filepath); } /**