Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Cron to delete articles by structure field
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.
Kind regards,
Íñigo
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
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
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.
Liferay will automagically expire it at that time and you won't need to do any custom coding.
I stand corrected. :-)
For this task, David's way is better.
Fernando
For this task, David's way is better.
Fernando
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™