Cron to delete articles by structure field

Iñigo Boyano, modified 6 Years ago. Junior Member Posts: 96 Join Date: 2/4/14 Recent Posts
Hi, 

I have to develop a module in Liferay DXP to delete journalArticles based on a structure field of those contents, the structure have a field called 'cancelationDate' to determine when the Article is useless. From that date, the content won't show in the portal but will persist in BBDD. After a 'x' days after that date, the article would be deleted from BBDD.

I think about developing a cron job module to delete from BBDD those articles every sunday for example. I've read the following post about cron jobs looking for some info:
https://community.liferay.com/blogs/-/blogs/liferay-7-ce-liferay-dxp-scheduled-tasks, but i don't know how to start.

  • In the doRecive method is where i have to code the logic to find the articles to delete, right? It's posible in that module to access liferay services like DDMStructureLocalService or others in order to get the articles by structure.
  • I don't understant the function of the methods 'activate', 'deactivate'.
  • Is there any other better way to achieve this funcionality that is not to develop a cron module?

Kind regards, 

Íñigo
thumbnail
Fernando Fernandez, modified 6 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts
Iñigo Boyano
  • In the doRecive method is where i have to code the logic to find the articles to delete, right? It's posible in that module to access liferay services like DDMStructureLocalService or others in order to get the articles by structure.
  • I don't understant the function of the methods 'activate', 'deactivate'.
  • Is there any other better way to achieve this funcionality that is not to develop a cron module?


Hi Íñigo,

Yes, the doReceive is the method that runs your task and you can access Liferay services from there.

The activate/deactivate methods are run when your module enters/exits the OSGi container and should be the ones who register/deregister your task and your task runner.

I think this is a good way of doing this. ;-)

HTH

Fernando
thumbnail
David H Nebinger, modified 6 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
Instead of putting it in the structure, just use the expiration date on the article itself.

Liferay will automagically expire it at that time and you won't need to do any custom coding.
thumbnail
Fernando Fernandez, modified 6 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts
I stand corrected. :-)

For this task, David's way is better.

​​​​​​​Fernando