Merge branch 'MDL-59505-master-gdrive' of git://github.com/mudrd8mz/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2017-09-26 01:29:35 +02:00
commit c9d9acb289
2 changed files with 38 additions and 4 deletions

View File

@ -901,6 +901,8 @@ class repository_googledocs extends repository {
* @return string updated reference (final one before it's saved to db).
*/
public function reference_file_selected($reference, $context, $component, $filearea, $itemid) {
global $CFG, $SITE;
// What we need to do here is transfer ownership to the system user (or copy)
// then set the permissions so anyone with the share link can view,
// finally update the reference to contain the share link if it was not
@ -949,8 +951,23 @@ class repository_googledocs extends repository {
$fullpath = 'root';
$allfolders = [];
foreach ($contextlist as $context) {
// Make sure a folder exists here.
$foldername = clean_param($context->get_context_name(), PARAM_PATH);
// Prepare human readable context folders names, making sure they are still unique within the site.
$prevlang = force_current_language($CFG->lang);
$foldername = $context->get_context_name();
force_current_language($prevlang);
if ($context->contextlevel == CONTEXT_SYSTEM) {
// Append the site short name to the root folder.
$foldername .= ' ('.$SITE->shortname.')';
// Append the relevant object id.
} else if ($context->instanceid) {
$foldername .= ' (id '.$context->instanceid.')';
} else {
// This does not really happen but just in case.
$foldername .= ' (ctx '.$context->id.')';
}
$foldername = clean_param($foldername, PARAM_PATH);
$allfolders[] = $foldername;
}

View File

@ -848,6 +848,8 @@ class repository_onedrive extends repository {
* @return string $modifiedreference (final one before saving to DB)
*/
public function reference_file_selected($reference, $context, $component, $filearea, $itemid) {
global $CFG, $SITE;
// What we need to do here is transfer ownership to the system user (or copy)
// then set the permissions so anyone with the share link can view,
// finally update the reference to contain the share link if it was not
@ -897,8 +899,23 @@ class repository_onedrive extends repository {
$fullpath = '';
$allfolders = [];
foreach ($contextlist as $context) {
// Make sure a folder exists here.
$foldername = urlencode(clean_param($context->get_context_name(), PARAM_PATH));
// Prepare human readable context folders names, making sure they are still unique within the site.
$prevlang = force_current_language($CFG->lang);
$foldername = $context->get_context_name();
force_current_language($prevlang);
if ($context->contextlevel == CONTEXT_SYSTEM) {
// Append the site short name to the root folder.
$foldername .= '_'.$SITE->shortname;
// Append the relevant object id.
} else if ($context->instanceid) {
$foldername .= '_id_'.$context->instanceid;
} else {
// This does not really happen but just in case.
$foldername .= '_ctx_'.$context->id;
}
$foldername = urlencode(clean_param($foldername, PARAM_PATH));
$allfolders[] = $foldername;
}