I'm writing a plugin that moves photos between physical albums, preserving the metadata. I've got the basics working: when editing a photo (or video) that's already in a physical album, select the new Move tab, pick a target physical album, click Move:
The file on disk is moved from the source directory to the target and the IMAGES_TABLE and IMAGE_CATEGORY_TABLE tables are updated accordingly. This preserves all the tags, description, etc. etc.
What I'm trying to figure out now is how to manage the thumbnails, specifically:
- clean up the thumbnails left behind for the image's original location
- create thumbnails for the image's new location (I know the new thumbnails will be auto-generated when the photo is accessed for the first time, but ideally I'd create those as part of the move)
Poking around in the Piwigo functions (like the uploader), I found delete_element_derivatives. Would this handle the thumbnails (-cu, -me, -sq, -th, etc.)? If so, would it also handle the pwg_representatives (i.e., thumbnails for videos created by videojs)?
Any suggestions on how to properly handle this or the creation of the new thumbnails?
Right now the plugin only works on a single photo but I'd like to eventually add it to Batch Manager as well ... maybe version 2.0. :)
Thanks!
Piwigo version: 2.9.0
PHP version: 7.0.18-0ubuntu0.17.04.1
MySQL version: 5.7.18-0ubuntu0.17.04.1
Last edited by windracer (2017-06-07 22:15:46)
Offline
Hello
delete_element_derivatives is removing only the generated resized pictures (-cu, -me, -sq, -th, etc.) by default all
for the representative, you could move it with the original object (representative_ext original_to_representative( $path, $infos['representative_ext']) ) ; you could also move the derivative since the tree is the same as the physical one, and avoid the issue of recreating it
Offline
great plugin, if you make it work with batch manager i will use it
Offline
flop25 wrote:
Hello
delete_element_derivatives is removing only the generated resized pictures (-cu, -me, -sq, -th, etc.) by default all
Thanks for the confirmation. I'll use that to remove the thumbnails/resizes from the source directory.
flop25 wrote:
for the representative, you could move it with the original object (representative_ext original_to_representative( $path, $infos['representative_ext']) ) ; you could also move the derivative since the tree is the same as the physical one, and avoid the issue of recreating it
Ok, I'll look into this. Thanks for the tips! Sounds like I'm on the right path.
Offline
I've got the representative handling working. Had to do a little more than I originally thought because the pwg_representative folder might not exist yet in the destination so I have to create it. And then I also wanted to remove the pwg_representative folder from the source if it was empty after the move.
Now on to the derivatives ...
Offline
Grrr ... just realized that representatives can also have derivatives. So in addition to the pwg_representative folder in the physical directory/album, there's also in the derivatives folder under /_data/i/...etc.
Offline
Ok, I think I've manage to cover all the bases. The plugin handles representatives (and their derivatives) and all other derivatives, so no orphans and no need to re-generate. I want to do some more testing and then I'll try and publish my first plugin!
Offline
Ok, first release!
http://piwigo.org/ext/extension_view.php?eid=859
Offline
Hi :-)
Can you add EN file for language support
Offline
Can you point me to instructions on how to do that? Everything is in English already.
Offline
Hi :-)
in main.inc.php add function to load language
add_event_handler('loading_lang', 'physical_photo_move_loading_lang'); function physical_photo_move_loading_lang(){ load_language('plugin.lang', PPM_PATH); }
add folder 'language'
in forder language add folder 'en_UK'
in forder en_UK add files
description.txt and plugin.lang.php
description.txt ->
Move a photo (the actual file) from one physical album to another, preserving all metadata.
plugin.lang.php ->
<?php $lang['Move Photo'] = 'Move Photo'; $lang['Current physical album:'] = 'Current physical album:'; $lang['Current file location:'] = 'Current file location:'; ........ ?>
Offline
Ok, seems straightforward enough. I already had the load_language in there, but no corresponding add_event or the language files, obviously.
So in plugin.lang.php, I should include a line for every @translate in my plugin, right?
Offline
Yes
Offline
Also, it looks like I should redo my @translate lines and use variable names to make the lines in plugin.inc.php shorter. In other words this:
$lang['CURR_PHYS_ALBUM'] = 'Current physical album:';
instead of this:
$lang['Current physical album:'] = 'Current physical album:';
And then I'd have to add an en_US language folder with these files too since that's my own default language. And I'm guessing if I didn't, I end up seeing 'CURR_PHYS_ALBUM' on the page instead of the en_US translation.
Thank you!
Offline
Absolutely
You're welcome
Offline