@@ -182,7 +182,7 @@ static public function store_backup_file($backupid, $filepath) {
182
182
183
183
// Extract useful information to decide
184
184
$ 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
186
186
$ filename = $ sinfo ['filename ' ]->value ; // Backup filename
187
187
$ backupmode = $ dinfo [0 ]->mode ; // Backup mode backup::MODE_GENERAL/IMPORT/HUB
188
188
$ backuptype = $ dinfo [0 ]->type ; // Backup type backup::TYPE_1ACTIVITY/SECTION/COURSE
@@ -203,50 +203,57 @@ static public function store_backup_file($backupid, $filepath) {
203
203
}
204
204
205
205
// 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 ;
209
210
switch ($ backuptype ) {
210
211
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 ;
214
216
break ;
215
217
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 ;
219
222
break ;
220
223
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 ;
224
228
break ;
225
229
}
226
230
227
231
// Backups of type HUB (by definition never have user info)
228
232
// are sent to user's "user_tohub" file area. The upload process
229
233
// will be responsible for cleaning that filearea once finished
230
234
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 ;
234
239
}
235
240
236
- // Backups without user info or withe the anoymise functionality
241
+ // Backups without user info or with the anonymise functionality
237
242
// enabled are sent to user's "user_backup"
238
243
// file area. Maintenance of such area is responsibility of
239
244
// the user via corresponding file manager frontend
240
245
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 ;
244
250
}
245
251
246
252
// Let's send the file to file storage, everything already defined
247
253
$ fs = get_file_storage ();
248
254
$ fr = array (
249
255
'contextid ' => $ ctxid ,
256
+ 'component ' => $ component ,
250
257
'filearea ' => $ filearea ,
251
258
'itemid ' => $ itemid ,
252
259
'filepath ' => '/ ' ,
@@ -257,8 +264,8 @@ static public function store_backup_file($backupid, $filepath) {
257
264
// If file already exists, delete if before
258
265
// creating it again. This is BC behaviour - copy()
259
266
// 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 ' ]);
262
269
$ sf = $ fs ->get_file_by_hash ($ pathnamehash );
263
270
$ sf ->delete ();
264
271
}
0 commit comments