Message Boards

Documents & media - load file at startup

Manuel Baltieri, modified 3 Years ago.

Documents & media - load file at startup

New Member Posts: 7 Join Date: 4/21/20 Recent Posts
Hello,
I created some custom document that I use in my portlet. Since I have to manage multiple installations, can I automatically upload documents to the startup of the portlet without having to manually add them via the portal menu?
Is there a tutorial on this point?
Thanks Manuel
thumbnail
Christoph Rabel, modified 3 Years ago.

RE: Documents & media - load file at startup

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
It depends on your Liferay version. I am assuming 7.0 or higher.
One way would be to use an Activator. An activator is called when your module is deployed and you can do any kind of initialization steps there. Basically you just need to add a method with the Activate annotation to a component.
    @Activate
&nbsp;&nbsp;&nbsp; protected void activate(Map<object, object> properties) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Do whatever you need here ....
&nbsp;&nbsp;&nbsp; }
</object,>
Of course, this is called whenever the component is deployed, so it might not be what you need.

Another option could be the resource importer. But you need a theme or a site template to do that. Also, resource importer is kinda deprecated nowadays and I would avoid using it for 7.3 projects.
https://help.liferay.com/hc/en-us/articles/360017883012-Importing-Resources-with-a-Theme-
Starting with 7.1, there is the option to use a site initializer. There's not a lot of documentation, but there are a couple of examples out there, e.g.:
https://github.com/liferay/com-liferay-commerce/tree/7.1.x/commerce-theme-minium/commerce-theme-minium-site-initializer
Manuel Baltieri, modified 3 Years ago.

RE: Documents & media - load file at startup

New Member Posts: 7 Join Date: 4/21/20 Recent Posts
Hello Christoph,thanks for the reply, unfortunattly my liferay version is 6.1.2. I've lookef for resource imported but is supported only from liferay 7.0, is correct?
Do you suggest me any other way to automatically load the documents?

 Actually the fastest way that i've found is throught the documents importer in the control panel. I can import my *.lar file, but a software way will be better.
Thanks,Manuel​​​​​​​