#!/bin/bash
# Import unholy-nation-wiki.xml with content model fixes

XML_FILE="${1:-backup_tool/unholy-nation-wiki.xml}"
TEMP_XML="/tmp/unholy-nation-wiki-import.xml"

if [ ! -f "$XML_FILE" ]; then
    echo "Error: XML file not found: $XML_FILE"
    exit 1
fi

cd /var/www/unfiles/wiki

echo "Converting content models..."
sed 's/<model>Scribunto<\/model>/<model>wikitext<\/model>/g; s/<model>interactivemap<\/model>/<model>wikitext<\/model>/g' "$XML_FILE" > "$TEMP_XML"

echo "Importing XML..."
php maintenance/importDump.php "$TEMP_XML"

echo "Fixing Unholy_Nation_Wiki page with Main_Page content from database..."
php maintenance/getText.php "Main_Page" > /tmp/main_page_content.txt
php maintenance/edit.php -u admin "Unholy_Nation_Wiki" < /tmp/main_page_content.txt

echo "Running jobs..."
php maintenance/runJobs.php --maxjobs=50

echo "Done!"
