MDL-64658 files: Support constant to avoid file merging

... in file_save_draft_area_files
This commit is contained in:
Juan Leyva
2019-03-25 14:57:18 +01:00
parent 3271c39c74
commit e0695f8764
3 changed files with 84 additions and 0 deletions
+18
View File
@@ -29,6 +29,12 @@ defined('MOODLE_INTERNAL') || die();
*/
define('BYTESERVING_BOUNDARY', 's1k2o3d4a5k6s7');
/**
* Do not process file merging when working with draft area files.
*/
define('IGNORE_FILE_MERGE', -1);
/**
* Unlimited area size constant
*/
@@ -888,6 +894,7 @@ function file_remove_editor_orphaned_files($editor) {
*
* @category files
* @param int $draftitemid the id of the primary draft area.
* When set to -1 (probably, by a WebService) it won't process file merging, keeping the original state of the file area.
* @param int $usercontextid the user's context id.
* @param string $text some html content that needs to have files copied to the correct draft area.
* @param bool $forcehttps force https urls.
@@ -899,6 +906,11 @@ function file_merge_draft_areas($draftitemid, $usercontextid, $text, $forcehttps
return null;
}
// Do not merge files, leave it as it was.
if ($draftitemid === IGNORE_FILE_MERGE) {
return null;
}
$urls = extract_draft_file_urls_from_text($text, $forcehttps, $usercontextid, 'user', 'draft');
// No draft areas to rewrite.
@@ -1015,6 +1027,7 @@ function file_copy_file_to_file_area($file, $filename, $itemid) {
* @global stdClass $USER
* @param int $draftitemid the id of the draft area to use. Normally obtained
* from file_get_submitted_draft_itemid('elementname') or similar.
* When set to -1 (probably, by a WebService) it won't process file merging, keeping the original state of the file area.
* @param int $contextid This parameter and the next two identify the file area to save to.
* @param string $component
* @param string $filearea indentifies the file area.
@@ -1028,6 +1041,11 @@ function file_copy_file_to_file_area($file, $filename, $itemid) {
function file_save_draft_area_files($draftitemid, $contextid, $component, $filearea, $itemid, array $options=null, $text=null, $forcehttps=false) {
global $USER;
// Do not merge files, leave it as it was.
if ($draftitemid === IGNORE_FILE_MERGE) {
return null;
}
$usercontext = context_user::instance($USER->id);
$fs = get_file_storage();