[BUGIFX] Ensure that pid is not NULL

In some cases it may happen that the pid cannot be determined
while migrating DAM relations. In such a case, the migration of
those problematic records will fail because a NULL value for the
pid field will make the query fail.

In such cases, fall back to 0 for the pid.