Skip to content

Commit 64f9379

Browse files
committed
MDL-22950 adding new component column to the files table, unfortunately this change requires changes in all 2.0dev code, please review all custom code that was already upgraded to 2.0; fixing multiple problems and regressions in mod/assignment
1 parent ffc3f86 commit 64f9379

File tree

220 files changed

+4635
-4297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+4635
-4297
lines changed

admin/bloglevelupgrade.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,26 @@ function bloglevelupgrade_entries($blogentries, $forum, $cm, $groupid=-1) {
103103

104104
// Copy file attachment records
105105
$fs = get_file_storage();
106-
$files = $fs->get_area_files($sitecontext->id, 'blog_attachment', $blogentry->id);
106+
$files = $fs->get_area_files($sitecontext->id, 'blog', 'attachment', $blogentry->id);
107107

108108
if (!empty($files)) {
109109
foreach ($files as $storedfile) {
110110
$newfile = new object();
111-
$newfile->filearea = 'forum_attachment';
111+
$newfile->component = 'mod_forum';
112+
$newfile->filearea = 'attachment';
112113
$newfile->itemid = $discussion->firstpost;
113114
$newfile->contextid = $forumcontext->id;
114115
$fs->create_file_from_storedfile($newfile, $storedfile->get_id());
115116
}
116117
}
117118

118-
$files = $fs->get_area_files($sitecontext->id, 'blog_post', $blogentry->id);
119+
$files = $fs->get_area_files($sitecontext->id, 'blog', 'post', $blogentry->id);
119120

120121
if (!empty($files)) {
121122
foreach ($files as $storedfile) {
122123
$newfile = new object();
123-
$newfile->filearea = 'forum_post';
124+
$newfile->component = 'mod_forum';
125+
$newfile->filearea = 'post';
124126
$newfile->itemid = $discussion->firstpost;
125127
$newfile->contextid = $forumcontext->id;
126128
$fs->create_file_from_storedfile($newfile, $storedfile->get_id());

admin/settings/grades.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
// new CFG variable for gradebook (what roles to display)
2727
$temp->add(new admin_setting_special_gradebookroles());
2828

29-
// enable outcomes checkbox
30-
$temp->add(new admin_setting_configcheckbox('enableoutcomes', get_string('enableoutcomes', 'grades'), get_string('enableoutcomes_help', 'grades'), 0));
29+
// enable outcomes checkbox now in subsystems area
3130

3231
$temp->add(new admin_setting_grade_profilereport());
3332

backup/backup_execute.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
//Print final message
7777
echo $OUTPUT->box(get_string("backupfinished"));
7878
$context = get_context_instance(CONTEXT_COURSE, $course->id);
79-
echo $OUTPUT->continue_button("$CFG->wwwroot/files/index.php?contextid=".$context->id."&filearea=course_backup&itemid=0");
79+
echo $OUTPUT->continue_button("$CFG->wwwroot/files/index.php?contextid=".$context->id."&component=backup&filearea=course&itemid=0");
8080
} else {
8181
echo $OUTPUT->box(get_string('importdataexported'));
8282
if (!empty($preferences->backup_destination)) {

backup/backuplib.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2637,7 +2637,7 @@ function copy_zip_to_course_dir ($preferences) {
26372637
//Define zip destination (course dir)
26382638
$context = get_context_instance(CONTEXT_COURSE, $preferences->backup_course);
26392639
$fs = get_file_storage();
2640-
$file_record = array('contextid'=>$context->id, 'filearea'=>'course_backup',
2640+
$file_record = array('contextid'=>$context->id, 'component'=>'backup', 'filearea'=>'course',
26412641
'itemid'=>0, 'filepath'=>'/', 'filename'=>$preferences->backup_name,
26422642
'timecreated'=>time(), 'timemodified'=>time());
26432643
$fs->create_file_from_pathname($file_record, $from_zip_file);

backup/moodle2/backup_stepslib.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ protected function define_structure() {
232232
$section->set_source_alias('section', 'number');
233233

234234
// Set annotations
235-
$section->annotate_files(array('course_section'), 'id');
235+
$section->annotate_files('course', 'section', 'id');
236236

237237
return $section;
238238
}
@@ -311,7 +311,8 @@ protected function define_structure() {
311311

312312
$course->annotate_ids('grouping', 'defaultgroupingid');
313313

314-
$course->annotate_files(array('course_summary', 'course_content'), null);
314+
$course->annotate_files('course', 'summary', null);
315+
$course->annotate_files('course', 'legacy', null);
315316

316317
// Return root element ($course)
317318

@@ -656,8 +657,9 @@ protected function define_structure() {
656657

657658
// Define file annotations
658659

659-
// TODO: Change "course_group_image" file area to the one finally used for group images
660-
$group->annotate_files(array('course_group_description', 'course_group_image'), 'id');
660+
//TODO: not implemented yet
661+
$group->annotate_files('group', 'description', 'id');
662+
$group->annotate_files('group', 'image', 'id');
661663

662664
// Return the root element (groups)
663665
return $groups;
@@ -980,7 +982,7 @@ protected function define_structure() {
980982
$files = new backup_nested_element('files');
981983

982984
$file = new file_nested_element('file', array('id'), array(
983-
'contenthash', 'contextid', 'filearea', 'itemid',
985+
'contenthash', 'contextid', 'component', 'filearea', 'itemid',
984986
'filepath', 'filename', 'userid', 'filesize',
985987
'mimetype', 'status', 'timecreated', 'timemodified',
986988
'source', 'author', 'license', 'sortorder'));
@@ -1238,9 +1240,8 @@ protected function define_execution() {
12381240
global $DB;
12391241

12401242
// List of fileareas we are going to annotate
1241-
// TODO: Change "user_image" file area to the one finally used for user images
1242-
$fileareas = array(
1243-
'user_private', 'user_profile', 'user_image');
1243+
// TODO: user image not implemented yet
1244+
$fileareas = array('private', 'profile', 'image');
12441245

12451246
// Fetch all annotated (final) users
12461247
$rs = $DB->get_recordset('backup_ids_temp', array(
@@ -1252,7 +1253,7 @@ protected function define_execution() {
12521253
foreach ($fileareas as $filearea) {
12531254
// We don't need to specify itemid ($userid - 4th param) as far as by
12541255
// context we can get all the associated files. See MDL-22092
1255-
backup_structure_dbops::annotate_files($this->get_backupid(), $userctxid, $filearea, null);
1256+
backup_structure_dbops::annotate_files($this->get_backupid(), $userctxid, 'user', $filearea, null);
12561257
}
12571258
}
12581259
$rs->close();

backup/util/dbops/backup_structure_dbops.class.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,14 @@ public static function insert_backup_ids_record($backupid, $itemname, $itemid) {
103103
}
104104
}
105105

106-
public static function annotate_files($backupid, $contextid, $filearea, $itemid) {
106+
public static function annotate_files($backupid, $contextid, $component, $filearea, $itemid) {
107107
global $DB;
108108
$sql = 'SELECT id
109109
FROM {files}
110110
WHERE contextid = ?
111+
AND component = ?
111112
AND filearea = ?';
112-
$params = array($contextid, $filearea);
113+
$params = array($contextid, $component, $filearea);
113114

114115
if (!is_null($itemid)) { // Add itemid to query and params if necessary
115116
$sql .= ' AND itemid = ?';

backup/util/helper/backup_helper.class.php

+29-22
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static public function store_backup_file($backupid, $filepath) {
182182

183183
// Extract useful information to decide
184184
$hasusers = (bool)$sinfo['users']->value; // Backup has users
185-
$isannon = (bool)$sinfo['anonymize']->value; // Backup is annonymzed
185+
$isannon = (bool)$sinfo['anonymize']->value; // Backup is anonymised
186186
$filename = $sinfo['filename']->value; // Backup filename
187187
$backupmode= $dinfo[0]->mode; // Backup mode backup::MODE_GENERAL/IMPORT/HUB
188188
$backuptype= $dinfo[0]->type; // Backup type backup::TYPE_1ACTIVITY/SECTION/COURSE
@@ -203,50 +203,57 @@ static public function store_backup_file($backupid, $filepath) {
203203
}
204204

205205
// Calculate file storage options of id being backup
206-
$ctxid = 0;
207-
$filearea = '';
208-
$itemid = 0;
206+
$ctxid = 0;
207+
$filearea = '';
208+
$component = '';
209+
$itemid = 0;
209210
switch ($backuptype) {
210211
case backup::TYPE_1ACTIVITY:
211-
$ctxid = get_context_instance(CONTEXT_MODULE, $id)->id;
212-
$filearea = 'activity_backup';
213-
$itemid = 0;
212+
$ctxid = get_context_instance(CONTEXT_MODULE, $id)->id;
213+
$component = 'backup';
214+
$filearea = 'activity';
215+
$itemid = 0;
214216
break;
215217
case backup::TYPE_1SECTION:
216-
$ctxid = get_context_instance(CONTEXT_COURSE, $courseid)->id;
217-
$filearea = 'section_backup';
218-
$itemid = $id;
218+
$ctxid = get_context_instance(CONTEXT_COURSE, $courseid)->id;
219+
$component = 'backup';
220+
$filearea = 'section';
221+
$itemid = $id;
219222
break;
220223
case backup::TYPE_1COURSE:
221-
$ctxid = get_context_instance(CONTEXT_COURSE, $courseid)->id;
222-
$filearea = 'course_backup';
223-
$itemid = 0;
224+
$ctxid = get_context_instance(CONTEXT_COURSE, $courseid)->id;
225+
$component = 'backup';
226+
$filearea = 'course';
227+
$itemid = 0;
224228
break;
225229
}
226230

227231
// Backups of type HUB (by definition never have user info)
228232
// are sent to user's "user_tohub" file area. The upload process
229233
// will be responsible for cleaning that filearea once finished
230234
if ($backupmode == backup::MODE_HUB) {
231-
$ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
232-
$filearea = 'user_tohub';
233-
$itemid = 0;
235+
$ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
236+
$component = 'user';
237+
$filearea = 'tohub';
238+
$itemid = 0;
234239
}
235240

236-
// Backups without user info or withe the anoymise functionality
241+
// Backups without user info or with the anonymise functionality
237242
// enabled are sent to user's "user_backup"
238243
// file area. Maintenance of such area is responsibility of
239244
// the user via corresponding file manager frontend
240245
if ($backupmode == backup::MODE_GENERAL && (!$hasusers || $isannon)) {
241-
$ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
242-
$filearea = 'user_backup';
243-
$itemid = 0;
246+
$ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
247+
$component = 'user';
248+
$filearea = 'backup';
249+
$itemid = 0;
244250
}
245251

246252
// Let's send the file to file storage, everything already defined
247253
$fs = get_file_storage();
248254
$fr = array(
249255
'contextid' => $ctxid,
256+
'component' => $component,
250257
'filearea' => $filearea,
251258
'itemid' => $itemid,
252259
'filepath' => '/',
@@ -257,8 +264,8 @@ static public function store_backup_file($backupid, $filepath) {
257264
// If file already exists, delete if before
258265
// creating it again. This is BC behaviour - copy()
259266
// overwrites by default
260-
if ($fs->file_exists($fr['contextid'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename'])) {
261-
$pathnamehash = $fs->get_pathname_hash($fr['contextid'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename']);
267+
if ($fs->file_exists($fr['contextid'], $fr['component'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename'])) {
268+
$pathnamehash = $fs->get_pathname_hash($fr['contextid'], $fr['component'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename']);
262269
$sf = $fs->get_file_by_hash($pathnamehash);
263270
$sf->delete();
264271
}

backup/util/structure/backup_nested_element.class.php

+15-20
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class backup_nested_element extends base_nested_element implements processable {
3535
protected $params; // Unprocessed params as specified in the set_source() call
3636
protected $procparams;// Processed (path resolved) params array
3737
protected $aliases; // Define DB->final element aliases
38-
protected $fileannotelement; // Element to be used as itemid for file annotations
39-
protected $fileannotareas; // array of file areas to be searched by file annotations
38+
protected $fileannotations; // array of file areas to be searched by file annotations
4039
protected $counter; // Number of instances of this element that have been processed
4140

4241
/**
@@ -54,8 +53,7 @@ public function __construct($name, $attributes = null, $final_elements = null) {
5453
$this->params = null;
5554
$this->procparams= null;
5655
$this->aliases = array();
57-
$this->fileannotelement = null;
58-
$this->fileannotareas = array();
56+
$this->fileannotations = array();
5957
$this->counter = 0;
6058
}
6159

@@ -148,21 +146,21 @@ public function set_source_alias($dbname, $finalelementname) {
148146
}
149147
}
150148

151-
public function annotate_files($areas, $elementname) {
152-
if (!is_array($areas)) { // Check we are passing array
153-
throw new base_element_struct_exception('annotate_files_requires_array_of_areas', $areas);
154-
}
155-
$annotations = $this->get_file_annotations();
156-
if (!empty($annotations[0])) { // Check we haven't defined file annotations already
157-
throw new base_element_struct_exception('annotate_files_already_defined', $this->get_name());
149+
public function annotate_files($component, $filearea, $elementname) {
150+
// note: it is possible to annotate areas ONLY in current context, ie modules may backup only from module context
151+
if (!array_key_exists($component, $this->fileannotations)) {
152+
$this->fileannotations[$component] = array();
158153
}
154+
159155
if ($elementname !== null) { // Check elementname is valid
160-
$element = $this->find_element($elementname);
161-
// Annotate the element
162-
$this->fileannotelement= $element;
156+
$elementname = $this->find_element($elementname); //TODO: no warning here? (skodak)
157+
}
158+
159+
if (array_key_exists($filearea, $this->fileannotations[$component])) {
160+
throw new base_element_struct_exception('annotate_files_duplicate_annotation', "$component/$filearea/$elementname");
163161
}
164-
// Annotate the areas
165-
$this->fileannotareas = $areas;
162+
163+
$this->fileannotations[$component][$filearea] = $elementname;
166164
}
167165

168166
public function annotate_ids($itemname, $elementname) {
@@ -175,10 +173,7 @@ public function annotate_ids($itemname, $elementname) {
175173
* @backup_structure and the areas to be searched
176174
*/
177175
public function get_file_annotations() {
178-
if (empty($this->fileannotareas)) {
179-
return array(null, null);
180-
}
181-
return array($this->fileannotareas, $this->fileannotelement);
176+
return $this->fileannotations;
182177
}
183178

184179
public function get_source_array() {

backup/util/structure/backup_structure_processor.class.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ public function pre_process_nested_element(base_nested_element $nested) {
6767

6868
public function process_nested_element(base_nested_element $nested) {
6969
// Proceed with all the file annotations for this element
70-
list($fileareas, $element) = $nested->get_file_annotations();
71-
if ($fileareas) { // If there are areas to search
72-
$backupid = $this->get_var(backup::VAR_BACKUPID);
73-
$contextid= $this->get_var(backup::VAR_CONTEXTID);
74-
$itemid = !is_null($element) ? $element->get_value() : null;
75-
foreach ($fileareas as $filearea) {
76-
backup_structure_dbops::annotate_files($backupid, $contextid, $filearea, $itemid);
70+
$fileannotations = $nested->get_file_annotations();
71+
if ($fileannotations) { // If there are areas to search
72+
$backupid = $this->get_var(backup::VAR_BACKUPID);
73+
$contextid = $this->get_var(backup::VAR_CONTEXTID);
74+
foreach ($fileannotations as $component=>$area) {
75+
foreach ($area as $filearea=>$element) {
76+
$itemid = !is_null($element) ? $element->get_value() : null;
77+
backup_structure_dbops::annotate_files($backupid, $contextid, $component, $filearea, $itemid);
78+
}
7779
}
7880
}
7981
}

0 commit comments

Comments
 (0)