Skip to content
Snippets Groups Projects
Verified Commit 3b05593f authored by Alberto Paderno's avatar Alberto Paderno
Browse files

Issue #2898530: HTTP_HOST is not a reliable default prefix

parent 6caedf3a
No related branches found
No related tags found
1 merge request!20Issue #2898530: HTTP_HOST is not a reliable default prefix
Pipeline #230903 passed
......@@ -66,3 +66,10 @@ function apc_requirements($phase) {
return $requirements;
}
/**
* Clear the APCu storage since the prefix used for the cache bins has changed.
*/
function apc_update_7101() {
apcu_clear_cache();
}
......@@ -94,22 +94,37 @@ protected static function getPrefixSettingForBin($bin) {
}
public function __construct($bin) {
global $databases;
$this->bin = $bin;
$this->drush = (drupal_is_cli() && function_exists('drush_log'));
// First we determine the prefix from a setting.
$prefix = self::getPrefixSettingForBin($this->bin);
// If we do not have a configured prefix we use the HTTP_HOST.
if (empty($prefix) && isset($_SERVER['HTTP_HOST'])) {
// Provide a fallback for multisite. This is on purpose not inside the
// getPrefixSettingsForBin() function in order to decouple the unified
// prefix variable logic and custom module related security logic, which
// is not necessary for all backends.
$prefix = $_SERVER['HTTP_HOST'] . '::';
// As fallback for a multisite installation, use the database connection
// information to generate a prefix.
if (empty($prefix) && isset($databases) && is_array($databases)) {
$db_info = '';
if (isset($databases['default']['default']) && is_array($databases['default']['default'])) {
if (isset($databases['default']['default']['host'])) {
$db_info .= $databases['default']['default']['prefix'];
}
if (isset($databases['default']['default']['database'])) {
$db_info .= $databases['default']['default']['database'];
}
if (isset($databases['default']['default']['prefix'])) {
$db_info .= serialize($databases['default']['default']['prefix']);
}
}
$hash = substr(hash('sha256', $db_info, TRUE), 0, 16);
$prefix = drupal_base64_encode($hash);
}
else {
$prefix = $prefix . '::';
if (!empty($prefix) && substr($prefix, -2) !== '::') {
$prefix .= '::';
}
// When we are in testing mode we add the test prefix.
......@@ -117,7 +132,7 @@ public function __construct($bin) {
$prefix = $test_prefix . '::' . $prefix;
}
$this->prefix = "apc_cache_$prefix";
$this->prefix = empty($prefix) ? 'apc_cache::' : "apc_cache_$prefix";
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment