docs: def republish_module(td, plpy):
      """When a module is republished, create new minor versions of collections.
  
      All collections (including subcollections) that this module is contained
      in part of will need to be updated (a minor update).
  
      e.g. there is a collection c1 v2.1, which contains a chapter sc1 v2.1,
      which contains a module m1 v3. When m1 is updated, we will have a new row
      in the modules table with m1 v4.
  
      This trigger will create increment the minor versions of c1 and sc1, so
      we'll have c1 v2.2, and sc1 v2.2. However, another chapter sc2 will stay
      at v2.1.
  
      We need to create a collection tree for c1 v2.2 which is exactly the same
      as c1 v2.1, but with m1 v4 instead of m1 v3, and sc1 v2.2 and c1 v2.2
      instead of sc1 2.1 and c1 v2.1
      """
      portal_type = td['new']['portal_type']
      modified = 'OK'
      moduleid = td['new']['moduleid']
      legacy_version = td['new']['version']
      submitter = td['new']['submitter']
      submitlog = td['new']['submitlog']
  
      modified = set_version(portal_type, legacy_version, td)
  
      current_module_ident = get_current_module_ident(moduleid, plpy)
      if current_module_ident:
          # need to overide autogen uuid to keep it constant per moduleid
          uuid = get_module_uuid(plpy, moduleid)
          td['new']['uuid'] = uuid
          modified = 'MODIFY'
      else:
          # nothing to do if the module/collection is new
          return modified
  
      if portal_type != 'Module':
          # nothing else to do if something else is being published
          return modified
  
      # Module is republished
      replace_map = {current_module_ident: td['new']['module_ident']}
      # find the nested subcollections the module is in, and
      # republish them, as well, adding to map, for all collections
      # Note that map is for all subcollections, regardless of what
      # collection they are contained in.
      for sub_id in get_subcols(current_module_ident, plpy):
          minor = next_version(sub_id, plpy)
          new_subcol_ident = republish_collection(submitter, submitlog,
                                                  minor, sub_id, plpy)
          replace_map[sub_id] = new_subcol_ident
  
      # Now do each collection that contains this module
      for collection_id in get_collections(current_module_ident, plpy):
          minor = next_version(collection_id, plpy)
          new_ident = republish_collection(submitter, submitlog, minor,
                                           collection_id, plpy)
          replace_map[collection_id] = new_ident
          rebuild_collection_tree(collection_id, replace_map, plpy)
  
      return modified