Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Duplicate
-
2.8.5
-
None
-
None
-
MOODLE_28_STABLE
Description
I observed the following issue in Moodle 2.8.5:
If a new wiki page is created, files are added to attachment area and content is created using Atto before saving the page, the newly uploaded attachment files are deleted.
Steps to reproduce:
1. Create a new empty wiki page.
2. Go to "Files" tab and add new attachment files
3. Submit changes to files
4. Click on "Edit" tab without viewing the page before
5. Enter content using Atto
6. Submit edit page
7. The newly added attachments have been deleted!
As I have figured out so far, this problem arises in Atto's autosave function which also saves the draft files area. When trying to restore the saved data, Atto merges the saved draft area with the newly created one. However, all files that have been newly added are deleted.
I have observed the following scenario:
- When a new wiki page is created, Moodle initialises a new draft file area which contains all attachment files.
- Atto creates a new autosave record pointing to the newly created draft file area.
- When files are added, Moodle creates another draft file area and copies newly added files to attachment area.
- When returning to Atto, the autosave record is retrieved from DB. Atto tries to restore all saved content.
- The draft file area from the autosave record is merged with the other draft area.
- Newly added files are only in the destination area but not in the source area. => Moodle interprets data that is only in destination area as "to be deleted" and therefore deletes newly added files from draft area.
- After submitting the content created in Atto, Moodle merges the draft area with the attachments area. As the newly added files have already been deleted from draft area, these files only exist in the attachments area.
- Hence the new files are again considered as "to be deleted" and therefore are also deleted from attachments area.
I assume this is caused by function file_save_draft_area_files() from lib/filelib.php which interprets all files existing only in destination file area as "to be deleted". However, for merging two draft file areas, there should be a function that copies all files from source to destination except for all files that already exist in destination area.