8 Replies Latest reply on Oct 22, 2013 4:05 PM by areohbee

    recordPublishedPhotoId and with setPropertyForPlugin before that

    egzplicit

      Hello,

       

      I'm building my first Lightroom plugin and i'm having trouble dealing with processRenderedPhotos(). Images are being uploaded to a service (RESTful API) and the service response contains some metadata I need to set to the photo. I'm doing:

       

       

       

      photo.catalog:withWriteAccessDo( "publishing", function( context )
          -- bla bla, image was uploaded
          photo:setPropertyForPlugin( _PLUGIN, "someKey", "someValue" )
          rendition:recordPublishedPhotoId( remoteId 
      end )
      

       

      The problem is that by calling photo:setPropertyForPlugin(), my image goes into the "Modified Photos to Re-Publish" queue instead of being in the "Published" one. If i don't call the setPropertyForPlugin() method, the image is moved into the "Published photos" section.

       

      I belive the withWriteAccessDo() has a delay and my rendition:recordPublishedPhotoId() call is actually performed BEFORE the writes to the LrPhoto object, hence the moving of that image to the "modified" queue (sometimes I can even see the UI shoing the image in the "Published" queue and then it refreshes and moves into the modified one).

       

      Please help

       

      Thank you!

        • 1. Re: recordPublishedPhotoId and with setPropertyForPlugin before that
          egzplicit Level 1

          So far it seems that the re-publish is triggere because the "someKey" is present in the metadataThatTriggersRepublish table. If I remove it from there, calling the setPropertyForPlugin() method and then calling recordPublishedPhotoId() works just fine.

           

          Is there a way aroudn this? I still want the "someKey" custom metadata to trigger a republish when the user changes it via the Lightroom UI, however I don't want the republish to happen when the actual plugin is changing it via photo:setPropertyForPlugin() inside the processRenderedPhotos() method.

          • 2. Re: recordPublishedPhotoId and with setPropertyForPlugin before that
            areohbee Level 6

            After setting the property and returning from the catalog-with-do method, reset the modified-for-republish flag to what it was before, or what you want it to be (hint: publishedPhoto:setEditedFlag( desiredValue ). Note: you'll have to go back into another catalog-with-do method.

             

            This multi-stage catalog updating became so common in my code that I built it into a single multi-phased catalog-access-wrapper method - maybe that was overkill, but food for thought...

             

            Rob

            • 3. Re: recordPublishedPhotoId and with setPropertyForPlugin before that
              egzplicit Level 1

              That makes sense, thank you. Did not spot the setEditedFlag() method inside the LrPublishedPhoto class. I've tried to do it your way and it seems to work, the only annoying thing is the UI refresh: when a new photo is added to a published collection and the user presses "Publish", 1st the image is uploaded to the remote service, then the metadata is set based on the service reply: this cause the image to go into the "modified photos for re-publish" queue for a tiny bit, until the other catalog-with-do method kicks in and sets the flag back to false.

               

              Before reading your reply, I fixed this by using exportContext.publishedCollection:addPhotoByRemoteId() called from the 1st (and only, in this case) catalog-with-do method. In the documentation it states that if the photo is already published, it will just update the remoteId property, but actually it's also setting the edited flag to false. This causes no jumping of the image inside the "modified photos for re-publish" queue and it makes it go straight into the "published" one... however, it is a hack and not the right way of doing it

              • 4. Re: recordPublishedPhotoId and with setPropertyForPlugin before that
                areohbee Level 6

                Did you try doing it (reseting edited flag) in the same with-do invocation? - there is a small chance that might work, depending on how it's coded...

                • 5. Re: recordPublishedPhotoId and with setPropertyForPlugin before that
                  egzplicit Level 1

                  I don't think I can because the writing of the catalog changes needs to happen first. According to the docs:

                   

                  As of version 3.0, changes you make to the database within this call do not have immediate effect, but are written to the database upon successful completion of the callback function. This means, in general, that if you create a new item (for instance, by callingcatalog:createCollection()), you cannot retrieve information about that item until the with___AccessDo has finished

                   

                   

                  From what I understand, that means I cannot retrieve the published photos (LrPublishedPhoto instances) from that collection because the new photos are not actually "published" until the catalog-with-write method finishes. I've tried doing something like:

                   

                  LrFunctionContext.postAsyncTaskWithContext( "wefwefwefwef", function( context )

                                          for k,obj in pairs(exportContext.publishedCollection:getPublishedPhotos()) do

                                              obj:setEditedFlag( false )

                                          end        

                                      end )

                   

                  essentially 1) doing the upload to the service 2) setting the extra metadata returned by the service 3) calling rendition:recordPublishedPhotoId 4) getting all published photos inside the collection and marking them via setEditedFlag(false)... but it doesn't seem to work.

                   

                  Edited: to make things even more complicated, I had to start an async task because publishedCollection:getPublishedPhotos() only works in an async task.

                  • 6. Re: recordPublishedPhotoId and with setPropertyForPlugin before that
                    areohbee Level 6

                    Right - my suggestion for trying would only apply if photo was already published, and even then it would be a long shot.

                    • 7. Re: recordPublishedPhotoId and with setPropertyForPlugin before that
                      egzplicit Level 1

                      Yeah, however, I did eventually find a way: instead of uploading the photo to the service and setting the custom metadata right after, I'm now updating all photos from the queue and I'm storing the metadata for each image in a table variable. After finishing with the uploads and marking all the images via rendition:recordPublishedPhotoId( remoteId ) , the images end up in the "Published" section. After this I start to iterate over the table storing the metadata and within another catalog-with-write method I write the custom metadata and immediately call publishedPhoto:setEditedFlag( false )

                       

                      Doing so causes the images to go directly to the "Published" section and to stay there

                       

                       

                      Thanks for helping!

                      • 8. Re: recordPublishedPhotoId and with setPropertyForPlugin before that
                        areohbee Level 6

                        Where there's a will, there's (sometimes) a way - congrats (and you're welcome).

                        R