ezsystems/ezpublish-legacy — pull request #792 by bdunogier (2013-10-16 08:55:37+00:00)
Title: EZP-21324: Fixed missing references to copied image attributes

See http://jira.ez.no/browse/EZP-213234

This PR fixes a use-case where image files from content A might be deleted when content B is deleted.

## Use-case
- create a content A with an image attribute
- edit content A, but don't change the image.
- Version 1 references the file. An entry exists in ezimagefile.
- Version 2 will reference the same image than version 1. A (duplicate) entry exists in ezimagefile.
- copy content A to content B
- Version 1 references the *same* image than A version 1. There is no reference from this attribute to the image in ezimagefile
- Version 2 references a copy (actually a hard link, but it doesn't matter) of the image from A version 2. An entry exists in ezimagefile.

The consequence is that when B version 1 gets deleted (either manually, or because the version limit gets reached, or when B is deleted, the image used by A (both versions) will get deleted.

## Fix
The PR fixes:
- what is done when copying (by adding references to the image used in v1 to ezimagefile)
- what is done when deleting (usage of the image is checked for any attribute, using ezimagefile, since we have proper references)
- existing data, by providing an update script, [update/common/scripts/5.3/recreateimagesreferences.php](https://github.com/ezsystems/ezpublish-legacy/blob/fix/EZP-21324-copy_old_version_images/update/common/scripts/5.3/recreateimagesreferences.php)

## TODO
- [ ] Fix the delete code