[opencms-dev] Can the export of a project and modules from one server and import to another server be automated

Pere Torrodellas ptorrodellas at fihoca.com
Tue Apr 1 09:46:00 CEST 2008


You can export with a scheduled job and this code, adapted to your needs and environment :

For a module:

      String moduleName = "my.mod";

      // Module resources
      List resList = OpenCms.getModuleManager().getModule(moduleName)
            .getResources();
      // Verify resources
      ArrayList resListCopy = new ArrayList();
      for (Iterator it = resList.iterator(); it.hasNext();) {
         String res = (String) it.next();
         try {
            if (res != null) {
               cms.readResource(res);
               resListCopy.add(res);
            }
         } catch (Exception e) {
            // Resource not available - Log it
         }
      }

      String[] resources = new String[resListCopy.size()];

      for (int i = 0; i < resListCopy.size(); i++) {
         resources[i] = (String) resListCopy.get(i);
      }

      String moduleFile = OpenCms.getSystemInfo()
         .getAbsoluteRfsPathRelativeToWebInf("packages/modules/" 
               + moduleName + ".zip");
      File file = new File(moduleFile);
      if (file.exists()) {
         file.delete();
      }

      CmsModuleImportExportHandler moduleExportHandler = new CmsModuleImportExportHandler();
      moduleExportHandler.setFileName(moduleFile);
      moduleExportHandler.setAdditionalResources(resources);
      moduleExportHandler.setModuleName(moduleName.replace('\\', '/'));
      moduleExportHandler.setDescription("Module Export: "
            + moduleExportHandler.getModuleName());

      // Export
      OpenCms.getImportExportManager().exportData(cms, moduleExportHandler, report);

For a site folder:

      String filePath = OpenCms.getSystemInfo()
            .getAbsoluteRfsPathRelativeToWebInf(
                  "packages/" + folderName  + ".zip");

      File file = new File(filePath);
      if (file.exists()) {
         file.delete();
      }

      List resourcesToExport = new ArrayList();
      resourcesToExport.add(folderName + "/");

      CmsExport ce = new CmsExport(cms, filePath, resourcesToExport, false,
            true, null, false, false, 0L, report, true);

I suppose that these are the corresponding classes/methods to import.

Hope this helps,

Pere
  ----- Original Message ----- 
  From: Michael von Bodungen 
  To: opencms-dev at opencms.org 
  Sent: Monday, March 31, 2008 4:45 PM
  Subject: [opencms-dev] Can the export of a project and modules from one server and import to another server be automated


  We are using OpenCms and we have a staging server and production server.  The staging server is where users make all content changes, rather than in production.  We would like to automate the export of the OpenCms project and modules on staging and their import to OpenCms on the production server.

  Looking at the scheduler, I can't see any predefined jobs.  Can anyone tell me if this has been done - supply any suggestions?

  Thanks,
  Michael



------------------------------------------------------------------------------



  _______________________________________________
  This mail is sent to you from the opencms-dev mailing list
  To change your list options, or to unsubscribe from the list, please visit
  http://lists.opencms.org/mailman/listinfo/opencms-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20080401/888d589a/attachment.htm>


More information about the opencms-dev mailing list