mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merge branch 'w44_MDL-42110_m26_addoninstaller' of https://github.com/skodak/moodle
This commit is contained in:
commit
9a84376d4b
@ -392,8 +392,10 @@ class tool_installaddon_installer {
|
||||
*
|
||||
* @param string $source full path to the existing directory
|
||||
* @param string $target full path to the new location of the directory
|
||||
* @param int $dirpermissions
|
||||
* @param int $filepermissions
|
||||
*/
|
||||
public function move_directory($source, $target) {
|
||||
public function move_directory($source, $target, $dirpermissions, $filepermissions) {
|
||||
|
||||
if (file_exists($target)) {
|
||||
throw new tool_installaddon_installer_exception('err_folder_already_exists', array('path' => $target));
|
||||
@ -405,7 +407,16 @@ class tool_installaddon_installer {
|
||||
throw new tool_installaddon_installer_exception('err_no_such_folder', array('path' => $source));
|
||||
}
|
||||
|
||||
make_writable_directory($target);
|
||||
if (!file_exists($target)) {
|
||||
// Do not use make_writable_directory() here - it is intended for dataroot only.
|
||||
mkdir($target, true);
|
||||
@chmod($target, $dirpermissions);
|
||||
}
|
||||
|
||||
if (!is_writable($target)) {
|
||||
closedir($handle);
|
||||
throw new tool_installaddon_installer_exception('err_folder_not_writable', array('path' => $target));
|
||||
}
|
||||
|
||||
while ($filename = readdir($handle)) {
|
||||
$sourcepath = $source.'/'.$filename;
|
||||
@ -416,10 +427,11 @@ class tool_installaddon_installer {
|
||||
}
|
||||
|
||||
if (is_dir($sourcepath)) {
|
||||
$this->move_directory($sourcepath, $targetpath);
|
||||
$this->move_directory($sourcepath, $targetpath, $dirpermissions, $filepermissions);
|
||||
|
||||
} else {
|
||||
rename($sourcepath, $targetpath);
|
||||
@chmod($targetpath, $filepermissions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,10 @@ if (file_exists($plugintypepath.'/'.$pluginname)) {
|
||||
get_string('invaliddata', 'core_error'));
|
||||
}
|
||||
|
||||
$installer->move_directory($zipcontentpath.'/'.$pluginname, $plugintypepath.'/'.$pluginname);
|
||||
// Copy permissions form the plugin type directory.
|
||||
$dirpermissions = fileperms($plugintypepath);
|
||||
$filepermissions = ($dirpermissions & 0666); // Strip execute flags.
|
||||
|
||||
$installer->move_directory($zipcontentpath.'/'.$pluginname, $plugintypepath.'/'.$pluginname, $dirpermissions, $filepermissions);
|
||||
fulldelete($CFG->tempdir.'/tool_installaddon/'.$jobid);
|
||||
redirect(new moodle_url('/admin'));
|
||||
|
@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2013 David Mudrak <david@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_installaddon_installer_test extends advanced_testcase {
|
||||
class tool_installaddon_installer_testcase extends advanced_testcase {
|
||||
|
||||
public function test_get_addons_repository_url() {
|
||||
$installer = testable_tool_installaddon_installer::instance();
|
||||
@ -137,7 +137,7 @@ class tool_installaddon_installer_test extends advanced_testcase {
|
||||
file_put_contents($contentsdir.'/readme.txt', 'Hello world!');
|
||||
|
||||
$installer = tool_installaddon_installer::instance();
|
||||
$installer->move_directory($jobroot.'/contents', $jobroot.'/moved');
|
||||
$installer->move_directory($jobroot.'/contents', $jobroot.'/moved', 0777, 0666);
|
||||
|
||||
$this->assertFalse(is_dir($jobroot.'/contents'));
|
||||
$this->assertTrue(is_file($jobroot.'/moved/sub/folder/readme.txt'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user