Class CmsModuleUpdater

java.lang.Object
org.opencms.module.CmsModuleUpdater

public class CmsModuleUpdater extends Object
Class used for updating modules.

This class updates modules in a smarter way than simply deleting and importing them again: The resources in the import ZIP file are compared to the resources in the currently installed module and only makes changes when necessary. The reason for this is that deletions of resources can be slow in some very large OpenCms installations, and the classic way of updating modules (delete/import) can take a long time because of this.

  • Constructor Details

  • Method Details

    • checkCompatibleModuleResources

      public static boolean checkCompatibleModuleResources(CmsModule installedModule, CmsModule newModule)
      Checks whether the module resources and sites of the two module versions are suitable for updating.

      Parameters:
      installedModule - the installed module
      newModule - the module to import
      Returns:
      true if the module resources are compatible
    • create

      public static Optional<CmsModuleUpdater> create(CmsObject cms, String importFile, I_CmsReport report) throws CmsException
      Tries to create a new updater instance.

      If the module is deemed non-updatable, an empty result is returned.

      Parameters:
      cms - the current CMS context
      importFile - the import file path
      report - the report to write to
      Returns:
      an optional module updater
      Throws:
      CmsException - if something goes wrong
    • needToUpdateResourceFields

      public static boolean needToUpdateResourceFields(CmsResource existingRes, CmsResource newRes, boolean reduced)
      Check if a resource needs to be updated because of its direct fields.

      Parameters:
      existingRes - the existing resource
      newRes - the new resource
      reduced - true if we are in reduced export mode
      Returns:
      true if we need to update the resource based on its direct fields
    • normalizePath

      public static String normalizePath(String... pathComponents)
      Normalizes the path.

      Parameters:
      pathComponents - the path components
      Returns:
      the normalized path
    • readModuleData

      public static CmsModuleImportData readModuleData(CmsObject cms, String importFile, I_CmsReport report) throws CmsException
      Reads the module data from an import zip file.

      Parameters:
      cms - the CMS context
      importFile - the import file
      report - the report to write to
      Returns:
      the module data
      Throws:
      CmsException - if something goes wrong
    • importRelations

      public void importRelations(CmsObject cms) throws CmsException
      Update relations for all imported resources.

      Parameters:
      cms - the current CMS context
      Throws:
      CmsException - if something goes wrong
    • run

      public void run()
      Performs the module update.

    • updateAcls

      public boolean updateAcls(CmsObject cms, CmsResourceImportData resData, CmsResource resource) throws CmsException
      Updates the access control list fr a resource.

      Parameters:
      cms - the current cms context
      resData - the resource data
      resource - the existing resource
      Returns:
      the resource
      Throws:
      CmsException - if something goes wrong
    • createAndSetModuleImportProject

      Creates the project used to import module resources and sets it on the CmsObject.
      Parameters:
      cms - the CmsObject to set the project on
      module - the module
      Returns:
      the created project
      Throws:
      CmsException - if something goes wrong
    • deleteConflictingResources

      protected void deleteConflictingResources(CmsObject cms, CmsModule module, Map<CmsUUID,CmsUUID> conflictingIds) throws CmsException, Exception
      Deletes and publishes resources with ID conflicts.
      Parameters:
      cms - the CMS context to use
      module - the module
      conflictingIds - the conflicting ids
      Throws:
      CmsException - if something goes wrong
      Exception - if something goes wrong
    • parseLinks

      protected void parseLinks(CmsObject cms) throws CmsException
      Parses links for XMLContents etc.
      Parameters:
      cms - the CMS context to use
      Throws:
      CmsException - if something goes wrong
    • processDeletions

      protected void processDeletions(CmsObject cms, List<CmsResource> toDelete) throws CmsException
      Handles the file deletions.
      Parameters:
      cms - the CMS context to use
      toDelete - the resources to delete
      Throws:
      CmsException - if something goes wrong
    • processImportResource

      protected void processImportResource(CmsObject cms, CmsResourceImportData resData, int index)
      Processes single resource from module import data.
      Parameters:
      cms - the CMS context to use
      resData - the resource data from the module import
      index - index of the current import resource
    • runImportScript

      protected void runImportScript(CmsObject cms, CmsModule module)
      Runs the module import script.
      Parameters:
      cms - the CMS context to use
      module - the module for which to run the script