Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload-Action overwrites synchronized metadata unconditianally #56

Open
Louisonix opened this issue Nov 12, 2020 · 0 comments
Open

Upload-Action overwrites synchronized metadata unconditianally #56

Louisonix opened this issue Nov 12, 2020 · 0 comments

Comments

@Louisonix
Copy link

Louisonix commented Nov 12, 2020

Piwigo offers the possibility to synchronize image metadata (exif,iptc) into database fields. One can sync fields from iptc to database fields. It's enabled with the following config example:

// use_iptc: Use IPTC data during database synchronization with files
// metadata
$conf['use_iptc'] = true;

// use_iptc_mapping : in which IPTC fields will Piwigo find image
// information ? This setting is used during metadata synchronisation. It
// associates a piwigo_images column name to a IPTC key
$conf['use_iptc_mapping'] = array(
  'date_creation'   => '2#055',
  'author'          => '2#080',
  'name'            => '2#005',
  'comment'         => '2#120'
  );

When uploading images with the admin interface, this works fine.

With the community-upload plugin mechanism, these fields will end up empty, most of the time. Why? Because the the image-upload form offers 3 text inputs for "name", "author" and "description". These fields are written to the database, after the image was uploaded and saved, therefore it overwrites the values taken from the iptc fields.

The following patch only submits fields containing user input, so the metadata is only overwritten when the user enters text into these fields.

diff --git a/plugins/community/add_photos.tpl b/plugins/community/add_photos.tpl
index 0152d3b..d463fbb 100644
--- a/plugins/community/add_photos.tpl
+++ b/plugins/community/add_photos.tpl
@@ -290,16 +290,28 @@ var limit_storage = {$limit_storage};
         uploadedPhotos.push(parseInt(data.result.image_id));
         uploadCategory = data.result.category;
 
+        // Improved handling of settings override: 
+        var postParams = {
+            single_value_mode: "replace",
+            image_id: data.result.image_id
+        };
+
+        if(jQuery("input[name=author]").val().length > 0) {
+          postParams.author = jQuery("input[name=author]").val();
+        }
+
+        if(jQuery("input[name=name]").val().length > 0) {
+          postParams.name = jQuery("input[name=name]").val();
+        }
+
+        if(jQuery("textarea[name=description]").val().length > 0) {
+          postParams.comment = jQuery("textarea[name=description]").val();
+        }
+
         jQuery.ajax({
           url: rootUrl + "ws.php?format=json&method=pwg.images.setInfo",
           type:"POST",
-          data: {
-            single_value_mode: "replace",
-            image_id: data.result.image_id,
-            author: jQuery("input[name=author]").val(),
-            name: jQuery("input[name=name]").val(),
-            comment: jQuery("textarea[name=description]").val(),
-          },
+          data: postParams,
           dataType: "json",
           success:function(data) {
             console.log(data);
-- 
2.10.5


@Louisonix Louisonix changed the title Upload-Action overwrites synchronized Metadata unconditianally Upload-Action overwrites synchronized metadata unconditianally Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant