@@ -926,11 +926,12 @@ end
926926-- *************************************************
927927function PiwigoAPI .createPublishCollection (catalog , publishService , propertyTable , name , remoteId , parentSet )
928928 -- create new publish collection or return existing
929- log : info ( " createPublishCollection - " .. name .. " , " .. remoteId )
929+
930930 local newColl
931931 catalog :withWriteAccessDo (" Create PublishedCollection " , function ()
932932 newColl = publishService :createPublishedCollection (name , parentSet , true )
933933 end )
934+
934935 -- add remoteids and urls to collection
935936 PiwigoAPI .setCollectionDets (newColl , catalog , propertyTable , name , remoteId , parentSet )
936937
@@ -950,7 +951,7 @@ function PiwigoAPI.validatePiwigoStructure(propertyTable)
950951 local rv , allCats
951952 local catalog = LrApplication .activeCatalog ()
952953 rv = PiwigoAPI .getPublishService (propertyTable )
953- if not rv then
954+ if not PiwigoAPI . getPublishService ( propertyTable ) then
954955 LrErrors .throwUserError (" Error in validatePiwigoStructure: Cannot find Piwigo publish service for host/user." )
955956 return false
956957 end
@@ -1294,7 +1295,7 @@ function PiwigoAPI.checkAdmin(propertyTable)
12941295 if not (propertyTable .Connected ) then
12951296 rv = PiwigoAPI .login (propertyTable )
12961297 if not rv then
1297- callStatus .statusMsg = ' PiwigoAPI:updateMetadata - cannot connect to piwigo'
1298+ callStatus .statusMsg = ' PiwigoAPI.checkAdmin - cannot connect to piwigo'
12981299 return callStatus
12991300 end
13001301 end
@@ -1756,6 +1757,7 @@ end
17561757
17571758-- *************************************************
17581759function PiwigoAPI .checkPhoto (propertyTable , pwImageID )
1760+ log :info (" PiwigoAPI.checkPhoto - checking for photo with id " .. pwImageID )
17591761 -- check if image with this id exists on Piwigo
17601762 -- pwg.images.getInfo
17611763 local rtnStatus = {}
@@ -1800,10 +1802,19 @@ function PiwigoAPI.updateGallery(propertyTable, exportFilename, metaData)
18001802 local params = {
18011803 { name = " method" , value = " pwg.images.addSimple" },
18021804 { name = " category" , value = metaData .Albumid },
1803- { name = " author" , value = metaData .Creator },
1804- { name = " name" , value = metaData .Title },
1805- { name = " comment" , value = metaData .Caption }
18061805 }
1806+ if metaData .Title and metaData .Title ~= " " then
1807+ table.insert (params ,
1808+ { name = " name" , value = metaData .Title })
1809+ end
1810+ if metaData .Creator and metaData .Creator ~= " " then
1811+ table.insert (params ,
1812+ { name = " author" , value = metaData .Creator })
1813+ end
1814+ if metaData .Caption and metaData .Caption ~= " " then
1815+ table.insert (params ,
1816+ { name = " comment" , value = metaData .Caption })
1817+ end
18071818 -- keywords
18081819 if metaData .tagString and metaData .tagString ~= " " then
18091820 table.insert (params ,
@@ -1935,29 +1946,53 @@ function PiwigoAPI.updateMetadata(propertyTable, lrPhoto, metaData)
19351946 return callStatus
19361947 end
19371948 if metaData .Remoteid ~= " " then
1938- log : info ( " PiwigoAPI.updateMetadata - checking for existing photo with remoteid " .. metaData . Remoteid )
1949+
19391950 local rtnStatus = PiwigoAPI .checkPhoto (propertyTable , metaData .Remoteid )
19401951 if not rtnStatus .status then
1952+ log :info (" PiwigoAPI.updateMetadata - checking for existing photo with remoteid " .. metaData .Remoteid )
19411953 callStatus .statusMsg = " PiwigoAPI.updateMetadata - cannot locate image " ..
19421954 metaData .Remoteid .. " on Piwigo - cannot update metadata"
19431955 return callStatus
19441956 end
19451957 else
1958+ log :info (" PiwigoAPI.updateMetadata - checking for existing photo with remoteid " .. metaData .Remoteid )
19461959 callStatus .statusMsg = " PiwigoAPI.updateMetadata - missing Piwigo image ID - cannot update metadata"
19471960 return callStatus
19481961 end
19491962
1950- local params = {
1963+ -- sanity check metadata
1964+ metaData .Creator = metaData .Creator or " "
1965+ metaData .Title = metaData .Title or " "
1966+ metaData .Caption = metaData .Caption or " "
1967+ metaData .dateCreated = metaData .dateCreated or " "
1968+ metaData .tagString = metaData .tagString or " "
1969+ -- parameters for POST
1970+
1971+ local params = {
19511972 { name = " method" , value = " pwg.images.setInfo" },
19521973 { name = " image_id" , value = tostring (metaData .Remoteid ) },
1953- { name = " author" , value = metaData .Creator },
1954- { name = " name" , value = metaData .Title },
1955- { name = " comment" , value = metaData .Caption },
1956- { name = " date_creation" , value = metaData .dateCreated },
19571974 { name = " single_value_mode" , value = " replace" }, -- force metadata to be replaced rather than appended
19581975 { name = " multiple_value_mode" , value = " replace" }, -- force tags to be replaced rather than appended
19591976 { name = " pwg_token" , value = propertyTable .token }
19601977 }
1978+
1979+ if metaData .Title and metaData .Title ~= " " then
1980+ table.insert (params ,
1981+ { name = " name" , value = metaData .Title })
1982+ end
1983+ if metaData .Creator and metaData .Creator ~= " " then
1984+ table.insert (params ,
1985+ { name = " author" , value = metaData .Creator })
1986+ end
1987+ if metaData .dateCreated and metaData .dateCreated ~= " " then
1988+ table.insert (params ,
1989+ { name = " date_creation" , value = metaData .dateCreated })
1990+ end
1991+ if metaData .Caption and metaData .Caption ~= " " then
1992+ table.insert (params ,
1993+ { name = " comment" , value = metaData .Caption })
1994+ end
1995+
19611996 -- keywords
19621997 if metaData .tagString and metaData .tagString ~= " " then
19631998 -- convert tagString to list of tagIDS
@@ -1985,7 +2020,7 @@ function PiwigoAPI.updateMetadata(propertyTable, lrPhoto, metaData)
19852020 end
19862021 end
19872022
1988- -- now update Piwigo
2023+ -- now update Piwigo
19892024 local postResponse = PiwigoAPI .httpPostMultiPart (propertyTable , params )
19902025 if not postResponse .status then
19912026 callStatus .statusMsg = " Unable to set metadata - " .. postResponse .statusMsg
@@ -2096,8 +2131,10 @@ function PiwigoAPI.specialCollections(propertyTable)
20962131 local remoteId = thisSet :getRemoteId ()
20972132 local name = thisSet :getName ()
20982133 local scName = PiwigoAPI .buildSpecialCollectionName (name )
2134+ log :info (" Processing collection set " ..
2135+ thisSet :getName () .. " , " .. scName .. " , remoteId " .. tostring (remoteId ))
20992136 local scColl = PiwigoAPI .createPublishCollection (catalog , publishService , propertyTable , scName , remoteId ,
2100- thisSet )
2137+ thisSet )
21012138 if scColl == nil then
21022139 LrDialogs .message (" Failed to create special collection for " .. name , " " , " warning" )
21032140 end
@@ -2326,16 +2363,14 @@ function PiwigoAPI.httpPostMultiPart(propertyTable, params)
23262363 -- LrHttp.postMultipart( url, content, headers, timeout, callbackFn, suppressFormData )
23272364 local postResponse = {}
23282365 local postHeaders = {}
2329- log : info ( " PiwigoAPI.httpPostMultiPart - params \n " .. utils . serialiseVar ( params ))
2366+
23302367 local httpResponse , httpHeaders = LrHttp .postMultipart (
23312368 propertyTable .pwurl ,
23322369 params ,
23332370 {
23342371 headers = { field = " Cookie" , value = propertyTable .cookies }
23352372 }
23362373 )
2337- log :info (" PiwigoAPI.httpPostMultiPart - httpResponse \n " .. utils .serialiseVar (httpResponse ))
2338- log :info (" PiwigoAPI.httpPostMultiPart - httpHeaders \n " .. utils .serialiseVar (httpHeaders ))
23392374
23402375 local body
23412376 if httpResponse then
@@ -2346,6 +2381,9 @@ function PiwigoAPI.httpPostMultiPart(propertyTable, params)
23462381 postHeaders .statusDesc = (httpHeaders and (httpHeaders .statusDes or httpHeaders .statusDesc )) or " "
23472382 end
23482383 if not body then
2384+ log :info (" PiwigoAPI.httpPostMultiPart - params\n " .. utils .serialiseVar (params ))
2385+ log :info (" PiwigoAPI.httpPostMultiPart - httpResponse \n " .. utils .serialiseVar (httpResponse ))
2386+ log :info (" PiwigoAPI.httpPostMultiPart - httpHeaders \n " .. utils .serialiseVar (httpHeaders ))
23492387 postResponse .status = false
23502388 postResponse .statusMsg = postHeaders .status .. " - " .. postHeaders .statusDesc
23512389 return postResponse
@@ -2355,10 +2393,16 @@ function PiwigoAPI.httpPostMultiPart(propertyTable, params)
23552393 postResponse .status = true
23562394 postResponse .statusMsg = " "
23572395 else
2396+ log :info (" PiwigoAPI.httpPostMultiPart - params\n " .. utils .serialiseVar (params ))
2397+ log :info (" PiwigoAPI.httpPostMultiPart - httpResponse \n " .. utils .serialiseVar (httpResponse ))
2398+ log :info (" PiwigoAPI.httpPostMultiPart - httpHeaders \n " .. utils .serialiseVar (httpHeaders ))
23582399 postResponse .status = false
23592400 postResponse .statusMsg = body .message or " "
23602401 end
23612402 else
2403+ log :info (" PiwigoAPI.httpPostMultiPart - params\n " .. utils .serialiseVar (params ))
2404+ log :info (" PiwigoAPI.httpPostMultiPart - httpResponse \n " .. utils .serialiseVar (httpResponse ))
2405+ log :info (" PiwigoAPI.httpPostMultiPart - httpHeaders \n " .. utils .serialiseVar (httpHeaders ))
23622406 postResponse .status = false
23632407 postResponse .statusMsg = body .message or " "
23642408 end
0 commit comments