MDL-42016 repository: Simplify API to sync external files

Too many functions, too different parameters, unnecessary DB queries.
All repositories developed for Moodle 2.3-2.5 will continue to work.

Also get rid of DB field files_reference.lifetime, it is not used by
anybody except repository itself.
MDL-42016 files: Properly synchronise internal references
MDL-42016 Implement new sync method in repositories