Skip to content

Commit 7ae11bc

Browse files
committed
Add option to enable a Publish Collection to be converted to a Publish Collection Set
1 parent e38a564 commit 7ae11bc

9 files changed

Lines changed: 230 additions & 27 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## [20251219.14] - 2025-12-19
3+
### Added
4+
- A new menu item has been added Library->Plug-in Extras->Piwigo Publisher->Convert selected Published Collection to Published Collection Set. This option enables a Publish Collection to be converted to a Publish Collection Set, enabling sub albums to be created under this album.
5+
26
## [20251218.13] - 2025-12-18
37
### Fixed
48
- Send Metadata to Piwigo for Selected Photos crashed when photos weren't selected from a Publish Service

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A Lightroom Classic plugin which publishes images to a Piwigo host via the Piwig
99
* Images are not downloaded from Piwigo as part of this, nor are existing images in LrC automatically added to the newly created Published Collections.
1010
* Images added to the Publish Service are published to the corresponding album on Piwigo. Metadata and keywords are transferred, respecting rules configured in the Publishing Manager for this service.
1111
* Special collections can be created which allow images to be published to Piwigo albums that also have sub-albums. See details in the notes on the relationship between Piwigo Albums and LrC Publish Services below.
12+
* The plugin allows a Publish Collection to be converted to a Publish Collection Set - a Special Collection is created for the new Publish Collection Set and any photos that were in the converted Publish Collection will be in this Special Collection. This enables sub albums to be created under an album that was initially created for photos only.
1213
* Set Piwigo album cover from an image in the Published Collection
1314
* Metadata and keywords are exported directly to Piwigo regardless of exif/iptc settings - as part of the publish process along with the photo, or separately via a menu on the Library -> Plug-in Extras menu - which sends the metadata without re-sending the photo.
1415
* the following fields are set :
@@ -52,7 +53,7 @@ The plugin provides a function to import an existing Piwigo album structure into
5253
- If a Piwigo album contains sub-albums, an equivalent Publish Collection Set is created in the LrC Publish Service.
5354
- If a Piwigo album contains only photographs (i.e. no sub-albums) or is empty then a Publish Collection is created in the LrC Publish Service.
5455
- Piwigo allows an album to contain both photographs and sub albums. LrC does not allow this - a Publish Collection Set can contain only further Publish Collection Sets, or Publish Collections, not both. Publish Collections can contain only photographs and not further Publish Collection Sets.
55-
- The workround for this constraint is the the creation of specical collections (an option in the Piwigo Publish Service Configuration Extras section of the Publishing Manager). This creates a specially named collection for each collection set, linked to the parent album in Piwigo. Any photos in these collections are published to the Piwigo parent album.
56+
- The workround for this constraint is the the creation of specical collections (an option in the Piwigo Publish Service Configuration Extras section of the Publishing Manager). This creates a 'Special Collection', named "[Photos in *CollectionSetName* ]" for each collection set, linked to the parent album in Piwigo. Any photos in these collections are published to the Piwigo parent album.
5657
- Piwigo allows albums with the same name to exist under the same parent. LrC does not allow this - albums with the same name can only exist if they are sub albums of different parents within the publish service.
5758
- The plugin allows the alteration of the Piwigo album structure:
5859
- New albums containing photographs can be created - right-click in Publish Service -> Create Piwigo Album... or Create Piwigo Album (Smart collection)...

piwigoPublish.lrplugin/Info.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ return {
4949
title = "Send Metadata to Piwigo for Selected Photos",
5050
file = "PWSendMetadata.lua",
5151
},
52+
{
53+
title = "Convert selected Published Collection to Published Collection Set",
54+
file = "PWCollToSet.lua",
55+
},
5256
},
5357

5458
LrPluginInfoProvider = 'PluginInfo.lua',
5559

56-
VERSION = { major=20251218, minor=13, revision=0 },
60+
VERSION = { major=20251219, minor=14, revision=0 },
5761
}

piwigoPublish.lrplugin/Init.lua

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

7373
_G.PiwigoBusy = false
7474
_G.iconPath = _PLUGIN:resourceId("icons/icon_med.png")
75-
_G.pluginVersion = "20251218.13"
75+
_G.pluginVersion = "20251219.14"
7676

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
--[[
2+
3+
PWCollToSet.lua
4+
5+
Copyright (C) 2024 Fiona Boston <fiona@fbphotography.uk>.
6+
7+
This file is part of PiwigoPublish
8+
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation; either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
]]
22+
23+
--*******************************************
24+
local function CollToSet()
25+
log:info("CollToSet")
26+
local callStatus = {}
27+
local catalog = LrApplication.activeCatalog()
28+
29+
local selPhotos = catalog:getTargetPhotos()
30+
local sources = catalog:getActiveSources()
31+
--[[
32+
if utils.nilOrEmpty(selPhotos) then
33+
LrDialogs.message("Please select photos to resend metadata","","warning")
34+
return false
35+
end
36+
]]
37+
-- is source a LrPublishedCollection or LrPublishedCollectionSet in selected published service
38+
local useService = nil
39+
local selectedCollection = nil
40+
local catId = nil
41+
local publishSettings = nil
42+
for s, source in pairs(sources) do
43+
if type(source) == "table" and source.type then
44+
local srcType = source:type()
45+
if srcType == "LrPublishedCollection" or srcType == "LrPublishedCollectionSet" then
46+
local thisService = source:getService()
47+
local thisSettings = thisService:getPublishSettings()
48+
-- is this publish service using this plugin?
49+
local thisPluginId = thisService:getPluginId()
50+
if thisPluginId == _PLUGIN.id then
51+
useService = thisService
52+
selectedCollection = source
53+
publishSettings = thisSettings
54+
break
55+
end
56+
end
57+
end
58+
end
59+
60+
if not selectedCollection then
61+
LrDialogs.message("CollToSet - Can't access collection object for this publish collection - check selection","","warning")
62+
return false
63+
end
64+
if selectedCollection:type() == "LrPublishedCollectionSet" then
65+
LrDialogs.message("CollToSet - You have selected a Published Collection Set - please select a Published Collection","","warning")
66+
return false
67+
end
68+
69+
if not useService then
70+
LrDialogs.message("Please select a Collection within a Piwigo Publisher service","","warning")
71+
return false
72+
end
73+
if not publishSettings then
74+
LrDialogs.message("CollToSet - Can't find publish settings for this publish collection","","warning")
75+
return false
76+
end
77+
local selCollName = selectedCollection:getName()
78+
local selColParent = selectedCollection:getParent()
79+
catId = selectedCollection:getRemoteId()
80+
local selColParentName = nil
81+
local checkSCName = ""
82+
-- check that selected collection is not already a special collection
83+
if selColParent then
84+
if selCollName == PiwigoAPI.buildSpecialCollectionName(selColParent:getName()) then
85+
LrDialogs.message("Special Collections cannot be converted to Collection Sets","","warning")
86+
return false
87+
end
88+
end
89+
90+
local result = LrDialogs.confirm("Covert Publish Collection to Set","Convert " ..selCollName .." to a Publish Collection Set?", "Ok","Cancel")
91+
if result ~= 'ok' then
92+
return false
93+
end
94+
95+
-- 1 - rename seleted collection to a special collection name
96+
local newName = PiwigoAPI.buildSpecialCollectionName(selCollName)
97+
local rv = PiwigoAPI.setCollectionDets(selectedCollection, catalog, publishSettings, newName, catId, selColParent)
98+
99+
-- 2 - Create new collection set
100+
-- Set parent and remote id same as selected collection parent
101+
local newCollSet = PiwigoAPI.createPublishCollectionSet(catalog, useService, publishSettings, selCollName, catId, selColParent)
102+
if not newCollSet then
103+
LrDialogs.message("CollToSet - Can't fcreate new collection set " .. selCollName,"","warning")
104+
return false
105+
end
106+
107+
-- 3 - Set parent of selected collection to the new collection set
108+
rv = PiwigoAPI.setCollectionDets(selectedCollection, catalog, publishSettings, newName, catId, newCollSet)
109+
110+
111+
end
112+
113+
LrTasks.startAsyncTask(CollToSet)

piwigoPublish.lrplugin/PWSendMetadata.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ local function SendMetadata()
4242
if type(source) == "table" and source.type then
4343
local srcType = source:type()
4444
if srcType == "LrPublishedCollection" or srcType == "LrPublishedCollectionSet" then
45-
log:info("Source " .. s .. " is " .. source:getName() )
4645
local thisService = source:getService()
4746
local thisSettings = thisService:getPublishSettings()
4847
-- is this publish service using this plugin?

piwigoPublish.lrplugin/PWSetAlbumCover.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ local function SetAlbumCover()
4141

4242
-- we now have a single photo.
4343
local selPhoto = selPhotos[1]
44-
log:info("Selected photo is " .. selPhoto.localIdentifier)
45-
46-
4744
-- is source a LrPublishedCollection or LrPublishedCollectionSet in selected published service
4845
local useService = nil
4946
local useSource = nil
@@ -53,7 +50,6 @@ local function SetAlbumCover()
5350
if type(source) == "table" and source.type then
5451
local srcType = source:type()
5552
if srcType == "LrPublishedCollection" or srcType == "LrPublishedCollectionSet" then
56-
log:info("Source " .. s .. " is " .. source:getName() )
5753
local thisService = source:getService()
5854
local thisSettings = thisService:getPublishSettings()
5955
-- is this publish service using this plugin?

piwigoPublish.lrplugin/PiwigoAPI.lua

Lines changed: 104 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -326,22 +326,9 @@ local function buildCategoryPath(cat, allCats)
326326

327327
return path
328328
end
329-
-- *************************************************
330-
local function createPublishCollection(catalog, publishService, propertyTable, name, remoteId, parentSet)
331-
-- create new collection or return existing
332-
log:info("createPublishCollection - " .. name .. ", " .. remoteId)
333-
local newColl
334-
catalog:withWriteAccessDo("Create PublishedCollection ", function()
335-
newColl = publishService:createPublishedCollection( name, parentSet, true )
336-
end)
337-
-- add remoteids and urls to collection
338-
catalog:withWriteAccessDo("Add Piwigo details to collection", function()
339-
newColl:setRemoteId( remoteId)
340-
newColl:setRemoteUrl( propertyTable.host .. "/index.php?/category/" .. remoteId )
341-
newColl:setName( name )
342-
end)
343-
return newColl
344-
end
329+
330+
331+
345332

346333

347334
-- *************************************************
@@ -453,6 +440,97 @@ end
453440
-- G L O B A L F U N C T I O N S
454441
-- *************************************************
455442

443+
-- *************************************************
444+
function PiwigoAPI.fixSpecialCollectionNames(catalog, publishService, propertyTable)
445+
-- fix extra space in specialCollectionNames
446+
-- get all collectionsets
447+
local collSets = {}
448+
collSets = utils.recursePubCollectionSets(publishService, collSets)
449+
450+
-- Now look for specialCollections for each collset
451+
for cs, collSet in pairs(collSets) do
452+
local childColls = collSet:getChildren()
453+
if childColls then
454+
local parentName = collSet:getName()
455+
for cc, childCol in pairs(childColls) do
456+
local ccName = childCol:getName()
457+
local remoteId = childCol:getRemoteId()
458+
if string.sub(ccName,1,11) == "[ Photos in" and string.sub(ccName,-2) == " ]" then
459+
-- special collection - fix name by removing space prior to ]
460+
local newName = PiwigoAPI.buildSpecialCollectionName(parentName)
461+
log:info("PiwigoAPI.fixSpecialCollectionNames - " .. ccName .. " fixed to " .. newName)
462+
catalog:withWriteAccessDo("Set Collection Name", function()
463+
childCol:setName( newName )
464+
end)
465+
end
466+
end
467+
end
468+
end
469+
end
470+
471+
-- *************************************************
472+
function PiwigoAPI.buildSpecialCollectionName(name)
473+
-- consistently build special collection name
474+
local scName = "[Photos in " .. name.. " ]"
475+
return scName
476+
end
477+
478+
479+
480+
-- *************************************************
481+
function PiwigoAPI.setCollectionDets(thisCollorSet, catalog, propertyTable, name, remoteId, parentSet)
482+
catalog:withWriteAccessDo("Add Piwigo details to collection", function()
483+
thisCollorSet:setRemoteId( remoteId )
484+
thisCollorSet:setRemoteUrl( propertyTable.host .. "/index.php?/category/" .. remoteId )
485+
thisCollorSet:setName( name )
486+
thisCollorSet:setParent( parentSet )
487+
end)
488+
return true
489+
end
490+
491+
-- *************************************************
492+
function PiwigoAPI.createPublishCollectionSet(catalog, publishService, propertyTable, name, remoteId, parentSet)
493+
494+
495+
--PiwigoAPI.createPublishCollectionSet(catalog, useService, publishSettings, selCollName, catId, selColParent)
496+
-- create new publish collection set or return existing
497+
log:info("createPublishCollectionSet - " .. name .. ", " .. remoteId)
498+
local newColl
499+
catalog:withWriteAccessDo("Create PublishedCollectionSet ", function()
500+
newColl = publishService:createPublishedCollectionSet( name, parentSet, true )
501+
end)
502+
-- add remoteids and urls to collection
503+
PiwigoAPI.setCollectionDets(newColl, catalog, propertyTable, name, remoteId, parentSet)
504+
--[[
505+
catalog:withWriteAccessDo("Add Piwigo details to collection", function()
506+
newColl:setRemoteId( remoteId)
507+
newColl:setRemoteUrl( propertyTable.host .. "/index.php?/category/" .. remoteId )
508+
newColl:setName( name )
509+
end)
510+
]]
511+
return newColl
512+
513+
end
514+
515+
-- *************************************************
516+
function PiwigoAPI.createPublishCollection(catalog, publishService, propertyTable, name, remoteId, parentSet)
517+
-- create new publish collection or return existing
518+
log:info("createPublishCollection - " .. name .. ", " .. remoteId)
519+
local newColl
520+
catalog:withWriteAccessDo("Create PublishedCollection ", function()
521+
newColl = publishService:createPublishedCollection( name, parentSet, true )
522+
end)
523+
-- add remoteids and urls to collection
524+
PiwigoAPI.setCollectionDets(newColl, catalog, propertyTable, name, remoteId, parentSet)
525+
--[[
526+
catalog:withWriteAccessDo("Add Piwigo details to collection", function()
527+
newColl:setRemoteId( remoteId)
528+
newColl:setRemoteUrl( propertyTable.host .. "/index.php?/category/" .. remoteId )
529+
newColl:setName( name )
530+
end)
531+
]]
532+
return newColl
533+
end
456534
-- *************************************************
457535
function PiwigoAPI.ConnectionChange(propertyTable)
458536
log:info('PublishDialogSections.ConnectionChange')
@@ -1341,14 +1419,21 @@ function PiwigoAPI.specialCollections(propertyTable)
13411419
caption = "Starting...",
13421420
functionContext = context,
13431421
}
1344-
1422+
--[[
1423+
-- check if scNameFix has been run and run it if not
1424+
if not(propertyTable.scNameFix) then
1425+
log:info("PiwigoAPI.specialCollections - running scNameFix")
1426+
rv = PiwigoAPI.fixSpecialCollectionNames(catalog, publishService, propertyTable)
1427+
propertyTable.scNameFix = true
1428+
end
1429+
]]
13451430
for s, thisSet in pairs(allSets) do
13461431
progressScope:setPortionComplete(s, #allSets)
13471432
progressScope:setCaption("Processing " .. s .. " of " .. #allSets .. " collction sets")
13481433
local remoteId = thisSet:getRemoteId()
13491434
local name = thisSet:getName()
1350-
local scName = "[Photos in " .. name .. " ]"
1351-
local scColl = createPublishCollection(catalog, publishService, propertyTable, scName, remoteId, thisSet)
1435+
local scName = PiwigoAPI.buildSpecialCollectionName(name)
1436+
local scColl = PiwigoAPI.createPublishCollection(catalog, publishService, propertyTable, scName, remoteId, thisSet)
13521437
if scColl == nil then
13531438
LrDialogs.message("Failed to create special collection for " .. name,"","warning")
13541439
end

piwigoPublish.lrplugin/PublishServiceProvider.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ return {
5252
{ key = "userPW", default = '' },
5353
{ key = "KwFullHierarchy", default = true},
5454
{ key = "KwSynonyms", default = true},
55+
--{ key = "scNameFix",default = false}
5556

5657
},
5758

0 commit comments

Comments
 (0)