Class CmsModuleUpdater

  • public class CmsModuleUpdater
    extends java.lang.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.

    • Method Detail

      • 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.

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

        public static java.util.Optional<CmsModuleUpdatercreate​(CmsObject cms,
                                                                  java.lang.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.

        cms - the current CMS context
        importFile - the import file path
        report - the report to write to
        an optional module updater
        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.

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

        public static java.lang.String normalizePath​(java.lang.String... pathComponents)
        Normalizes the path.

        pathComponents - the path components
        the normalized path
      • run

        public void run()
        Performs the module update.

      • deleteConflictingResources

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

        protected void processImportResource​(CmsObject cms,
                                             CmsResourceImportData resData,
                                             int index)
        Processes single resource from module import data.
        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.
        cms - the CMS context to use
        module - the module for which to run the script