Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Florencia Gadea
After deploy event?
December 6, 2012 5:12 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

Hi Everyone!

I would like to run some code after a portlet is deployed.

Is there something like an after deploy event?

If not, how can I achieve this?

Regards,

Flor.
Jan Geißler
RE: After deploy event?
December 6, 2012 5:28 AM
Answer

Jan Geißler

Community Moderator

Rank: Liferay Master

Posts: 735

Join Date: July 5, 2011

Recent Posts

http://www.liferay.com/de/documentation/liferay-portal/6.1/user-guide/-/ai/startup-even-1

application.startup.events=*.*.*.StartupHook


1
2public class StartupHook extends SimpleAction
3@Override
4    public void run(String[] companyIds) throws ActionException


This should get you on track.
David H Nebinger
RE: After deploy event?
December 6, 2012 5:30 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11056

Join Date: September 1, 2006

Recent Posts

There is no 'after deploy event'. However, as Jan pointed out you can use the startup event. To get it to be one time only, you should do some sort of query to check whether you've already completed the actions previously.
Florencia Gadea
RE: After deploy event?
December 6, 2012 5:44 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

That is a great idea David. Any idea about how to check if the action has been executed previously? Should I store a property in the database? Is there a specific table to do that? Or should I create my own entity?

Regards,

Flor.
Jan Geißler
RE: After deploy event?
December 6, 2012 5:50 AM
Answer

Jan Geißler

Community Moderator

Rank: Liferay Master

Posts: 735

Join Date: July 5, 2011

Recent Posts

Even if I am not David ;)

EG. If you want to add some USers in your StratupAction, you could check if the Users already exist in the Database, and stop executing the if the user is already there.

Regards
Florencia Gadea
RE: After deploy event?
December 6, 2012 6:06 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

Thanks Jan, that will do!
David H Nebinger
RE: After deploy event?
December 6, 2012 8:27 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11056

Join Date: September 1, 2006

Recent Posts

Liferay does have a Release object and corresponding ReleaseLocalServiceUtil that you can use... It's not as rigid as the parameters would tend to indicate...

You could use:
1
2Release release = ReleaseLocalServiceUtil.getRelease("my-plugin", 1);


to see if your release is there. If not, you'd do:
1
2release = ReleaseLocalServiceUtil.addRelease("my-plugin", 1);

and then invoke your startup code.

You could even handle upgrades in a similar way. If you're checking for ("my-plugin", 5) but don't find it, you can step backwards to see if there was a previous release already deployed, then handle upgrades from the previous version up to 5, then use:
1
2release = ReleaseLocalServiceUtil.updateRelease(release.getReleaseId(), 5, buildDate, true);


so that your one release entry is updated to be build 5...

Liferay uses a 4 digit release value, i.e. 6012 to indicate it is 6.0 sp 12 or 6.0 EE...
Florencia Gadea
RE: After deploy event?
December 6, 2012 8:39 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 146

Join Date: March 27, 2012

Recent Posts

Thanks David, really useful information.
Jan Geißler
RE: After deploy event?
December 6, 2012 8:40 AM
Answer

Jan Geißler

Community Moderator

Rank: Liferay Master

Posts: 735

Join Date: July 5, 2011

Recent Posts

Hey. I didn't think of that till now. Thanks for this valuable information ;)
David H Nebinger
RE: After deploy event?
December 6, 2012 9:49 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11056

Join Date: September 1, 2006

Recent Posts

Most devs aren't really aware that they can use the release stuff also...