Skip to content

Commit

Permalink
Update rename-wiki.py
Browse files Browse the repository at this point in the history
  • Loading branch information
RhinosF1 authored Jan 7, 2024
1 parent c7c4e27 commit b3fa78e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions modules/mediawiki/files/cookbooks/rename-wiki.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess
import sys
import argparse
from typing import Optional, TypedDict

Expand Down Expand Up @@ -29,20 +30,22 @@ def execute_salt_command(salt_command: str, shell: bool = False, stdout: Optiona
return subprocess.run(salt_command, shell=shell, stdout=stdout, text=text)


def get_db_cluster(oldwiki_db: str) -> Optional[str]:
def get_db_cluster(oldwiki_db: str) -> str:
command = generate_salt_command('db131*', f'cmd.run "mysql -e \'SELECT wiki_dbcluster FROM mhglobal.cw_wikis WHERE wiki_dbname = "{oldwiki_db}" \' "')
result = execute_salt_command(salt_command=command, shell=True, stdout=subprocess.PIPE, text=True)
cluster_name = result.stdout.strip()
return db_clusters.get(cluster_name)
return db_clusters[cluster_name]


def rename_wiki(oldwiki_db: str, newwiki_db: str) -> None:
# Step 1: Get the db cluster for the old wiki dbname
oldwiki_cluster = get_db_cluster(oldwiki_db)

if not oldwiki_cluster:
try:
oldwiki_cluster = get_db_cluster(oldwiki_db)
except KeyError:
print(f'Error: Unable to determine the db cluster for {oldwiki_db}')
return
sys.exit(1)

# Step 2: Execute SQL commands for rename
execute_salt_command(salt_command=generate_salt_command(oldwiki_cluster, f'mysqldump {oldwiki_db} > oldwikidb.sql'))
Expand Down

0 comments on commit b3fa78e

Please sign in to comment.