@@ -161,23 +161,23 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
161161
162162 local lrPhoto = rendition .photo
163163 local remoteId = rendition .publishedPhotoId or " "
164-
164+
165165 -- Detect photo already published in this service (multi-album support)
166166 local existingPwImageId = nil
167167 if remoteId == " " then
168168 -- Method 1: Via custom metadata (photos published with plugin >= 20251224.16)
169169 local storedImageUrl = lrPhoto :getPropertyForPlugin (_PLUGIN , " pwImageURL" )
170170 local storedHost = lrPhoto :getPropertyForPlugin (_PLUGIN , " pwHostURL" )
171-
171+
172172 log :info (" DEBUG multi-album: remoteId vide, checking metadata..." )
173173 log :info (" DEBUG storedHost: " .. tostring (storedHost ))
174174 log :info (" DEBUG storedImageUrl: " .. tostring (storedImageUrl ))
175175 log :info (" DEBUG propertyTable.host: " .. tostring (propertyTable .host ))
176-
176+
177177 if storedHost == propertyTable .host and storedImageUrl then
178178 existingPwImageId = utils .extractPwImageIdFromUrl (storedImageUrl , propertyTable .host )
179179 end
180-
180+
181181 -- Method 2: Search in other collections of the service (fallback)
182182 if not existingPwImageId then
183183 log :info (" DEBUG multi-album: metadata vides, recherche cross-collection..." )
@@ -187,7 +187,7 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
187187 log :info (" DEBUG multi-album: trouvé via cross-collection, ID = " .. tostring (existingPwImageId ))
188188 end
189189 end
190-
190+
191191 -- Verify the image still exists on Piwigo
192192 if existingPwImageId then
193193 local checkStatus = PiwigoAPI .checkPhoto (propertyTable , existingPwImageId )
@@ -197,7 +197,7 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
197197 end
198198 end
199199 end
200-
200+
201201 -- Wait for next photo to render.
202202 local success , pathOrMessage = rendition :waitForRender ()
203203 -- Check for cancellation again after photo has been rendered.
@@ -212,12 +212,12 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
212212 -- upload to Piwigo
213213 callStatus = {}
214214 local filePath = pathOrMessage
215-
215+
216216 -- If photo already exists on Piwigo, associate instead of uploading
217217 if existingPwImageId then
218218 log :info (" Photo exists on Piwigo (ID " .. existingPwImageId .. " ), associating to album " .. albumId )
219219 callStatus = PiwigoAPI .associateImageToCategory (propertyTable , existingPwImageId , albumId )
220-
220+
221221 if callStatus .status then
222222 rendition :recordPublishedPhotoId (callStatus .remoteid )
223223 rendition :recordPublishedPhotoUrl (callStatus .remoteurl )
@@ -228,66 +228,68 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
228228 existingPwImageId = nil
229229 end
230230 end
231-
232- if not existingPwImageId then
233- -- Begin existing upload block (indent all upload code until end of if success)
234- local metaData = {}
235- -- build metadata structure
236- metaData = utils .getPhotoMetadata (propertyTable , lrPhoto )
237- metaData .Albumid = albumId
238- metaData .Remoteid = remoteId
239- -- run to build missingTags - tags that will be created on upload to Piwigo
240- -- will use this to decide whether to run build tagtable cache
241- -- means we don't have to rebuild after each uploaded photo
242- local tagIdList , missingTags = utils .tagsToIds (propertyTable .tagTable , metaData .tagString )
243-
244- -- do the upload
245- callStatus = PiwigoAPI .updateGallery (propertyTable , filePath , metaData )
246- -- check status and complete rendition
247- if callStatus .status then
248- rendition :recordPublishedPhotoId (callStatus .remoteid or " " )
249- rendition :recordPublishedPhotoUrl (callStatus .remoteurl or " " )
250- rendition :renditionIsDone (true )
251- -- set metadata for photo
252- local pluginData = {
253- pwHostURL = propertyTable .host ,
254- albumName = albumName ,
255- albumUrl = albumUrl ,
256- imageUrl = callStatus .remoteurl ,
257- pwUploadDate = os.date (" %Y-%m-%d" ),
258- pwUploadTime = os.date (" %H:%M:%S" ),
259- pwCommentSync = " "
260- }
261- if propertyTable .syncCommentsPublish then
262- -- set to allow comments to sync for this photo if flag set
263- pluginData .pwCommentSync = " YES"
264- end
265-
266- -- store / update custom metadata
267-
268231
269- PiwigoAPI .storeMetaData (catalog , lrPhoto , pluginData )
270-
271- -- photo was uploaded with keywords included, but existing keywords aren't replaced by this process,
272- -- so force a metadata update using pwg.images.setInfo with single_value_mode set to "replace" to force old metadata/keywords to be replaced
273- metaData .Remoteid = callStatus .remoteid
274- if missingTags then
275- -- refresh cached tag list as new tags have been created during updateGallery
276- rv , propertyTable .tagTable = PiwigoAPI .getTagList (propertyTable )
277- end
278- if not rv then
279- LrDialogs .message (" PiwigoAPI:updateMetadata - cannot get taglist from Piwigo" )
280- end
281- callStatus = PiwigoAPI .updateMetadata (propertyTable , lrPhoto , metaData )
282- if not callStatus .status then
283- LrDialogs .message (" Unable to set metadata for uploaded photo - " .. callStatus .statusMsg )
232+ if not existingPwImageId then
233+ -- Begin existing upload block (indent all upload code until end of if success)
234+ local metaData = {}
235+ -- build metadata structure
236+ metaData = utils .getPhotoMetadata (propertyTable , lrPhoto )
237+ metaData .Albumid = albumId
238+ metaData .Remoteid = remoteId
239+ -- run to build missingTags - tags that will be created on upload to Piwigo
240+ -- will use this to decide whether to run build tagtable cache
241+ -- means we don't have to rebuild after each uploaded photo
242+ local tagIdList , missingTags = utils .tagsToIds (propertyTable , metaData .tagString )
243+
244+ -- do the upload
245+ callStatus = PiwigoAPI .updateGallery (propertyTable , filePath , metaData )
246+ -- check status and complete rendition
247+ if callStatus .status then
248+ rendition :recordPublishedPhotoId (callStatus .remoteid or " " )
249+ rendition :recordPublishedPhotoUrl (callStatus .remoteurl or " " )
250+ rendition :renditionIsDone (true )
251+ -- set metadata for photo
252+ local pluginData = {
253+ pwHostURL = propertyTable .host ,
254+ albumName = albumName ,
255+ albumUrl = albumUrl ,
256+ imageUrl = callStatus .remoteurl ,
257+ pwUploadDate = os.date (" %Y-%m-%d" ),
258+ pwUploadTime = os.date (" %H:%M:%S" ),
259+ pwCommentSync = " "
260+ }
261+ if propertyTable .syncCommentsPublish then
262+ -- set to allow comments to sync for this photo if flag set
263+ pluginData .pwCommentSync = " YES"
264+ end
265+
266+ -- store / update custom metadata
267+
268+
269+ PiwigoAPI .storeMetaData (catalog , lrPhoto , pluginData )
270+
271+ -- photo was uploaded with keywords included, but existing keywords aren't replaced by this process,
272+ -- so force a metadata update using pwg.images.setInfo with single_value_mode set to "replace" to force old metadata/keywords to be replaced
273+ metaData .Remoteid = callStatus .remoteid
274+ if missingTags then
275+ -- refresh cached tag list as new tags have been created during updateGallery
276+ rv , propertyTable .tagTable = PiwigoAPI .getTagList (propertyTable )
277+ if not rv then
278+ LrDialogs .message (" PiwigoAPI:updateMetadata - cannot get taglist from Piwigo" )
279+ else
280+ utils .buildTagIndex (propertyTable )
281+ end
282+ end
283+ callStatus = PiwigoAPI .updateMetadata (propertyTable , lrPhoto , metaData )
284+ if not callStatus .status then
285+ LrDialogs .message (" Unable to set metadata for uploaded photo - " .. callStatus .statusMsg )
286+ end
287+ else
288+ rendition :uploadFailed (callStatus .message or " Upload failed" )
284289 end
285- else
286- rendition :uploadFailed (callStatus .message or " Upload failed" )
287- end
288290
289- -- When done with photo, delete temp file.
290- LrFileUtils .delete (pathOrMessage )
291+ -- When done with photo, delete temp file.
292+ LrFileUtils .delete (pathOrMessage )
291293 end -- end if not existingPwImageId
292294 else
293295 rendition :uploadFailed (pathOrMessage or " Render failed" )
@@ -422,19 +424,21 @@ function PublishTask.deletePhotosFromPublishedCollection(publishSettings, arrayO
422424 local thisLrPhoto = thisPhotoToUnpublish [1 ]
423425 local thispwImageID = thisPhotoToUnpublish [2 ]
424426 local thisPubPhoto = thisPhotoToUnpublish [3 ]
425-
427+
426428 -- Use dissociate instead of delete to preserve multi-album associations
427- log :info (" PublishTask.deletePhotosFromPublishedCollection - dissociating photo " .. thispwImageID .. " from category " .. pwCatID )
429+ log :info (" PublishTask.deletePhotosFromPublishedCollection - dissociating photo " ..
430+ thispwImageID .. " from category " .. pwCatID )
428431 callStatus = PiwigoAPI .dissociateImageFromCategory (publishSettings , thispwImageID , pwCatID )
429432 if callStatus .status then
430433 -- Only clear metadata if photo is no longer in any other published collection
431434 -- Check if photo exists in other collections of this service
432435 local publishService = publishedCollection :getService ()
433436 local stillPublished = utils .findExistingPwImageId (publishService , thisLrPhoto )
434-
437+
435438 if not stillPublished then
436439 -- Photo is no longer published anywhere, clear all metadata
437- log :info (" PublishTask.deletePhotosFromPublishedCollection - photo " .. thispwImageID .. " orphaned, clearing metadata" )
440+ log :info (" PublishTask.deletePhotosFromPublishedCollection - photo " ..
441+ thispwImageID .. " orphaned, clearing metadata" )
438442 catalog :withWriteAccessDo (" Updating " .. thisLrPhoto :getFormattedMetadata (" fileName" ),
439443 function ()
440444 thisLrPhoto :setPropertyForPlugin (_PLUGIN , " pwHostURL" , " " )
@@ -446,7 +450,8 @@ function PublishTask.deletePhotosFromPublishedCollection(publishSettings, arrayO
446450 thisLrPhoto :setPropertyForPlugin (_PLUGIN , " pwCommentSync" , " " )
447451 end )
448452 else
449- log :info (" PublishTask.deletePhotosFromPublishedCollection - photo " .. thispwImageID .. " still in other collections, keeping metadata" )
453+ log :info (" PublishTask.deletePhotosFromPublishedCollection - photo " ..
454+ thispwImageID .. " still in other collections, keeping metadata" )
450455 end
451456 thisPhotoToUnpublish [4 ] = true
452457 else
@@ -639,26 +644,26 @@ function PublishTask.imposeSortOrderOnPublishedCollection(publishSettings, info,
639644 -- It allows you to detect published photos that no longer meet the criteria and mark them for
640645 -- deletion.
641646 log :info (" PublishTask.imposeSortOrderOnPublishedCollection" )
642-
647+
643648 local validSequence = {}
644649 local publishedCollection = info .publishedCollection
645-
650+
646651 if not publishedCollection then
647652 return nil
648653 end
649-
654+
650655 -- Check if it is a smart collection
651656 if not publishedCollection :isSmartCollection () then
652657 return nil
653658 end
654-
659+
655660 -- Retrieve photos currently in the smart collection (according to criteria)
656661 local currentPhotos = publishedCollection :getPhotos ()
657662 local currentPhotoIds = {}
658663 for _ , photo in ipairs (currentPhotos ) do
659664 currentPhotoIds [photo .localIdentifier ] = true
660665 end
661-
666+
662667 -- Browse the remoteIds of published photos
663668 -- remoteIdSequence contains the remoteIds in the current order
664669 local publishedPhotos = publishedCollection :getPublishedPhotos ()
@@ -669,7 +674,7 @@ function PublishTask.imposeSortOrderOnPublishedCollection(publishSettings, info,
669674 remoteIdToPhoto [remoteId ] = pubPhoto
670675 end
671676 end
672-
677+
673678 -- Build the valid sequence: only photos that still meet the criteria
674679 for _ , remoteId in ipairs (remoteIdSequence ) do
675680 local pubPhoto = remoteIdToPhoto [remoteId ]
@@ -683,12 +688,12 @@ function PublishTask.imposeSortOrderOnPublishedCollection(publishSettings, info,
683688 -- its remoteId will not be in validSequence.
684689 end
685690 end
686-
687- log :info (" PublishTask.imposeSortOrderOnPublishedCollection - " ..
688- # remoteIdSequence .. " published, " ..
689- # validSequence .. " still match criteria, " ..
690- (# remoteIdSequence - # validSequence ) .. " to delete" )
691-
691+
692+ log :info (" PublishTask.imposeSortOrderOnPublishedCollection - " ..
693+ # remoteIdSequence .. " published, " ..
694+ # validSequence .. " still match criteria, " ..
695+ (# remoteIdSequence - # validSequence ) .. " to delete" )
696+
692697 return validSequence
693698end
694699
@@ -801,11 +806,11 @@ function PublishTask.viewForCollectionSettings(f, publishSettings, info)
801806 { title = " Percent" , value = " Percent" },
802807 }
803808 local metaDataOpts = {
804- { title = " All Metadata" , value = " All Metadata" },
805- { title = " Copyright only" , value = " Copyright Only" },
806- { title = " Copyright & Contact Info Only" , value = " Copyright & Contact Info Only" },
807- { title = " All Except Camera Raw Info" , value = " All Except Camera Raw Info" },
808- { title = " All Except Camera & Camera Raw Info" , value = " All Except Camera & Camera Raw Info" },
809+ { title = " All Metadata" , value = " All Metadata" },
810+ { title = " Copyright only" , value = " Copyright Only" },
811+ { title = " Copyright & Contact Info Only" , value = " Copyright & Contact Info Only" },
812+ { title = " All Except Camera Raw Info" , value = " All Except Camera Raw Info" },
813+ { title = " All Except Camera & Camera Raw Info" , value = " All Except Camera & Camera Raw Info" },
809814 }
810815
811816 local pwAlbumUI = f :group_box {
@@ -1093,11 +1098,11 @@ function PublishTask.viewForCollectionSetSettings(f, publishSettings, info)
10931098 { title = " Percent" , value = " Percent" },
10941099 }
10951100 local metaDataOpts = {
1096- { title = " All Metadata" , value = " All Metadata" },
1097- { title = " Copyright only" , value = " Copyright Only" },
1098- { title = " Copyright & Contact Info Only" , value = " Copyright & Contact Info Only" },
1099- { title = " All Except Camera Raw Info" , value = " All Except Camera Raw Info" },
1100- { title = " All Except Camera & Camera Raw Info" , value = " All Except Camera & Camera Raw Info" },
1101+ { title = " All Metadata" , value = " All Metadata" },
1102+ { title = " Copyright only" , value = " Copyright Only" },
1103+ { title = " Copyright & Contact Info Only" , value = " Copyright & Contact Info Only" },
1104+ { title = " All Except Camera Raw Info" , value = " All Except Camera Raw Info" },
1105+ { title = " All Except Camera & Camera Raw Info" , value = " All Except Camera & Camera Raw Info" },
11011106 }
11021107
11031108 local pwAlbumUI = f :group_box {
0 commit comments