mirror of
https://github.com/moodle/moodle.git
synced 2025-07-19 13:21:42 +02:00
MDL-23984 improved dataroot handling in installer
This commit is contained in:
10
install.php
10
install.php
@@ -304,7 +304,7 @@ if ($config->stage == INSTALL_DOWNLOADLANG) {
|
||||
$hint_dataroot = get_string('pathsroparentdataroot', 'install', $a);
|
||||
$config->stage = INSTALL_PATHS;
|
||||
} else {
|
||||
if (!make_upload_directory('lang', false)) {
|
||||
if (!install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
|
||||
$hint_dataroot = get_string('pathserrcreatedataroot', 'install', $a);
|
||||
$config->stage = INSTALL_PATHS;
|
||||
}
|
||||
@@ -344,12 +344,8 @@ if ($config->stage == INSTALL_DATABASETYPE) {
|
||||
if ($config->stage == INSTALL_DOWNLOADLANG) {
|
||||
$downloaderror = '';
|
||||
|
||||
// Create necessary lang dir
|
||||
if (!make_upload_directory('lang', false)) {
|
||||
$downloaderror = get_string('cannotcreatelangdir', 'error');
|
||||
|
||||
// Download and install lang component
|
||||
} else if ($cd = new component_installer('http://download.moodle.org', 'langpack/2.0', $CFG->lang.'.zip', 'languages.md5', 'lang')) {
|
||||
// Download and install lang component, lang dir was already created in install_init_dataroot
|
||||
if ($cd = new component_installer('http://download.moodle.org', 'langpack/2.0', $CFG->lang.'.zip', 'languages.md5', 'lang')) {
|
||||
if ($cd->install() == COMPONENT_ERROR) {
|
||||
if ($cd->get_error() == 'remotedownloaderror') {
|
||||
$a = new stdClass();
|
||||
|
@@ -78,6 +78,57 @@ function install_ini_get_bool($ini_get_arg) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates dataroot if not exists yet,
|
||||
* makes sure it is writable, add lang directory
|
||||
* and add .htaccess just in case it works.
|
||||
*
|
||||
* @param string $dataroot full path to dataroot
|
||||
* @param int $dirpermissions
|
||||
* @return bool success
|
||||
*/
|
||||
function install_init_dataroot($dataroot, $dirpermissions) {
|
||||
if (file_exists($dataroot) and !is_dir($dataroot)) {
|
||||
// file with the same name exists
|
||||
return false;
|
||||
}
|
||||
|
||||
umask(0000);
|
||||
if (!file_exists($dataroot)) {
|
||||
if (!mkdir($dataroot, $dirpermissions, true)) {
|
||||
// most probably this does not work, but anyway
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@chmod($dataroot, $dirpermissions);
|
||||
|
||||
if (!is_writable($dataroot)) {
|
||||
return false; // we can not continue
|
||||
}
|
||||
|
||||
// now create the lang folder - we need it and it makes sure we can really write in dataroot
|
||||
if (!is_dir("$dataroot/lang")) {
|
||||
if (!mkdir("$dataroot/lang", $dirpermissions, true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!is_writable("$dataroot/lang")) {
|
||||
return false; // we can not continue
|
||||
}
|
||||
|
||||
// finally just in case some broken .htaccess that prevents access just in case it is allowed
|
||||
if (!file_exists("$dataroot/.htaccess")) {
|
||||
if ($handle = fopen("$dataroot/.htaccess", 'w')) {
|
||||
fwrite($handle, "deny from all\r\nAllowOverride None\r\nNote: this file is broken intentionally, we do not want anybody to undo it in subdirectory!\r\n");
|
||||
fclose($handle);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print help button
|
||||
* @param string $url
|
||||
|
Reference in New Issue
Block a user