@@ -248,17 +248,21 @@ local function populateCollections(stdColls, smartColls, publishService, propert
248248 local name = node .name
249249 local extra = node .extra or nil
250250 local oldPubPhotos
251+ local oldlrPhotos
252+ local publishedIds
251253 if extra then
252254 oldPubPhotos = extra .pubphotos or {}
255+ oldlrPhotos = extra .lrPhotos or {}
256+ publishedIds = extra .publishedIds or {}
253257 end
254258
255259 log :info (" processing collection " .. name .. " with " .. # oldPubPhotos .. " photos" )
256-
260+ local lrPhotosToAdd = {} -- photos to add without piwigo metadata
257261 if # oldPubPhotos > 0 then
258262 local albumUrl = collection :getRemoteUrl ()
259- local lrPhotosToAdd = {} -- photos to add without piwigo metadata
260263 for pp , pubPhoto in pairs (oldPubPhotos ) do
261264 local lrPhoto = pubPhoto :getPhoto ()
265+ local photoId = lrPhoto .localIdentifier
262266 if pwDetails .isPiwigo and pwDetails .isSameHost then
263267 -- this is the same Piwigo host then we can copy remote ids etc
264268 local pubFlag = false
@@ -299,17 +303,23 @@ local function populateCollections(stdColls, smartColls, publishService, propert
299303 table.insert (lrPhotosToAdd , lrPhoto )
300304 end
301305 end
302-
303- if # lrPhotosToAdd > 0 then
304- catalog :withWriteAccessDo (" Add Photos to collection" , function ()
305- collection :addPhotos (lrPhotosToAdd )
306- end )
307- stats .imagesCloned = stats .imagesCloned + # lrPhotosToAdd
308- progressScope :setPortionComplete (stats .imagesCloned , stats .images )
309- progressScope :setCaption (" Cloning Images... " ..
310- stats .imagesCloned .. " of " .. stats .images .. " images" )
306+ end
307+ -- now add any remaining lrPhotos that were not published photos - from oldlrPhotos
308+ for _ , lrPhoto in pairs (oldlrPhotos ) do
309+ local photoId = lrPhoto .localIdentifier
310+ if not publishedIds [photoId ] then
311+ table.insert (lrPhotosToAdd , lrPhoto )
311312 end
312313 end
314+ if # lrPhotosToAdd > 0 then
315+ catalog :withWriteAccessDo (" Add Photos to collection" , function ()
316+ collection :addPhotos (lrPhotosToAdd )
317+ end )
318+ stats .imagesCloned = stats .imagesCloned + # lrPhotosToAdd
319+ progressScope :setPortionComplete (stats .imagesCloned , stats .images )
320+ progressScope :setCaption (" Cloning Images... " ..
321+ stats .imagesCloned .. " of " .. stats .images .. " images" )
322+ end
313323 end
314324 end
315325
@@ -578,32 +588,36 @@ local function importServicePrelim(propertyTable, thisService, impService)
578588 unpublishedCollImages = 0 ,
579589 unpublishedSmartCollImages = 0 ,
580590 }
581-
591+ local canClone = true
582592 for id , collDets in pairs (indexById ) do
583593 local extraCollDets = {}
584594 local thisColl = catalog :getPublishedCollectionByLocalIdentifier (id )
585595 if thisColl then
586596 local colType = thisColl :type ()
587597 local info = {}
588598 local pubphotos = nil
599+ local lrPhotos = nil
589600 local isSmartColl = false
590601 local searchDesc = {}
591602 if colType == " LrPublishedCollection" then
592603 info = thisColl :getCollectionInfoSummary ()
593604 pubphotos = thisColl :getPublishedPhotos ()
605+ lrPhotos = thisColl :getPhotos ()
594606 -- check for smart collection
595607 isSmartColl = thisColl :isSmartCollection ()
596608 if isSmartColl then
597609 -- count number of lrPhotos in collection
598610 -- a different to number of published photos indicates un published photos
599- local numlrPhotos = # thisColl :getPhotos ()
600- local numPubPhotos = # thisColl :getPublishedPhotos ()
611+ -- which means we cannot proceed with cloning
612+ local numlrPhotos = # lrPhotos
613+ local numPubPhotos = # pubphotos
601614 if numlrPhotos > numPubPhotos then
602615 stats .unpublishedSmartCollImages = stats .unpublishedSmartCollImages +
603616 (numlrPhotos - numPubPhotos )
604617 end
605618 searchDesc = thisColl :getSearchDescription ()
606619 stats .smartCollections = stats .smartCollections + 1
620+ canClone = false
607621 else
608622 local numlrPhotos = # thisColl :getPhotos ()
609623 local numPubPhotos = # thisColl :getPublishedPhotos ()
@@ -626,11 +640,12 @@ local function importServicePrelim(propertyTable, thisService, impService)
626640 collSettings = info .collectionSettings
627641 pubSettings = info .publishSettings
628642 end
629-
643+ local publishedIds = {}
630644 if pubphotos then
631645 for pp , pubPhoto in pairs (pubphotos ) do
632646 stats .images = stats .images + 1
633647 local lrPhoto = pubPhoto :getPhoto ()
648+ publishedIds [lrPhoto .localIdentifier ] = true
634649 local fileName = " "
635650 local remId = pubPhoto :getRemoteId () or " "
636651 local remUrl = pubPhoto :getRemoteUrl () or " "
@@ -652,7 +667,9 @@ local function importServicePrelim(propertyTable, thisService, impService)
652667 extraCollDets .isSmartColl = isSmartColl
653668 extraCollDets .searchDesc = searchDesc
654669 extraCollDets .collSettings = collSettings
670+ extraCollDets .lrPhotos = lrPhotos
655671 extraCollDets .pubphotos = pubphotos
672+ extraCollDets .publishedIds = publishedIds
656673 collDets .extra = extraCollDets
657674 end
658675 end
@@ -666,23 +683,24 @@ local function importServicePrelim(propertyTable, thisService, impService)
666683 local text3 = " "
667684 local text4 = " "
668685 local text5 = " "
669- local canProceed = true
670686 if pwDetails .isPiwigo then
671687 if pwDetails .isSameHost then
672688 text2 = " The service being cloned is a Piwigo service connected to the same Piwigo host as this service."
673- if stats .unpublishedSmartCollImages > 0 or stats .unpublishedCollImages > 0 then
674- canProceed = false
689+ if not canClone then
675690 text3 =
676- " ** The service being cloned has collections with unpublished images - please fix before cloning **"
677- if stats .unpublishedCollImages > 0 then
678- text4 = " *** Unpublished Collection Images : " .. stats .unpublishedCollImages .. " ***"
679- end
691+ " ** The service being cloned has smart collections with unpublished images - please fix before cloning **"
692+
680693 if stats .unpublishedSmartCollImages > 0 then
681694 text5 = " *** Unpublished Smart Collection Images : " .. stats .unpublishedSmartCollImages .. " ***"
682695 end
683696 else
684697 text3 = " Collections/Sets will be cloned as will links to Piwigo albums and images if present"
685- text4 = " "
698+
699+ if stats .unpublishedCollImages > 0 then
700+ text4 = " *** Unpublished Collection Images : " .. stats .unpublishedCollImages .. " ***"
701+ else
702+ text4 = " "
703+ end
686704 text5 = " "
687705 end
688706 else
@@ -816,7 +834,7 @@ local function importServicePrelim(propertyTable, thisService, impService)
816834 },
817835 }
818836
819- if canProceed then
837+ if canClone then
820838 local dialog = LrDialogs .presentModalDialog ({
821839 title = " Confirm details of Publish Service to be cloned" ,
822840 contents = c ,
@@ -831,7 +849,7 @@ local function importServicePrelim(propertyTable, thisService, impService)
831849 local dialog = LrDialogs .presentModalDialog ({
832850 title = " Details of Publish Service to be cloned" ,
833851 contents = c ,
834- actionVerb = " OK " ,
852+ actionVerb = " Cancel Clone " ,
835853 cancelVerb = " < exclude >" ,
836854 })
837855 end
0 commit comments