I'd like find_or_create_alternate() to update the alternate image if the
original image is updated. I've come up with a solution that I think is
okay - my limited testing has shown it to work.
I'd like to check if others think it is a sane solution - I've still got
a lot to learn about Bricolage, so there's a good chance that I've
missed something.
Description:
The solution requires that the alternate image element type (as
specified in the 'et_key_name' parameter) has an additional custom field:
Key name: original_md5
Widet type: Text Box
When find_or_create_alternate() is called, it checks for the existence
of the 'original_md5' field in the alternate image. If it is not found,
processing continues as it did previously.
If 'original_md5' is present:
When find_or_create_alternate() is first called, it generates an MD5
digest of the original image, and stores it in the 'original_md5' field
of the alternate image.
On calls to find_or_create_alternate() it checks the value stored in
'original_md5' against the actual MD5 of the original image.
If the values are different, the original image is deemed to have
changed. The existing alternate image is deleted and replaced with a
new alternate image. The new alternate image 'original_md5' field is
updated accordingly.
If the values are the same, the original image is deemed to be the same
as the alternate image. In this case, the alternate image is returned
unaltered.
Questions:
Does this method make sense?
---
Should it be activated by a configuration directive, or is the
'original_md5' field requirement sufficient?
--
I'm calling the following private methods to delete the alternate image:
$alt->_delete_instance;
$alt->_delete_media;
$alt->_delete_file;
Is there a better way to do this (without calling private methods)?
---
I've created a new public method:
Bric::Biz::Asset::Business::Media->get_md5()
It uses Digest::MD5 to generate a 32 character hex MD5 digest of the
media file. Is that okay? I thought it might be useful from within
templates for images and other media types.
Regards,
Mike
original image is updated. I've come up with a solution that I think is
okay - my limited testing has shown it to work.
I'd like to check if others think it is a sane solution - I've still got
a lot to learn about Bricolage, so there's a good chance that I've
missed something.
Description:
The solution requires that the alternate image element type (as
specified in the 'et_key_name' parameter) has an additional custom field:
Key name: original_md5
Widet type: Text Box
When find_or_create_alternate() is called, it checks for the existence
of the 'original_md5' field in the alternate image. If it is not found,
processing continues as it did previously.
If 'original_md5' is present:
When find_or_create_alternate() is first called, it generates an MD5
digest of the original image, and stores it in the 'original_md5' field
of the alternate image.
On calls to find_or_create_alternate() it checks the value stored in
'original_md5' against the actual MD5 of the original image.
If the values are different, the original image is deemed to have
changed. The existing alternate image is deleted and replaced with a
new alternate image. The new alternate image 'original_md5' field is
updated accordingly.
If the values are the same, the original image is deemed to be the same
as the alternate image. In this case, the alternate image is returned
unaltered.
Questions:
Does this method make sense?
---
Should it be activated by a configuration directive, or is the
'original_md5' field requirement sufficient?
--
I'm calling the following private methods to delete the alternate image:
$alt->_delete_instance;
$alt->_delete_media;
$alt->_delete_file;
Is there a better way to do this (without calling private methods)?
---
I've created a new public method:
Bric::Biz::Asset::Business::Media->get_md5()
It uses Digest::MD5 to generate a 32 character hex MD5 digest of the
media file. Is that okay? I thought it might be useful from within
templates for images and other media types.
Regards,
Mike