Commit 9318a19f authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic
Browse files

Bug 1736843: recreate the sessions dirs when clear_all_caches deletes them

when calling clear_all_caches(true), the dataroot/sessions
directories will be deleted
we recreate them again at that moment instead of
waiting until the Session checks

behatnotneeded

Change-Id: I1ea2318cda4743d4908f5cb51990b02aa385a1ea
parent 5baa9b69
...@@ -123,25 +123,51 @@ class Session { ...@@ -123,25 +123,51 @@ class Session {
// Attempt to create session directories // Attempt to create session directories
if (!is_dir("$sessionpath/0")) { if (!is_dir("$sessionpath/0")) {
// Create three levels of directories, named 0-9, a-f // Create three levels of directories, named 0-9, a-f
$characters = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'); Session::create_directory_levels($sessionpath);
if (version_compare(PHP_VERSION, '7.1.0') >= 0) { }
$characters = array_merge($characters, array('g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', break;
'o', 'p', 'q', 'r', 's', 't', 'u', 'v')); default:
} throw new ConfigSanityException(get_string('wrongsessionhandle', 'error', get_config('sessionhandler')));
foreach ($characters as $c1) { }
check_dir_exists("$sessionpath/$c1"); }
foreach ($characters as $c2) {
check_dir_exists("$sessionpath/$c1/$c2"); public static function create_directory_levels($sessionpath) {
$status = true;
if (check_dir_exists($sessionpath)) {
// Create three levels of directories, named 0-9, a-f
$characters = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
$characters = array_merge($characters, array('g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v'));
}
foreach ($characters as $c1) {
if (check_dir_exists("$sessionpath/$c1")) {
foreach ($characters as $c2) {
if (check_dir_exists("$sessionpath/$c1/$c2")) {
foreach ($characters as $c3) { foreach ($characters as $c3) {
check_dir_exists("$sessionpath/$c1/$c2/$c3"); if (!check_dir_exists("$sessionpath/$c1/$c2/$c3")) {
$status = false;
break(3);
}
} }
} }
else {
$status = false;
break(2);
}
} }
} }
break; else {
default: $status = false;
throw new ConfigSanityException(get_string('wrongsessionhandle', 'error', get_config('sessionhandler'))); break;
}
}
}
else {
$status = false;
} }
return $status;
} }
/** /**
......
...@@ -5125,9 +5125,8 @@ function clear_all_caches($clearsessiondirs = false) { ...@@ -5125,9 +5125,8 @@ function clear_all_caches($clearsessiondirs = false) {
if ($clearsessiondirs) { if ($clearsessiondirs) {
$session_dir = get_config('dataroot') . 'sessions'; $session_dir = get_config('dataroot') . 'sessions';
if (check_dir_exists($session_dir) && !rmdirr($session_dir)) { rmdirr($session_dir);
throw new SystemException('Can not remove session directory ' . $session_dir); Session::create_directory_levels($session_dir);
}
} }
clearstatcache(); clearstatcache();
......
...@@ -595,43 +595,9 @@ function upgrade_plugin($upgrade) { ...@@ -595,43 +595,9 @@ function upgrade_plugin($upgrade) {
} }
function core_postinst() { function core_postinst() {
$status = true;
// Attempt to create session directories // Attempt to create session directories
$sessionpath = get_config('sessionpath'); $sessionpath = get_config('sessionpath');
if (check_dir_exists($sessionpath)) { $status = Session::create_directory_levels($sessionpath);
// Create three levels of directories, named 0-9, a-f
$characters = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
$characters = array_merge($characters, array('g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v'));
}
foreach ($characters as $c1) {
if (check_dir_exists("$sessionpath/$c1")) {
foreach ($characters as $c2) {
if (check_dir_exists("$sessionpath/$c1/$c2")) {
foreach ($characters as $c3) {
if (!check_dir_exists("$sessionpath/$c1/$c2/$c3")) {
$status = false;
break(3);
}
}
}
else {
$status = false;
break(2);
}
}
}
else {
$status = false;
break;
}
}
}
else {
$status = false;
}
$now = db_format_timestamp(time()); $now = db_format_timestamp(time());
// Set default search plugin // Set default search plugin
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment