Question

I've asked the same question in Liferay community but with no answers so I try here :)

I need to perform an action/call a method everytime a user download a file from the document library, for simplicity I'd say a System.out.println("a file has been downloaded") everytime the user click on the direct file link.

Do you have any idea on how I can achieve this? I'm using LR 6.0.6 CE and would really try to avoid the EXT environment... any idea on how to achieve this with a hook would be much appreciated!!

I was thinking about adding some javascript on the JSP (onClick) that calls the System.out.println() function, but not sure if it's possible.

I thought about action hooks, model listeners, override a service... what do you think would be the best way?

Was it helpful?

Solution

I've found a way to achieve this creating a model Listener for the DLFileEntry model and overriding the method "onAfterUpdate", which is triggered every time a document is downloaded because it changes the value of the readcount variable.

OTHER TIPS

In order to add business logic, you should rather look at DLFileEntryLocalService and the wrappers for this service, instead of model listeners. Model Listeners are meant for persistence-related fixes, but not to add arbitrary new logic - that's what's better in *LocalService wrappers, as *LocalService is all about business logic.

This requires a Hook, you're right to keep away from ext - it's not required here and you'd have more upgrade issues than with a hook.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top