4 Replies Latest reply on May 23, 2012 10:45 PM by evlogimenos

    How to set remoteId for new PublishedCollection?

    evlogimenos Level 1

      I am writing a PublishService plugin and I am stuck on how to properly implement creation of new Collections/CollectionSets.


      When an existing PublishedCollection is changed (renamed and collection settings are changed) renamePublishedCollection and updateCollectionSettings are called in that order. This allows setting the new name and different collection settings for the PublishedCollection.


      When a new PublishedCollection is created, only updateCollectionSettings is called. In this case the PublishedCollection lacks a remoteId (and there was no way to set it). Even if the remoteId is set inside this call, it ends up being overwritten by the caller of this function.


      How did you guys worked around this?


      Is there a chance for a change in 4.1 to call renamePublishedCollection after a new PublishedCollection creation and treat info.remoteId and info.remoteUrl as input parameters that are going to be persisted after this call returns?


      Message was edited by: disht

        • 1. Re: How to set remoteId for new PublishedCollection?
          Don McKee Level 1

          I'm not entirely sure what you're trying to do that isn't working, but I think you're having trouble setting a new (but not necessarily the initial?) LrPublishedCollection's remoteId field.  In updateCollectionSettings(), did you try


              info.publishedCollection:setRemoteId( myRemoteId )


          Reading between the lines, it looks like you may be trying to set the value by updating the read-only "info" table.


          The renamePublishedCollection() callback is intended to let you, for example, rename the remote representation of the collection if the user renames the local one.  Is that how you're trying to use it?


          Post back with more details if I'm misunderstanding what you're trying to do.



          • 2. Re: How to set remoteId for new PublishedCollection?
            evlogimenos Level 1

            Yes I tried what you suggest. If you do a plain:


            info.publishedCollection:setRemoteId( myRemoteId )


            inside updateCollectionSettings() you will get an error saying you should do this under a withWriteAccessDo() call. If you do this under a withWriteAccessDo() call, it "succeeds" only for you to find out that it does not get applied. I am guessing here but it seems that the code that calls updateCollectionSettings does something like this:


            info.name = name

            info.publishedCollection = makeFakePublishedCollection()

            info.collectionSettings = copySettingsFromDialog()

            updateCollectionSettings(prefs, info) -- Whatever you do on info.publishedCollection will have no effect.


              local collection = publishService:createPublishedCollection(info.name)



            • 3. Re: How to set remoteId for new PublishedCollection?
              Don McKee Level 1

              I just put this code in my updateCollectionSettings() callback:


              local collection = info.publishedCollection


              if collection:getRemoteId() == nil then

                 debug("Remote ID not set.  Setting now....")

                 collection.catalog:withWriteAccessDo( "Set Remote ID", function()

                    collection:setRemoteId( "My Remote ID" )



                 debugf("Remote ID set to '%s'", collection:getRemoteId() )



              The first time through (after selecting 'Rename' from the published collection's context menu), this is logged:


              DEBUG Remote ID not set.  Setting now....


              The second time through (after selecting 'Rename' again), this is what I see:


              DEBUG Remote ID set to 'My Remote ID'


              If you can't figure out what's going wrong, post your code and maybe someone here will spot the problem.



              • 4. Re: How to set remoteId for new PublishedCollection?
                evlogimenos Level 1

                Weird. I tried this again and it did work.


                But I opted for another solution which I implemented before I saw your reply: I do not create new remote collections until first publish. update/rename/delete do not update the server because there is no remoteId set.


                The latter works better when you undo right after creating a new published collection. If you create the published collection on the server and then undo, the remote collection is not deleted. If you wait until first publish you can undo creating a new published collection without leaving dangling remote collections.