Skip to content

Commit 206d2c7

Browse files
committed
Fix #39 - ajout de la fonction imposeSortOrderOnPublishedCollection pour gérer l'ordre de tri des collections publiées
1 parent 67e0beb commit 206d2c7

2 files changed

Lines changed: 74 additions & 12 deletions

File tree

piwigoPublish.lrplugin/PublishServiceProvider.lua

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,21 @@ return {
5656
{ key = "mdDescription", default = "{{caption}}" },
5757
{ key = "syncAlbumDescriptions", default = false },
5858
{ key = "syncCommentsPublish", default = true },
59-
{ key = "syncCommentsPubOnly", default = false }
60-
59+
{ key = "syncCommentsPubOnly", default = false },
6160
},
62-
--[[
63-
metadataThatTriggersRepublish = {
64-
default = false,
65-
title = true,
66-
caption = true,
67-
keywords = true,
68-
gps = true,
69-
dateCreated = true,
70-
},
71-
]]
61+
62+
metadataThatTriggersRepublish = function(publishSettings, photoId, fieldName)
63+
-- This function is called by Lightroom to determine whether a metadata
64+
-- change should trigger republishing.
65+
local triggerFields = {
66+
title = true,
67+
caption = true,
68+
keywords = true,
69+
gps = true,
70+
dateCreated = true,
71+
}
72+
return triggerFields[fieldName] or false
73+
end,
7274
-- canExportToTemporaryLocation = true
7375
-- canExportToTemporaryLocation = true
7476
-- showSections = { 'fileNaming', 'fileSettings', etc... }
@@ -107,6 +109,7 @@ return {
107109
renamePublishedCollection = PublishTask.renamePublishedCollection,
108110
reparentPublishedCollection = PublishTask.reparentPublishedCollection,
109111
deletePublishedCollection = PublishTask.deletePublishedCollection,
112+
imposeSortOrderOnPublishedCollection = PublishTask.imposeSortOrderOnPublishedCollection,
110113
validatePublishedCollectionName = PublishTask.validatePublishedCollectionName,
111114

112115
-- view on Piwigo Options

piwigoPublish.lrplugin/PublishTask.lua

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,65 @@ function PublishTask.shouldDeletePhotosFromServiceOnDeleteFromCatalog(publishSet
632632
return nil -- Show builtin Lightroom dialog.
633633
end
634634

635+
-- ************************************************
636+
function PublishTask.imposeSortOrderOnPublishedCollection(publishSettings, info, remoteIdSequence)
637+
-- This callback is called by Lightroom for smart collections.
638+
-- It allows you to detect published photos that no longer meet the criteria and mark them for
639+
-- deletion.
640+
log:info("PublishTask.imposeSortOrderOnPublishedCollection")
641+
642+
local validSequence = {}
643+
local publishedCollection = info.publishedCollection
644+
645+
if not publishedCollection then
646+
return nil
647+
end
648+
649+
-- Check if it is a smart collection
650+
if not publishedCollection:isSmartCollection() then
651+
return nil
652+
end
653+
654+
-- Retrieve photos currently in the smart collection (according to criteria)
655+
local currentPhotos = publishedCollection:getPhotos()
656+
local currentPhotoIds = {}
657+
for _, photo in ipairs(currentPhotos) do
658+
currentPhotoIds[photo.localIdentifier] = true
659+
end
660+
661+
-- Browse the remoteIds of published photos
662+
-- remoteIdSequence contains the remoteIds in the current order
663+
local publishedPhotos = publishedCollection:getPublishedPhotos()
664+
local remoteIdToPhoto = {}
665+
for _, pubPhoto in ipairs(publishedPhotos) do
666+
local remoteId = pubPhoto:getRemoteId()
667+
if remoteId then
668+
remoteIdToPhoto[remoteId] = pubPhoto
669+
end
670+
end
671+
672+
-- Build the valid sequence: only photos that still meet the criteria
673+
for _, remoteId in ipairs(remoteIdSequence) do
674+
local pubPhoto = remoteIdToPhoto[remoteId]
675+
if pubPhoto then
676+
local lrPhoto = pubPhoto:getPhoto()
677+
if lrPhoto and currentPhotoIds[lrPhoto.localIdentifier] then
678+
-- The photo still meets the criteria, keep it.
679+
table.insert(validSequence, remoteId)
680+
end
681+
-- If the photo is no longer in currentPhotoIds, it will be marked for deletion because
682+
-- its remoteId will not be in validSequence.
683+
end
684+
end
685+
686+
log:info("PublishTask.imposeSortOrderOnPublishedCollection - " ..
687+
#remoteIdSequence .. " published, " ..
688+
#validSequence .. " still match criteria, " ..
689+
(#remoteIdSequence - #validSequence) .. " to delete")
690+
691+
return validSequence
692+
end
693+
635694
-- ************************************************
636695
function PublishTask.validatePublishedCollectionName(name)
637696
log:info("PublishTask.validatePublishedCollectionName")

0 commit comments

Comments
 (0)