def publish_pending(cursor, publication_id):
cursor.execute("""<STR_LIT>""",<EOL>(publication_id, publication_id,))<EOL>publisher, message = cursor.fetchone()<EOL>cursor.connection.commit()<EOL>all_models = []<EOL>from .publish import publish_model<EOL>type_ = cnxepub.Document.__name__<EOL>cursor.execute("""<STR_LIT>""", (type_, publication_id,))<EOL>for row in cursor.fetchall():<EOL><INDENT>id, major_version, minor_version = row[<NUM_LIT:1>:<NUM_LIT:4>]<EOL>id = str(id)<EOL>version = '<STR_LIT:.>'.join([str(x)<EOL>for x in (major_version, minor_version,)<EOL>if x is not None])<EOL>metadata, content = row[-<NUM_LIT:2>:]<EOL>content = content[:]<EOL>metadata['<STR_LIT:version>'] = version<EOL>document = cnxepub.Document(id, content, metadata)<EOL>for ref in document.references:<EOL><INDENT>if ref.uri.startswith('<STR_LIT>'):<EOL><INDENT>hash = ref.uri[len('<STR_LIT>'):]<EOL>cursor.execute("""<STR_LIT>""", (hash,))<EOL>data, media_type = cursor.fetchone()<EOL>document.resources.append(cnxepub.Resource(<EOL>hash, io.BytesIO(data[:]), media_type, filename=hash))<EOL><DEDENT><DEDENT>_ident_hash = publish_model(cursor, document, publisher, message)  <EOL>all_models.append(document)<EOL><DEDENT>type_ = cnxepub.Binder.__name__<EOL>cursor.execute("""<STR_LIT>""", (type_, publication_id,))<EOL>for row in cursor.fetchall():<EOL><INDENT>id, major_version, minor_version, metadata = row[<NUM_LIT:1>:<NUM_LIT:5>]<EOL>tree = metadata['<STR_LIT>']<EOL>binder = _reassemble_binder(str(id), tree, metadata)<EOL>cursor.execute("""<STR_LIT>""",<EOL>(binder.ident_hash,))<EOL>binder.resources = [<EOL>cnxepub.Resource(r_hash,<EOL>io.BytesIO(r_data[:]),<EOL>r_media_type,<EOL>filename=r_filename)<EOL>for (r_hash, r_data, r_media_type, r_filename)<EOL>in cursor.fetchall()]<EOL>_ident_hash = publish_model(cursor, binder, publisher, message)  <EOL>all_models.append(binder)<EOL><DEDENT>from .publish import republish_binders<EOL>_republished_ident_hashes = republish_binders(cursor, all_models)  <EOL>cursor.execute("""<STR_LIT>""", (publication_id,))<EOL>state = cursor.fetchone()[<NUM_LIT:0>]<EOL>return state<EOL>
Given a publication id as ``publication_id``,
    write the documents to the *Connexions Archive*.