[BUGFIX] Wrong category relations

The relations between DAM records and DAM categories is
"inverted" compared to the relation between FAL records and
system categories (inverted usage of uid_local and uid_foreign
fields). The task does not handle this correctly.

Furthermore the relation must be established with the file
metadata rather than with the file itself.