Skip to content

Commit

Permalink
Create partial-reset-wiki.py
Browse files Browse the repository at this point in the history
  • Loading branch information
RhinosF1 authored May 18, 2024
1 parent 533a108 commit aa3ebc9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions miraheze/salt/mwcli/partial-reset-wiki.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import argparse
from miraheze.salt.utils import *

def reset_wiki(wiki: str) -> None:
# Step 1: Get the db cluster for the wiki

try:
wiki_cluster = get_db_cluster(wiki)
except (KeyError, IndexError):
print(f'Error: Unable to determine the db cluster for {wiki}')
sys.exit(1)

# Step 2: Execute deleteWiki.php
execute_salt_command(salt_command=generate_salt_command('mwtask181', f'mwscript extensions/CreateWiki/deleteWiki.php loginwiki --deletewiki {wiki} --delete {os.getlogin()}'))

# Step 3: Backup and drop database
execute_salt_command(salt_command=generate_salt_command(wiki_cluster, f"sudo -i mysqldump {wiki} > {wiki}.sql'"))
execute_salt_command(salt_command=generate_salt_command(wiki_cluster, f"sudo -i mysql -e 'DROP DATABASE {wiki}'"))


def main() -> None:
parser = argparse.ArgumentParser(description='Executes the commands needed to reset wikis')
parser.add_argument('--wiki', required=True, help='Old wiki database name')

args = parser.parse_args()
reset_wiki(args.wiki)


if __name__ == '__main__':
main()

0 comments on commit aa3ebc9

Please sign in to comment.