def _insert_metadata(cursor, model, publisher, message):
params = model.metadata.copy()<EOL>params['<STR_LIT>'] = publisher<EOL>params['<STR_LIT>'] = message<EOL>params['<STR_LIT>'] = _model_to_portaltype(model)<EOL>params['<STR_LIT>'] = str(cnxepub.DocumentSummaryFormatter(model))<EOL>for person_field in ATTRIBUTED_ROLE_KEYS:<EOL><INDENT>params[person_field] = [parse_user_uri(x['<STR_LIT:id>'])<EOL>for x in params.get(person_field, [])]<EOL><DEDENT>params['<STR_LIT>'] = parse_parent_ident_hash(model)<EOL>if model.ident_hash is not None:<EOL><INDENT>uuid, version = split_ident_hash(model.ident_hash,<EOL>split_version=True)<EOL>params['<STR_LIT>'] = uuid<EOL>params['<STR_LIT>'], params['<STR_LIT>'] = version<EOL>cursor.execute("<STR_LIT>",<EOL>(uuid,))<EOL>try:<EOL><INDENT>moduleid = cursor.fetchone()[<NUM_LIT:0>]<EOL><DEDENT>except TypeError:  <EOL><INDENT>moduleid = None<EOL><DEDENT>params['<STR_LIT>'] = moduleid<EOL>cursor.execute("<STR_LIT>",<EOL>(uuid,))<EOL>try:<EOL><INDENT>cursor.fetchone()[<NUM_LIT:0>]<EOL><DEDENT>except TypeError:  <EOL><INDENT>cursor.execute("<STR_LIT>",<EOL>(uuid,))<EOL><DEDENT>created = model.metadata.get('<STR_LIT>', None)<EOL>stmt = MODULE_INSERTION_TEMPLATE.format(**{<EOL>'<STR_LIT>': "<STR_LIT>",<EOL>'<STR_LIT>': "<STR_LIT>",<EOL>'<STR_LIT>': "<STR_LIT>",<EOL>'<STR_LIT>': moduleid is None and "<STR_LIT>" or "<STR_LIT>",<EOL>'<STR_LIT>': created is None and "<STR_LIT>" or "<STR_LIT>",<EOL>})<EOL><DEDENT>else:<EOL><INDENT>created = model.metadata.get('<STR_LIT>', None)<EOL>stmt = MODULE_INSERTION_TEMPLATE.format(**{<EOL>'<STR_LIT>': "<STR_LIT>",<EOL>'<STR_LIT>': "<STR_LIT>",<EOL>'<STR_LIT>': "<STR_LIT>",<EOL>'<STR_LIT>': "<STR_LIT>",<EOL>'<STR_LIT>': created is None and "<STR_LIT>" or "<STR_LIT>",<EOL>})<EOL><DEDENT>cursor.execute(stmt, params)<EOL>module_ident, ident_hash = cursor.fetchone()<EOL>_insert_optional_roles(cursor, model, module_ident)<EOL>return module_ident, ident_hash<EOL>
Insert a module with the given ``metadata``.