Get the new files ids when restoring a backup

Get the new files ids when restoring a backup

by Daniel VP -
Number of replies: 0

Hi all, 

I have been developing a new module based in the folder module. This module is roughly the same as the folder module but has one new table where we store metadata for each file, like a file's visibility or comments.

Also I modified the backup and restore scripts to save this new table into xml files. But I have some problems when restoring this table, I can't get the relation between the old ids of the files and the new ids generated when the files were imported. Due to this behaviour I can't update the file ids in the metadata table when restoring.

The metadata table has the following structure. Where file_id is the id of the files in the files table.

|  id |  file_id   | comment | visibility |
|  1  |  36766  |                   |       1       |
|  2  |  36767  |      Test     |        0       |

Looking at the table 'backup_ids_temp' when restoring I see that the 'fileref' items has an itemid, which is the id of the files before the import (The id in the backup files) but the 'newitemid' field is 0. Also reviewing the code in the 'backup/util/dbops/restore_dbops.class.php' in the function 'send_files_to_pool' when recreating the files I didn't see that these ids where stored anywhere.

As a test I modified this function to store the ids that are returned when creating a file or a folder in the 'newitemid' field and it seems to work.

Someone knows if Moodle can do this or if my approach is the correct one?

Thank you
Average of ratings: -