Du ser en gammel version af denne side. Se den nuværende version.

Sammenlign med nuværende Vis sidehistorik

« Forrige Version 6 Næste »

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
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 create_xwki_page(confluence_page_id,title,parent_url,content):

    slug = title.replace(" ","")
    url = parent_url + "/spaces/" + slug + "/pages/WebHome"

    #print (title)
    print (url)
    
    xml = "<page xmlns=\"http://www.xwiki.org\">"
    xml = xml + "<title>" + title + "</title>"
    xml = xml + "<syntax>xwiki/2.1</syntax>"
    xml = xml + "<content>" +  escape(content) + "</content></page>"

    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)

    #exit(0)

    #Children
    children = confluence.get_page_child_by_type(confluence_page_id, 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
        #labels = confluence.get_page_labels(page_id, prefix=None, start=None, limit=None)
        #if labels:
        #    attach_labels_to_page(wiki_space,slug,labels)

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

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




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

    url = config.xwiki_url + "/rest/wikis/xwiki/spaces/" + wiki_space + "/pages/" + slug + "/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)

def attach_labels_to_page(wiki_space,slug,labels):

    url = config.xwiki_url + "/rest/wikis/xwiki/spaces/" + wiki_space + "/pages/" + slug + "/tags"

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

    xml = "<tags xmlns=\"http://www.xwiki.org\">"

    for label in labels:
        
        xml = xml + "<tag>" + label + "</tag>"

    xml = xml + "</tag>"

    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)


#Start on the XWiki
wiki_space = "Sandbox" 

#Start Space in Confluence
space_key = "ATLASSIAN"

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

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

xwiki_page = create_xwki_page(homepage_id,title, config.xwiki_url + "/rest/wikis/xwiki/spaces/Sandbox",result)


  • Ingen etiketter