Correctly process situation when file reference source is missing

Details

1. Backup resource with references to Private files
2. Remove the source in Private files
3. Restore resource
4. Make sure that error is displayed to user who views resource and teacher is able to edit it

1. Backup resource with references to Private files
2. Remove the source in Private files
3. Restore resource
4. Make sure that error is displayed to user who views resource and teacher is able to edit it
Test 2
5. create resource with references to box.net, dropbox, equella repositories
6. remove originals
7. make sure you can view/edit the resource

For internal repositories it happens at the moment when source is deleted between backup and restore (although it should not, there is an issue MDL-33430 for that).

Please note that in MDLQA-2500 I am actually asking for the expected behaviour. I heard today in HQ chat that all references are equal - regardless whether they link to an external repository (like box.net) or an internal one (like Private files). So the referenced files are not includes in MBZ. Right now, I do not know if it is a feature or a bug.

David Mudrak
added a comment - 08/Jun/12 10:07 PM For internal repositories it happens at the moment when source is deleted between backup and restore (although it should not, there is an issue MDL-33430 for that).
Please note that in MDLQA-2500 I am actually asking for the expected behaviour. I heard today in HQ chat that all references are equal - regardless whether they link to an external repository (like box.net) or an internal one (like Private files). So the referenced files are not includes in MBZ. Right now, I do not know if it is a feature or a bug.

Sorry David, not quite sure what you ask here.
This issue has nothing to do with backup. There are just places in code that assume that source always exists and die with fatal error if not.
There is also code that set file status to 666 if source is missing and never check it. Also when source appears again the status is not restored (for example somebody deleted file from dropbox and later realised mistake and uploaded it back)

Marina Glancy
added a comment - 11/Jun/12 9:40 AM Sorry David, not quite sure what you ask here.
This issue has nothing to do with backup. There are just places in code that assume that source always exists and die with fatal error if not.
There is also code that set file status to 666 if source is missing and never check it. Also when source appears again the status is not restored (for example somebody deleted file from dropbox and later realised mistake and uploaded it back)

Marina Glancy
added a comment - 13/Jun/12 12:15 PM MDL-33550 Correctly process situation when file reference source is missing
do not die with fatal error if source file in moodle internal repository is missing;
moved code duplication for moodle repositories into class repository (functions send_file, get_reference_details, get_file_by_reference, get_file_reference);
update file status after repository::sync_external_file so we know that it is missing (or not missing anymore). Do not run this function more than once for file within one request;
display readable name for Private Files and Server files with the new format;
display broken icon in filemanager if we know that source is missing, display information (for admin) where it was located before: see repository::get_reference_details() and extending classes;
removed unnecessary queries in stored_ file::sync_external_file( );
syncronize files before displaying it's size in mod_resource, do not query $DB directly

Dan Poltawski
added a comment - 14/Jun/12 2:54 PM Just noting the above problem is occurring when all tests are running, but not a single test. Seems like a problem with the phpunit environment. Will alert Petr.

Dan Poltawski
added a comment - 14/Jun/12 4:29 PM Ok, i've integrated this now.
I think I would've I thrown an exception if file argument to sync_external_file() was empty/ not a stored file and not reseting.

Marina, while testing this I can't get the error you are talking about in the testing instructions. I used a File resource with 3 files in it, 2 of them being link to Private files content. (Haven't tested the repositories yet). Where is the error message supposed to happen? Do I have to use a specific resource/file type to reproduce it?

Frédéric Massart
added a comment - 15/Jun/12 10:53 AM Marina, while testing this I can't get the error you are talking about in the testing instructions. I used a File resource with 3 files in it, 2 of them being link to Private files content. (Haven't tested the repositories yet). Where is the error message supposed to happen? Do I have to use a specific resource/file type to reproduce it?
Cheers!

Andrew Davis
added a comment - 15/Jun/12 11:43 AM Fred, did you remove the file(s) from your private files before doing the restore?
What happens if you click on the resource on the course page of the restored course?

Fred,
for example if you create a Folder resource and put a reference to pdf file in there
then you backup, remove source of a reference
then restore
then as a student you view the Folder resource, click on pdf file but see 'file can not be found' error

as a teacher you edit the Folder resource, click on file and see error message as "original"

Marina Glancy
added a comment - 15/Jun/12 12:00 PM Fred,
for example if you create a Folder resource and put a reference to pdf file in there
then you backup, remove source of a reference
then restore
then as a student you view the Folder resource, click on pdf file but see 'file can not be found' error
as a teacher you edit the Folder resource, click on file and see error message as "original"

Frédéric Massart
added a comment - 15/Jun/12 1:10 PM Test passed on master.
I was using the File resource with a JPEG file which creates a display of the file, so the filenotfound error was not displayed.