mirror of
https://github.com/moodle/moodle.git
synced 2025-07-20 05:41:34 +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);
|
$hint_dataroot = get_string('pathsroparentdataroot', 'install', $a);
|
||||||
$config->stage = INSTALL_PATHS;
|
$config->stage = INSTALL_PATHS;
|
||||||
} else {
|
} else {
|
||||||
if (!make_upload_directory('lang', false)) {
|
if (!install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
|
||||||
$hint_dataroot = get_string('pathserrcreatedataroot', 'install', $a);
|
$hint_dataroot = get_string('pathserrcreatedataroot', 'install', $a);
|
||||||
$config->stage = INSTALL_PATHS;
|
$config->stage = INSTALL_PATHS;
|
||||||
}
|
}
|
||||||
@@ -344,12 +344,8 @@ if ($config->stage == INSTALL_DATABASETYPE) {
|
|||||||
if ($config->stage == INSTALL_DOWNLOADLANG) {
|
if ($config->stage == INSTALL_DOWNLOADLANG) {
|
||||||
$downloaderror = '';
|
$downloaderror = '';
|
||||||
|
|
||||||
// Create necessary lang dir
|
// Download and install lang component, lang dir was already created in install_init_dataroot
|
||||||
if (!make_upload_directory('lang', false)) {
|
if ($cd = new component_installer('http://download.moodle.org', 'langpack/2.0', $CFG->lang.'.zip', 'languages.md5', 'lang')) {
|
||||||
$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')) {
|
|
||||||
if ($cd->install() == COMPONENT_ERROR) {
|
if ($cd->install() == COMPONENT_ERROR) {
|
||||||
if ($cd->get_error() == 'remotedownloaderror') {
|
if ($cd->get_error() == 'remotedownloaderror') {
|
||||||
$a = new stdClass();
|
$a = new stdClass();
|
||||||
|
@@ -78,6 +78,57 @@ function install_ini_get_bool($ini_get_arg) {
|
|||||||
return false;
|
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
|
* Print help button
|
||||||
* @param string $url
|
* @param string $url
|
||||||
|
Reference in New Issue
Block a user