Resource Importer for Single Portal Instance

By Default in Liferay, Resource Importer will import journal articles,structures,templates,sites and document to all portal Instances present in the System

If we need to restrict Resource importer to one particular instance we can do it by following steps

STEP 1 : In your Theme Plugin go to docroot/WEB-INF/liferay-plugin-package.properties file and add the Portal Instance Web Id for which  you want the Themes's Resource Importer to work

company-web-id=sample.com

STEP 2 :  Download the Resource Importer Plugin from Github 

https://github.com/liferay/liferay-plugins/tree/6.2.x/webs/resources-importer-web 

STEP 3 : Go to  /docroot/WEBINF/src/com/liferay/resourceimporter/messaging/ResourceImporterHotDeployMessageListener.java   

Inside initialize(Message message) Method

Add the Highlighted code in initialize Method

  protected void initialize(Message message) throws Exception {
       String servletContextName = message.getString("servletContextName");
 
       ServletContext servletContext = ServletContextPool.get(servletContextName);
 
     if (servletContext == null) {
     return;
       }
 
    PluginPackageProperties pluginPackageProperties =
     new PluginPackageProperties(servletContext);
 
     String resourcesDir = pluginPackageProperties.getResourcesDir();
 
     if ((servletContext.getResource(ImporterFactory.RESOURCES_DIR) == null) &&servletContext.getResource(
         ImporterFactory.TEMPLATES_DIR) == null) && Validator.isNull(resourcesDir)) {
 
          return;
     }
    String webId = pluginPackageProperties .getProperty("company-web-id", StringPool.Blank);
   List<Company> companies = CompanyLocalServiceUtil.getCompanies();
 
  try {
     ExportImportThreadLocal.setLayoutImportInProcess(true);
     ExportImportThreadLocal.setPortletImportInProcess(true);
 
   for (Company company : companies) {
    if (!webId.isEmpty()  && !company.getWebId().equalIgnoreCase(webId)) {
            continue;
       }
         importResources(company, servletContext, pluginPackageProperties,message.getResponseId());
   }
  }
  finally {
       ExportImportThreadLocal.setLayoutImportInProcess(false); 
      ExportImportThreadLocal.setPortletImportInProcess(false);
    }
  }
 
STEP 4 : Deploy the Resource Importer