Skip to content

Commit 46ac631

Browse files
committed
Add checks to ensure publish service is saved after changes and make ensure Check and Link Piwigo Structure is run after cloning
1 parent fb8a4de commit 46ac631

7 files changed

Lines changed: 96 additions & 41 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# macOS system files
55
.DS_Store
66

7+
#localResources
8+
localResources/
9+
710
# not used
811
piwigoPublish.lrplugin/icons/piwigoPublish_1_0-assets/
912
piwigoPublish.lrplugin/icons/piwigoPublish_1_5-assets/

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
## [20260207.31] - 2026-02-06
3+
### Fixed
4+
Problem with Clone Existing Publish Service - smart collections
25

36
## [20260206.30] - 2026-02-06
47
### Fixed

piwigoPublish.lrplugin/Info.lua

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

6767
LrPluginInfoProvider = 'PluginInfo.lua',
6868

69-
VERSION = { major=20260206, minor=30, revision=0 },
69+
VERSION = { major=20260207, minor=31, revision=0 },
7070
}

piwigoPublish.lrplugin/Init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ _G.iconPath = _PLUGIN:resourceId("icons/icon_med.png")
7979
-- _PLUGIN.VERSION is nil here for some reason, so hardcoding for now
8080
-- just need to ensure both places are updated together
8181

82-
_G.versionInfo = { major=20260206, minor=30, revision=0 }
82+
_G.versionInfo = { major=20260207, minor=31, revision=0 }
8383

8484
_G.pluginVersion = string.format("%d.%d", versionInfo.major, versionInfo.minor)
8585
-- Auto-update checker

piwigoPublish.lrplugin/PWImportService.lua

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,15 @@ local function populateCollections(stdColls, smartColls, publishService, propert
328328
processSmartCollectionQueue(smartColls, publishService, propertyTable, 1, progressScope, stats)
329329
else
330330
progressScope:done()
331-
LrDialogs.message("Clone completed", "Publish Service Clone Complete.", "info")
331+
if pwDetails.isPiwigo and pwDetails.isSameHost then
332+
LrDialogs.message("Clone completed", "Publish Service Clone Complete.", "info")
333+
else
334+
LrDialogs.message("Clone completed",
335+
"Clone Complete. Check and Link Piwigo Structure will now be run", "info")
336+
--LrTasks.startAsyncTask(function()
337+
PiwigoAPI.validatePiwigoStructure(propertyTable)
338+
--end)
339+
end
332340
end
333341
end
334342

@@ -644,10 +652,10 @@ local function importServicePrelim(propertyTable, thisService, impService)
644652
if numlrPhotos > numPubPhotos then
645653
stats.unpublishedSmartCollImages = stats.unpublishedSmartCollImages +
646654
(numlrPhotos - numPubPhotos)
655+
canClone = false
647656
end
648657
searchDesc = thisColl:getSearchDescription()
649658
stats.smartCollections = stats.smartCollections + 1
650-
canClone = false
651659
else
652660
local numlrPhotos = #thisColl:getPhotos()
653661
local numPubPhotos = #thisColl:getPublishedPhotos()
@@ -736,11 +744,11 @@ local function importServicePrelim(propertyTable, thisService, impService)
736744
else
737745
text2 =
738746
"The service being cloned is a Piwigo service but connected to a different Piwigo host."
739-
text3 = "Collections/Sets will be cloned but links to Piwigo albums and images will not"
747+
text3 = "Collections/Sets and images will be cloned but links to Piwigo will not"
740748
end
741749
else
742750
text2 = "The service being cloned is not a Piwigo service."
743-
text3 = "Collections/Sets will be cloned but no links to Piwigo albums or images will be made"
751+
text3 = "Collections/Sets and images will be cloned but no links to Piwigo albums or images will be made"
744752
end
745753
local f = LrView.osFactory()
746754
local c = f:column {
@@ -871,7 +879,6 @@ local function importServicePrelim(propertyTable, thisService, impService)
871879
actionVerb = "Clone",
872880
cancelVerb = "Cancel",
873881
})
874-
log:info("importServicePrelim - dialog is " .. utils.serialiseVar(dialog))
875882
if dialog == "ok" then
876883
local rv = importService(propertyTable, thisService, impService, indexById, pwDetails, stats)
877884
end

piwigoPublish.lrplugin/PiwigoAPI.lua

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ end
240240
-- *************************************************
241241
local function buildCatHierarchy(allCats)
242242
-- convert flat list of categories to hierarchical table with children tables
243-
log:info("buildCatHierarchy - allCats\n" .. utils.serialiseVar(allCats))
243+
-- log:info("buildCatHierarchy - allCats\n" .. utils.serialiseVar(allCats))
244244
-- 1. Create all nodes (no hierarchy yet)
245245
local nodes = {}
246246
local roots = {}
@@ -273,7 +273,7 @@ local function buildCatHierarchy(allCats)
273273
end
274274
end
275275
end
276-
log:info("buildCatHierarchy - hierarchy\n" .. utils.serialiseVar(roots))
276+
-- log:info("buildCatHierarchy - hierarchy\n" .. utils.serialiseVar(roots))
277277
return roots
278278
end
279279

@@ -1058,6 +1058,11 @@ function PiwigoAPI.ConnectionChange(propertyTable)
10581058
propertyTable.cookieHeader = nil
10591059
propertyTable.userStatus = ""
10601060
propertyTable.token = ""
1061+
1062+
if (propertyTable.savedHost ~= propertyTable.host) or (propertyTable.savedUsername ~= propertyTable.userName) then
1063+
propertyTable.unsavedConnectionChanges = true
1064+
end
1065+
10611066
end
10621067

10631068
-- *************************************************
@@ -1247,6 +1252,7 @@ function PiwigoAPI.login(propertyTable)
12471252
"Error: Piwigo server URL, username or password is empty.")
12481253
return false
12491254
end
1255+
-- set default connectionname if blank
12501256
if not (propertyTable.LR_publish_connectionName) or propertyTable.LR_publish_connectionName == "" then
12511257
propertyTable.LR_publish_connectionName = propertyTable.userName .. "@" .. propertyTable.host
12521258
end
@@ -1519,7 +1525,7 @@ function PiwigoAPI.importAlbums(propertyTable)
15191525
-- log:info("PiwigoAPI:importAlbums - allCats\n" .. utils.serialiseVar(allCats) )
15201526
-- hierarchical table of categories
15211527
local catHierarchy = buildCatHierarchy(allCats)
1522-
log:info("PiwigoAPI:importAlbums - catHierarchy\n" .. utils.serialiseVar(catHierarchy))
1528+
-- log:info("PiwigoAPI:importAlbums - catHierarchy\n" .. utils.serialiseVar(catHierarchy))
15231529

15241530
local statusData = {
15251531
existing = 0,
@@ -2026,11 +2032,12 @@ end
20262032
-- *************************************************
20272033
function PiwigoAPI.associateImageToCategory(propertyTable, imageId, categoryId)
20282034
-- Associates an existing Piwigo image to an additional category without re-uploading
2029-
log:info("PiwigoAPI.associateImageToCategory - imageId: " .. tostring(imageId) .. ", categoryId: " .. tostring(categoryId))
2030-
2035+
log:info("PiwigoAPI.associateImageToCategory - imageId: " ..
2036+
tostring(imageId) .. ", categoryId: " .. tostring(categoryId))
2037+
20312038
local callStatus = { status = false }
20322039
local rv
2033-
2040+
20342041
-- Check connection
20352042
if not propertyTable.Connected then
20362043
rv = PiwigoAPI.login(propertyTable)
@@ -2039,37 +2046,38 @@ function PiwigoAPI.associateImageToCategory(propertyTable, imageId, categoryId)
20392046
return callStatus
20402047
end
20412048
end
2042-
2049+
20432050
local params = {
2044-
{ name = "method", value = "pwg.images.setInfo" },
2045-
{ name = "image_id", value = tostring(imageId) },
2046-
{ name = "categories", value = tostring(categoryId) },
2051+
{ name = "method", value = "pwg.images.setInfo" },
2052+
{ name = "image_id", value = tostring(imageId) },
2053+
{ name = "categories", value = tostring(categoryId) },
20472054
{ name = "multiple_value_mode", value = "append" },
2048-
{ name = "pwg_token", value = propertyTable.token }
2055+
{ name = "pwg_token", value = propertyTable.token }
20492056
}
2050-
2057+
20512058
local postResponse = PiwigoAPI.httpPostMultiPart(propertyTable, params)
2052-
2059+
20532060
if postResponse.status then
20542061
callStatus.status = true
20552062
callStatus.remoteid = imageId
20562063
callStatus.remoteurl = string.format("%s/picture.php?/%s/category/%s", propertyTable.host, imageId, categoryId)
20572064
else
20582065
callStatus.statusMsg = postResponse.statusMsg or "Association failed"
20592066
end
2060-
2067+
20612068
return callStatus
20622069
end
20632070

20642071
-- *************************************************
20652072
function PiwigoAPI.dissociateImageFromCategory(propertyTable, imageId, categoryId)
20662073
-- Removes an image from a specific category WITHOUT deleting the image
20672074
-- Uses pwg.images.setInfo to update categories list (excluding the target category)
2068-
log:info("PiwigoAPI.dissociateImageFromCategory - imageId: " .. tostring(imageId) .. ", categoryId: " .. tostring(categoryId))
2069-
2075+
log:info("PiwigoAPI.dissociateImageFromCategory - imageId: " ..
2076+
tostring(imageId) .. ", categoryId: " .. tostring(categoryId))
2077+
20702078
local callStatus = { status = false }
20712079
local rv
2072-
2080+
20732081
-- Check connection
20742082
if not propertyTable.Connected then
20752083
rv = PiwigoAPI.login(propertyTable)
@@ -2078,58 +2086,58 @@ function PiwigoAPI.dissociateImageFromCategory(propertyTable, imageId, categoryI
20782086
return callStatus
20792087
end
20802088
end
2081-
2089+
20822090
-- First, get current categories for this image
20832091
local checkStatus = PiwigoAPI.checkPhoto(propertyTable, imageId)
20842092
if not checkStatus.status then
20852093
callStatus.statusMsg = "Cannot find image " .. tostring(imageId) .. " on Piwigo"
20862094
return callStatus
20872095
end
2088-
2096+
20892097
local imageDets = checkStatus.imageDets
20902098
local currentCategories = imageDets.categories or {}
2091-
2099+
20922100
log:info("PiwigoAPI.dissociateImageFromCategory - image currently in " .. #currentCategories .. " categories")
2093-
2101+
20942102
-- Build new categories list excluding the target category
20952103
local newCategoryIds = {}
20962104
for _, cat in ipairs(currentCategories) do
20972105
if tostring(cat.id) ~= tostring(categoryId) then
20982106
table.insert(newCategoryIds, tostring(cat.id))
20992107
end
21002108
end
2101-
2109+
21022110
log:info("PiwigoAPI.dissociateImageFromCategory - remaining categories: " .. #newCategoryIds)
2103-
2111+
21042112
-- If image would be orphaned (no remaining categories), delete it entirely
21052113
if #newCategoryIds == 0 then
21062114
log:info("PiwigoAPI.dissociateImageFromCategory - image would be orphaned, deleting entirely")
21072115
return PiwigoAPI.deletePhoto(propertyTable, categoryId, imageId, callStatus)
21082116
end
2109-
2117+
21102118
-- Update image with new categories list (replaces all associations)
21112119
local categoriesStr = table.concat(newCategoryIds, ";")
2112-
2120+
21132121
local params = {
2114-
{ name = "method", value = "pwg.images.setInfo" },
2115-
{ name = "image_id", value = tostring(imageId) },
2116-
{ name = "categories", value = categoriesStr },
2122+
{ name = "method", value = "pwg.images.setInfo" },
2123+
{ name = "image_id", value = tostring(imageId) },
2124+
{ name = "categories", value = categoriesStr },
21172125
{ name = "multiple_value_mode", value = "replace" },
2118-
{ name = "pwg_token", value = propertyTable.token }
2126+
{ name = "pwg_token", value = propertyTable.token }
21192127
}
2120-
2128+
21212129
log:info("PiwigoAPI.dissociateImageFromCategory - new categories string: " .. categoriesStr)
2122-
2130+
21232131
local postResponse = PiwigoAPI.httpPostMultiPart(propertyTable, params)
2124-
2132+
21252133
if postResponse.status then
21262134
callStatus.status = true
21272135
log:info("PiwigoAPI.dissociateImageFromCategory - success")
21282136
else
21292137
callStatus.statusMsg = postResponse.statusMsg or "Dissociation failed"
21302138
log:info("PiwigoAPI.dissociateImageFromCategory - failed: " .. callStatus.statusMsg)
21312139
end
2132-
2140+
21332141
return callStatus
21342142
end
21352143

piwigoPublish.lrplugin/PublishDialogSections.lua

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ function PublishDialogSections.startDialog(propertyTable)
3737
propertyTable.ConCheck = true
3838
propertyTable.ConStatus = "Not Connected"
3939
end
40-
40+
-- Store the last saved connection details
41+
propertyTable.savedHost = propertyTable.host or ""
42+
propertyTable.savedUsername = propertyTable.userName or ""
43+
propertyTable.unsavedConnectionChanges = false
4144
propertyTable:addObserver('host', PiwigoAPI.ConnectionChange)
4245
propertyTable:addObserver('userName', PiwigoAPI.ConnectionChange)
4346
propertyTable:addObserver('userPW', PiwigoAPI.ConnectionChange)
@@ -50,7 +53,14 @@ end
5053

5154
-- *************************************************
5255
function PublishDialogSections.endDialog(propertyTable, why)
56+
log:info('PublishDialogSections.endDialog')
5357

58+
if why == 'ok' then
59+
-- User clicked Save - update our saved values
60+
propertyTable.savedHost = propertyTable.host
61+
propertyTable.savedUsername = propertyTable.userName
62+
propertyTable.unsavedConnectionChanges = false
63+
end
5464
end
5565

5666
-- *************************************************
@@ -187,6 +197,12 @@ local function prefsDialog(f, propertyTable)
187197
enabled = bind('Connected', propertyTable),
188198
tooltip = "Click to fetch the current album structure from the Piwigo Host above. Only albums the user has permission to see will be included",
189199
action = function(button)
200+
if propertyTable.unsavedConnectionChanges then
201+
LrDialogs.message("Unsaved Connection Changes",
202+
"You have changed the connection details. Please click 'Save' to save the publish service.",
203+
"info")
204+
return
205+
end
190206
local result = LrDialogs.confirm("Import Piwigo Albums",
191207
"Are you sure you want to import the album structure from Piwigo?\nExisting collections will be unaffected.",
192208
"Import", "Cancel")
@@ -219,6 +235,12 @@ local function prefsDialog(f, propertyTable)
219235
--enabled = false, -- temporary disabled
220236
tooltip = "Check Piwigo album structure against local collection / set structure",
221237
action = function(button)
238+
if propertyTable.unsavedConnectionChanges then
239+
LrDialogs.message("Unsaved Connection Changes",
240+
"You have changed the connection details. Please click 'Save' to save the publish service.",
241+
"info")
242+
return
243+
end
222244
local result = LrDialogs.confirm("Check / link Piwigo Structure",
223245
"Are you sure you want to check / link Piwigo Structure?\nExisting collections will be unaffected.",
224246
"Check", "Cancel")
@@ -249,6 +271,12 @@ local function prefsDialog(f, propertyTable)
249271
--enabled = false, -- temporary disabled
250272
tooltip = "Clone existing publish service (collections/sets and links to Piwigo)",
251273
action = function(button)
274+
if propertyTable.unsavedConnectionChanges then
275+
LrDialogs.message("Unsaved Connection Changes",
276+
"You have changed the connection details. Please click 'Save' to save the publish service.",
277+
"info")
278+
return
279+
end
252280
LrTasks.startAsyncTask(function()
253281
PWImportService.selectService(propertyTable)
254282
end)
@@ -275,6 +303,12 @@ local function prefsDialog(f, propertyTable)
275303
--enabled = false, -- temporary disabled
276304
tooltip = "Create special publish collections for publish collection sets, allowing images to be published to Piwigo albums with sub-albums",
277305
action = function(button)
306+
if propertyTable.unsavedConnectionChanges then
307+
LrDialogs.message("Unsaved Connection Changes",
308+
"You have changed the connection details. Please click 'Save' to save the publish service.",
309+
"info")
310+
return
311+
end
278312
local result = LrDialogs.confirm("Create Special Collections",
279313
"Are you sure you want to create Special Collections?\nExisting collections may be updated and missing Piwigo albums will be created.",
280314
"Create", "Cancel")

0 commit comments

Comments
 (0)