简体   繁体   中英

Does Liferay support the "run once" functionality?

So, if we want to run something only at Liferay startup, we can use the technique as described in some other answers here, like this . However, this offers, to express myself by using the OS administration expressions, "autorun" functionality. Every time when Liferay is started, this code will run. This is great for portlet initialization and stuff, which needs to be performed at every startup of Liferay.

But, what I want to know is, is there any "run once" functionality in Liferay? So, a way to specify what code to run, just like in the linked question, but to deactivate this action once it ran for the first time, automatically? For example, if we have some one time database initialization procedure or something like this.

Is this possible in Liferay?

Sure, I can manually implement a flag in database which would hold the information about whether one time action has executed or not, and then in action perform a check, and return from method before performing one time initialization if flag is true, sure, this is an option, but, is there some native Liferay way to execute an action once and only once?

So, I am looking for autounregister functionality. So that I can create an action, register it and then that Liferay autounregisters it once it ran it for the first time. Something like that.

Sure, the starting point is https://help.liferay.com/hc/en-us/articles/360018162611-Waiting-on-Lifecycle-Events

Look for PORTAL_INITIALIZED sample.

Run once is rather in the realm of an upgrade action . You can make up a module name and "upgrade" to its version 1.

Until you bring a newer upgrade routine, it did run and won't upgrade again. The name might sound weird, but it's precisely what needs to be done once and then never again (unless you want to add more - then you upgrade "further", or provide a new upgrade action)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM