@@ -1040,6 +1040,61 @@ function PiwigoAPI.storeMetaData(catalog, propertyTable, lrPhoto, pluginData)
10401040 propertyTable .publishedPhotoMap [pluginData .pwImageID ] = lrPhoto .localIdentifier
10411041end
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-- *************************************************
10441099function 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-- *************************************************
13311389function 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
13771435function 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-- *************************************************
16221684function 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
0 commit comments