create new tag
, view all tags

Issues with afterAttachmentSaveHander API

I have encountered several issues with the afterAttachmentSaveHander API. We need to decide how to resolve them.


I am developing a plugin that wants to save a companion attachment. It's not possible with the current API. See Store.pm.

In this case, when an image is saved, I want to generate and save a companion thumbnail. I want this to happen automagically whenever an attachment is saved, transparently to the user. (Except that the user gets to use the thumbnail!)

Secondarily, I want default links to images to display the thumbnail, but link to the large image.


  • the afterSave handler is called holding the topic lock. So any attempt to call saveAttachment recursively will deadlock.
  • saveAttachment closes the temporary file that (may have) used to hold the data just before calling the handler. This guarantees that the handle must reread the data all the way from the repository. This is unfortunate - on performance and atomicity grounds.
  • saveAttachment does not pass the new attachment's metadata to the handler - and it hasn't written the topic text back yet either. So the handler really can't know what it's doing.
  • there is no hook for the createlink option. It would be useful to be able to modify the returned link to meet coding or functional requirements. For example, to use %ATTACHMENT% or otherwise use an image in the link. (You may have seen the AttachLinkPlugin appear...I suspect that Attach.pm could export some useful methods for it and the ImgPlugin, but I digress.)


  • Implement a postAttachmentSaveHander callback - right at the final } of saveAttachment. It should pass everyting it knows.
  • Provide an "already locked" flag to saveAttachment for recursive handlers - this would prevent the deadlock. But the handler would need the open topic.
  • Move the tempfile unlink down to after the if( haveHanderlFor ) block.
  • Fill in %attrs before calling the handler, and pass them along.
  • Do something really different.
  • I can do something local - the prototype simply writes directly to pub/web/topic/file

Thoughts? Takers?

-- Contributors: TimotheLitt - 21 Dec 2008


Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2008-12-21 - TimotheLitt
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.