Docker install

The docker compose file:

networks:
  bridge:
    driver: bridge
services:
  # The container that runs XWiki in Tomcat, with the appropriate JDBC driver (for postgres).
  web:
    image: "xwiki:${XWIKI_VERSION}-postgres-tomcat"
    container_name: xwiki-postgres-tomcat-web
    depends_on:
      - db
    ports:
      - "8080:8080"
    # Default values defined in .env file.
    # The DB_USER/DB_PASSWORD/DB_DATABASE/DB_HOST variables are used in the hibernate.cfg.xml file.
    environment:
      - XWIKI_VERSION=${XWIKI_VERSION}
      - DB_USER=${DB_USER}
      - DB_PASSWORD=${DB_PASSWORD}
      - DB_DATABASE=${DB_DATABASE}
      - DB_HOST=xwiki-postgres-db
      - JAVA_OPTS="-Xmx2048m"
    # Provide a name instead of an auto-generated id for xwiki data (the permanent directory in included in it)
    # configured in the Dockerfile, to make it simpler to identify in 'docker volume ls'.
    volumes:
      - /opt/xwiki/xwiki-data:/usr/local/xwiki
    networks:
      - bridge
  # The container that runs the database (postgres)
  db:
    image: "postgres:17"
    container_name: xwiki-postgres-db
    volumes:
      - /opt/xwiki/postgres-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_ROOT_PASSWORD=${POSTGRES_ROOT_PASSWORD}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_DB=${DB_DATABASE}
      - POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale-provider=builtin --locale=C.UTF-8
    networks:
      - bridge

The Environment file (.env):

# Default environment values
XWIKI_VERSION=16.10.11
DB_USER=xwiki
DB_PASSWORD=Test1234!
DB_DATABASE=xwiki
POSTGRES_ROOT_PASSWORD=Test12345!


Simple page create:

PUT https://funky.mos-eisley.dk/rest/wikis/xwiki/spaces/Sandbox/pages/MyNewPage2

{code}
<page xmlns="http://www.xwiki.org">
  <title>My New Page2</title>
  <parent>Sandbox.WebHome</parent>
  <syntax>xwiki/2.1</syntax>
  <content>//Hello, this is italic text in XWiki syntax//</content>
</page>
{code}

The way to make the hierachy:

1st page under sandbox:

https://funky.mos-eisley.dk/rest/wikis/xwiki/spaces/Sandbox/pages/sub1

Sub parge for Page 1:

https://funky.mos-eisley.dk/rest/wikis/xwiki/spaces/Sandbox/spaces/sub1/pages/sub2

Sub parge for Page 2:

https://funky.mos-eisley.dk/rest/wikis/xwiki/spaces/Sandbox/spaces/sub1/spaces/sub2/pages/sub3


Migration script (WIP):

from atlassian import Confluence
import convert
import requests
from requests.auth import HTTPBasicAuth
from xml.sax.saxutils import escape
import os
import config

confluence = Confluence(
    url=config.conflunce_url,
    username=config.username,
    password=config.password)

def process_all_children(page):

    return ""

def create_xwki_page(wiki_space,title,parent,content):

    url = config.xwiki_url + "/rest/wikis/xwiki/spaces/" + wiki_space + "/pages/" + title.replace(" ","")
    
    xml = "<page xmlns=\"http://www.xwiki.org\"><title>" + title + "</title>"
    xml = xml + "<parent>" + wiki_space + "." + parent.replace(" ","") + "</parent>"
    xml = xml + "<syntax>xwiki/2.1</syntax>"
    xml = xml + "<content>" +  escape(content) + "</content></page>"

    #print (xml)

    headers = {
        "Content-Type": "application/xml"
    }

    response = requests.put(url, data=xml, headers=headers, auth=HTTPBasicAuth(config.username,config.password))

    # Check the response
    if response.status_code == 201:
        print("Page " + title + " created")
    else:
        if response.status_code == 202:
            print("Page " + title + " updated")
        else:
            print("Status code:", response.status_code)
            print("Response:", response.text)

def attach_file_to_page(wiki_space,title,file_path,filename):

    url = config.xwiki_url + "/rest/wikis/xwiki/spaces/" + wiki_space + "/pages/" + title.replace(" ","") + "/attachments/" + filename

    headers = {
        "Content-Type": "application/xml",
        "XWiki-AttachmentComment": "Uploaded by migrator"
    }
    
    with open(file_path, "rb") as f:
        #files = {"file": f}  # 
        response = requests.put(url, data=f, headers=headers, auth=HTTPBasicAuth(config.username,config.password))

    # Check the response
    if response.status_code == 201:
        print("Attachment " + filename + " created")
    else:
        if response.status_code == 202:
            print("Attachment " + filename + " updated")
        else:
            print("Status code:", response.status_code)
            print("Response:", response.text)

#Start on the XWiki
wiki_space = "Sandbox" 

#Start Space in Confluence
space_key = "ATLASSIAN"

space = confluence.get_space(space_key, expand='description.plain,homepage')
homepageid=space['homepage']['id']
prop = confluence.get_page_by_id(homepageid,expand="body.storage")
content = prop["body"]["storage"]["value"]
home_title = prop['title']

(result, log) = convert.convert(content)

xwiki_page = create_xwki_page(wiki_space,home_title,"webHome",result)
parent = home_title
children = confluence.get_page_child_by_type(homepageid, type='page', start=None, limit=None, expand=None)
for page in children:

    page_id = page["id"]

    page1 = confluence.get_page_by_id(page_id=page_id,expand="body.storage")
    content = page1["body"]["storage"]["value"]
    title = page['title']

    #Labels
    #confluence.get_page_labels(page_id, prefix=None, start=None, limit=None)

    #Attachments
    directory = "attachments/" + page_id
    os.makedirs(directory, exist_ok=True)
    (result, log) = convert.convert(content)

    xwiki_page = create_xwki_page(wiki_space,title,parent,result)
    #exit(0)
    attachments = confluence.download_attachments_from_page(page_id, path=directory)
   
    with os.scandir(directory) as entries:
        for entry in entries:
            if entry.is_file():
                attach_file_to_page(wiki_space,title,entry.path,entry.name)
  

    parent = title