Skip to content

Commit bfc6b35

Browse files
committed
Fix #24, plus create album bug introduced by 20260104.22
1 parent 3f38161 commit bfc6b35

6 files changed

Lines changed: 135 additions & 40 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Changelog
2+
## [20260105.23] - 2026-01-05
3+
### Fixed
4+
Fix #24 rename album does not update custom metadata. Also fix error that incorrect albumname was used for metadata with special collections
5+
Fix regression introduced by 20260104.22 causing crash when creating new album or album set
6+
27
## [20260104.22] - 2026-01-04
38
### Fixed
49
Changes to Category (album) visibility in Piwigo could cause duplicates to be created by plugin if a previously public album was changed to private in Piwigo and then a photo published to it. The plugin now effectively ignores public/private settings and can access all albums on the Piwigo host.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PiwigoPublish-lrc-plugin
22

3-
A Lightroom Classic plugin which publishes images to a Piwigo host via the Piwigo REST API.
3+
A Lightroom Classic plugin which publishes images to a Piwigo host via the Piwigo API.
44

55
## The following fuctionality is available:
66

piwigoPublish.lrplugin/Info.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ return {
5959

6060
LrPluginInfoProvider = 'PluginInfo.lua',
6161

62-
VERSION = { major=20260104, minor=22, revision=0 },
62+
VERSION = { major=20260105, minor=23, revision=0 },
6363
}

piwigoPublish.lrplugin/Init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ end
7272

7373
_G.PiwigoBusy = false
7474
_G.iconPath = _PLUGIN:resourceId("icons/icon_med.png")
75-
_G.pluginVersion = "20260104.22"
75+
_G.pluginVersion = "20260105.23"
7676
--_G.LocStrings = utils.loadStrings()
7777

piwigoPublish.lrplugin/PiwigoAPI.lua

Lines changed: 83 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,61 @@ function PiwigoAPI.storeMetaData(catalog, propertyTable, lrPhoto, pluginData)
10401040
propertyTable.publishedPhotoMap[pluginData.pwImageID] = lrPhoto.localIdentifier
10411041
end
10421042

1043+
-- *************************************************
1044+
function PiwigoAPI.updateMetaDataforCollection(propertyTable, pubCollection, metaData)
1045+
-- function to update metadata on all photos in a published collection
1046+
log:info("PiwigoAPI.updateMetaDataforCollection - collection " .. pubCollection:getName())
1047+
local catalog = LrApplication.activeCatalog()
1048+
local pubphotos = pubCollection:getPublishedPhotos()
1049+
local catId = pubCollection:getRemoteId()
1050+
local albumName = metaData.name or ""
1051+
1052+
1053+
for _, pubPhoto in ipairs(pubphotos) do
1054+
local lrPhoto = pubPhoto:getPhoto()
1055+
local pwImageID = pubPhoto:getRemoteId()
1056+
local photoRemoteId = pubPhoto:getRemoteId()
1057+
local mdRemoteUrl = lrPhoto:getPropertyForPlugin(_PLUGIN, "pwImageURL") or ""
1058+
local checkUrl = string.format("%s/picture.php?/%s/category/%s", propertyTable.host, photoRemoteId,
1059+
tostring(catId))
1060+
1061+
if mdRemoteUrl == checkUrl then
1062+
-- photo metadata is from this collection - update metadata fields
1063+
-- update metadata fields in lrPhoto
1064+
catalog:withWriteAccessDo("Updating " .. lrPhoto:getFormattedMetadata("fileName"),
1065+
function()
1066+
lrPhoto:setPropertyForPlugin(_PLUGIN, "pwAlbumName", albumName)
1067+
end)
1068+
end
1069+
end
1070+
end
1071+
1072+
-- *************************************************
1073+
function PiwigoAPI.updateMetaDataforCollectionSet(propertyTable, pubCollectionSet, metaData)
1074+
-- function to update metadata on all photos in a published collection
1075+
log:info("PiwigoAPI.updateMetaDataforCollectionSet - collection " .. pubCollectionSet:getName())
1076+
local catalog = LrApplication.activeCatalog()
1077+
local collSetName = pubCollectionSet:getName()
1078+
local remoteId = pubCollectionSet:getRemoteId()
1079+
local scCollSetName = PiwigoAPI.buildSpecialCollectionName(metaData.name or "")
1080+
-- look for special collection in children of this set
1081+
if pubCollectionSet:getChildCollections() == nil then
1082+
-- no child collections so nothing to do
1083+
return
1084+
end
1085+
1086+
for _, childColl in ipairs(pubCollectionSet:getChildCollections()) do
1087+
local thisName = childColl:getName()
1088+
if string.sub(thisName, 1, 1) == "[" and string.sub(thisName, -1) == "]" then
1089+
-- found special collection - update metadata for photos in this collection
1090+
log:info("PiwigoAPI.updateMetaDataforCollectionSet - renaming special collection " .. thisName ..
1091+
" to " .. scCollSetName)
1092+
PiwigoAPI.setCollectionDets(childColl, catalog, propertyTable, scCollSetName, remoteId, pubCollectionSet)
1093+
PiwigoAPI.updateMetaDataforCollection(propertyTable, childColl, metaData)
1094+
end
1095+
end
1096+
end
1097+
10431098
-- *************************************************
10441099
function PiwigoAPI.getPublishServicesForPlugin(pluginID)
10451100
-- Helper to get all publish service connections for this plugin
@@ -1145,20 +1200,19 @@ function PiwigoAPI.pwConnect(propertyTable)
11451200
{ field = "Content-Type", value = "application/x-www-form-urlencoded" },
11461201
{ field = "Accept-Encoding", value = "identity" },
11471202
}
1148-
log:info("PiwigoAPI.pwConnect - connecting to " .. propertyTable.pwurl)
1149-
log:info("PiwigoAPI.pwConnect - body:\n" .. utils.serialiseVar(body))
11501203

11511204
local httpResponse, httpHeaders = LrHttp.post(propertyTable.pwurl, body, headers)
11521205

1153-
log:info("PiwigoAPI.pwConnect - response headers:\n" .. utils.serialiseVar(httpHeaders))
1154-
log:info("PiwigoAPI.pwConnect - response body:\n" .. tostring(httpResponse))
1155-
11561206
if (httpHeaders.status == 201) or (httpHeaders.status == 200) then
11571207
-- successful connection to Piwigo
11581208
-- Now check login result
11591209
-- Decode JSON safely
11601210
local ok, rtnBody = pcall(JSON.decode, JSON, httpResponse)
11611211
if not ok or type(rtnBody) ~= "table" then
1212+
log:info("PiwigoAPI.pwConnect - connecting to " .. propertyTable.pwurl)
1213+
log:info("PiwigoAPI.pwConnect - body:\n" .. utils.serialiseVar(body))
1214+
log:info("PiwigoAPI.pwConnect - response headers:\n" .. utils.serialiseVar(httpHeaders))
1215+
log:info("PiwigoAPI.pwConnect - response body:\n" .. tostring(httpResponse))
11621216
LrDialogs.message(
11631217
"Cannot log in to Piwigo",
11641218
"Invalid or unreadable server response"
@@ -1196,6 +1250,10 @@ function PiwigoAPI.pwConnect(propertyTable)
11961250
return false
11971251
end
11981252
else
1253+
log:info("PiwigoAPI.pwConnect - connecting to " .. propertyTable.pwurl)
1254+
log:info("PiwigoAPI.pwConnect - body:\n" .. utils.serialiseVar(body))
1255+
log:info("PiwigoAPI.pwConnect - response headers:\n" .. utils.serialiseVar(httpHeaders))
1256+
log:info("PiwigoAPI.pwConnect - response body:\n" .. tostring(httpResponse))
11991257
local statusCode, statusDesc
12001258
status = httpHeaders and httpHeaders.status
12011259
if httpHeaders and httpHeaders.error then
@@ -1329,7 +1387,7 @@ end
13291387

13301388
-- *************************************************
13311389
function PiwigoAPI.pwCategoriesGetThis(propertyTable, thisCat)
1332-
log:info("PiwigoAPI.pwCategoriesGetThis - propertyTable\n" .. utils.serialiseVar(propertyTable))
1390+
log:info("PiwigoAPI.pwCategoriesGetThis")
13331391
local rv
13341392

13351393
-- check connection to piwigo
@@ -1377,13 +1435,11 @@ end
13771435
function PiwigoAPI.pwCategoriesGet(propertyTable, thisCat)
13781436
-- get list of categories from Piwigo
13791437
-- if thisCat is set then return this category and children, otherwise all categories
1380-
1438+
log:info("PiwigoAPI.pwCategoriesGet")
13811439
local Params = {
1382-
--{ name = "method", value = "pwg.categories.getList" },
13831440
{ name = "method", value = "pwg.categories.getAdminList" },
13841441
{ name = "recursive", value = "true" },
1385-
--{ name = "tree", value = "false" },
1386-
--{ name = "fullname", value = "false" }
1442+
13871443
}
13881444

13891445
if not (utils.nilOrEmpty(thisCat)) then
@@ -1506,9 +1562,15 @@ function PiwigoAPI.pwCategoriesAdd(propertyTable, info, metaData, callStatus)
15061562
return callStatus
15071563
end
15081564

1565+
local name = metaData.name or ""
1566+
local description = metaData.description or ""
1567+
local albumstatus = metaData.status or "public"
1568+
15091569
local Params = {
15101570
{ name = "method", value = "pwg.categories.add" },
1511-
{ name = "name", value = metaData.name },
1571+
{ name = "name", value = name },
1572+
{ name = "comment", value = description },
1573+
{ name = "status", value = albumstatus },
15121574
{ name = "pwg_token", value = propertyTable.token }
15131575
}
15141576
if metaData.parentCat ~= "" then
@@ -1621,6 +1683,8 @@ end
16211683
-- *************************************************
16221684
function PiwigoAPI.pwCategoriesSetinfo(propertyTable, info, metaData)
16231685
-- Set info on category - change name etc
1686+
1687+
log:info("PiwigoAPI.pwCategoriesSetinfo")
16241688
local callStatus = {}
16251689
callStatus.status = false
16261690
callStatus.statusMsg = ""
@@ -1643,8 +1707,8 @@ function PiwigoAPI.pwCategoriesSetinfo(propertyTable, info, metaData)
16431707
end
16441708

16451709
local remoteId = metaData.remoteId
1646-
local name = metaData.name
1647-
local description = metaData.description
1710+
local name = metaData.name or ""
1711+
local description = metaData.description or ""
16481712
local status = metaData.status or "public"
16491713

16501714
local params = {
@@ -1655,7 +1719,6 @@ function PiwigoAPI.pwCategoriesSetinfo(propertyTable, info, metaData)
16551719
{ name = "status", value = status },
16561720
{ name = "pwg_token", value = propertyTable.token }
16571721
}
1658-
log:info("PiwigoAPI.pwCategoriesSetinfo - params \n" .. utils.serialiseVar(params))
16591722

16601723
local httpResponse, httpHeaders = LrHttp.postMultipart(
16611724
propertyTable.pwurl,
@@ -1665,9 +1728,6 @@ function PiwigoAPI.pwCategoriesSetinfo(propertyTable, info, metaData)
16651728
}
16661729
)
16671730

1668-
log:info("PiwigoAPI.pwCategoriesSetinfo - httpHeaders\n" .. utils.serialiseVar(httpHeaders))
1669-
log:info("PiwigoAPI.pwCategoriesSetinfo - httpResponse\n" .. utils.serialiseVar(httpResponse))
1670-
16711731
local body
16721732
if httpResponse then
16731733
body = JSON:decode(httpResponse)
@@ -1677,10 +1737,16 @@ function PiwigoAPI.pwCategoriesSetinfo(propertyTable, info, metaData)
16771737
callStatus.status = true
16781738
callStatus.statusMsg = ""
16791739
else
1740+
log:info("PiwigoAPI.pwCategoriesSetinfo - params \n" .. utils.serialiseVar(params))
1741+
log:info("PiwigoAPI.pwCategoriesSetinfo - httpHeaders\n" .. utils.serialiseVar(httpHeaders))
1742+
log:info("PiwigoAPI.pwCategoriesSetinfo - httpResponse\n" .. utils.serialiseVar(httpResponse))
16801743
callStatus.status = false
16811744
callStatus.statusMsg = "Category " .. tostring(remoteId) .. " - " .. (body.message or "")
16821745
end
16831746
else
1747+
log:info("PiwigoAPI.pwCategoriesSetinfo - params \n" .. utils.serialiseVar(params))
1748+
log:info("PiwigoAPI.pwCategoriesSetinfo - httpHeaders\n" .. utils.serialiseVar(httpHeaders))
1749+
log:info("PiwigoAPI.pwCategoriesSetinfo - httpResponse\n" .. utils.serialiseVar(httpResponse))
16841750
callStatus.status = false
16851751
callStatus.statusMsg = "Category " .. tostring(remoteId) .. " - " .. (body.message or "")
16861752
end

piwigoPublish.lrplugin/PublishTask.lua

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,23 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
5454

5555
log:info('PublishTask.processRenderedPhotos - publishSettings:\n' .. utils.serialiseVar(propertyTable))
5656

57-
--[[
58-
local publishCollection = exportContext.publishCollection
59-
local publishCollectionProps = publishCollection:getPropertyTable()
60-
log:info('PublishTask.processRenderedPhotos - publishCollectionProps:\n' .. utils.serialiseVar(publishCollectionProps))
61-
]]
62-
6357
local publishedCollection = exportContext.publishedCollection
6458
local collectionInfo = publishedCollection:getCollectionInfoSummary()
6559
local collectionSettings = collectionInfo.collectionSettings
6660
-- log:info('PublishTask.processRenderedPhotos - collectionInfo:\n' .. utils.serialiseVar(collectionInfo))
61+
local parentCollSet = publishedCollection:getParent()
62+
local parentID = ""
6763
local albumName = publishedCollection:getName()
64+
-- check if album is special collection and and use name of parent album if so
65+
if string.sub(albumName, 1, 1) == "[" and string.sub(albumName, -1) == "]" then
66+
if parentCollSet then
67+
albumName = parentCollSet:getName()
68+
end
69+
end
6870
local albumId = publishedCollection:getRemoteId()
6971
local albumUrl = publishedCollection:getRemoteUrl()
70-
local parentCollSet = publishedCollection:getParent()
71-
local parentID = ""
72+
73+
7274
local requestRepub = false
7375
if parentCollSet then
7476
parentID = parentCollSet:getRemoteId()
@@ -106,7 +108,6 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
106108
end
107109

108110
local resetConnectioncount = 0
109-
110111
local renditionParams = {
111112
stopIfCanceled = true,
112113
}
@@ -161,10 +162,10 @@ function PublishTask.processRenderedPhotos(functionContext, exportContext)
161162

162163
metaData.fileName = lrPhoto:getFormattedMetadata("fileName") or ""
163164
local lrTime = lrPhoto:getRawMetadata("dateTimeOriginal")
164-
metaData.dateCreated = LrDate.timeToUserFormat(lrTime, "%Y-%m-%d %H:%M:%S")
165+
metaData.dateCreated = (LrDate.timeToUserFormat(lrTime, "%Y-%m-%d %H:%M:%S")) or ""
165166
metaData.Remoteid = remoteId
166167

167-
metaData.tagString = utils.BuildTagString(propertyTable, lrPhoto)
168+
metaData.tagString = utils.BuildTagString(propertyTable, lrPhoto) or ""
168169
-- run to build missingTags - tags that will be created on upload to Piwigo
169170
-- will use this to decide whether to run build tagtable cache
170171
-- means we don't have to rebuild after each uploaded photo
@@ -278,7 +279,7 @@ function PublishTask.deletePhotosFromPublishedCollection(publishSettings, arrayO
278279

279280
-- set up async prococess for piwigo calls
280281
LrTasks.startAsyncTask(function()
281-
-- now go through each photo in photosToUnpublish and renove from Piwigo
282+
-- now go through each photo in photosToUnpublish and remove from Piwigo
282283
for i, thisPhotoToUnpublish in pairs(photosToUnpublish) do
283284
local thisLrPhoto = thisPhotoToUnpublish[1]
284285
local thispwImageID = thisPhotoToUnpublish[2]
@@ -423,7 +424,7 @@ end
423424
function PublishTask.viewForCollectionSettings(f, publishSettings, info)
424425
log:info("PublishTask.viewForCollectionSettings")
425426

426-
local thisName = info.name
427+
local thisName = info.name or ""
427428
if string.sub(thisName, 1, 1) == "[" and string.sub(thisName, -1) == "]" then
428429
LrDialogs.message(
429430
"Edit Piwigo Album",
@@ -858,15 +859,15 @@ function PublishTask.updateCollectionSetSettings(publishSettings, info)
858859
local metaData = {}
859860
metaData.name = name
860861
metaData.remoteId = remoteId
861-
metaData.description = collectionSettings.albumDescription
862+
863+
metaData.description = collectionSettings.albumDescription or ""
862864
if collectionSettings.albumPrivate then
863865
metaData.status = "private"
864866
else
865867
metaData.status = "public"
866868
end
867-
-- update albumdesc if album exists and set
868-
869869

870+
-- update albumdesc if album exists and set
870871
metaData.name = CollectionName
871872
metaData.type = "collectionset"
872873
metaData.description = collectionSettings.albumDescription
@@ -958,6 +959,7 @@ end
958959

959960
-- ************************************************
960961
function PublishTask.renamePublishedCollection(publishSettings, info)
962+
log:info("PublishTask.renamePublishedCollection")
961963
local callStatus = {}
962964
callStatus.status = false
963965
-- called for both collections and collectionsets
@@ -966,13 +968,18 @@ function PublishTask.renamePublishedCollection(publishSettings, info)
966968
local newName = info.name
967969
local collection = info.publishedCollection
968970
local oldName = collection:getName()
969-
971+
local collectionSettings = nil
972+
if collection:type() == "LrPublishedCollectionSet" then
973+
collectionSettings = collection:getCollectionSetInfoSummary()
974+
else
975+
collectionSettings = collection:getCollectionInfoSummary()
976+
end
970977
local metaData = {}
971978
metaData.name = newName
972979
metaData.remoteId = remoteId
973980
metaData.oldName = oldName
974-
metaData.description = info.collectionSettings.albumDescription or ""
975-
if info.collectionSettings.albumPrivate then
981+
metaData.description = collectionSettings.albumDescription or ""
982+
if collectionSettings.albumPrivate then
976983
metaData.status = "private"
977984
else
978985
metaData.status = "public"
@@ -991,7 +998,24 @@ function PublishTask.renamePublishedCollection(publishSettings, info)
991998
end
992999
end
9931000
end
994-
if not (callStatus.status) then
1001+
if (callStatus.status) then
1002+
-- if this is Publishedcollection then need to update metadata in photos in this collection
1003+
-- address metadata changes if any
1004+
-- go through all published photos in this collection and update metadata
1005+
-- need to check that remoteUrl is same as metadata field as photo may be in multiple publish collections
1006+
-- check all published photos in this collection
1007+
log:info("PublishTask.renamePublishedCollection - updating photo metadata in renamed collection - collection is a " .. collection:type())
1008+
if collection:type() == "LrPublishedCollection" then
1009+
-- only PublishedCollections have photos
1010+
PiwigoAPI.updateMetaDataforCollection(publishSettings, collection, metaData)
1011+
end
1012+
-- if this is a publishedCollectionSet then need to check for special collection rename that and update photos in it
1013+
if collection:type() == "LrPublishedCollectionSet" then
1014+
-- check for special collection within collectionset and rename that, and check meta of photos in that collection
1015+
PiwigoAPI.updateMetaDataforCollectionSet(publishSettings, collection, metaData)
1016+
end
1017+
1018+
else
9951019
LrTasks.startAsyncTask(function()
9961020
LrFunctionContext.callWithContext("revertRename", function(context)
9971021
local cat = LrApplication.activeCatalog()

0 commit comments

Comments
 (0)