64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
import subprocess
|
|
|
|
|
|
class Setup:
|
|
|
|
def __init__(self, plugin_prefix):
|
|
self.plugin_prefix = plugin_prefix
|
|
# TODO: pass full path or target extraction folder path
|
|
self.sql_file = 'database.sql'
|
|
|
|
def __check_wp_cli():
|
|
"""Checks if WP-CLI is installed."""
|
|
try:
|
|
subprocess.call(["wp", "--info"])
|
|
return True
|
|
except Exception:
|
|
return False
|
|
|
|
def __download_core():
|
|
"""Download the core files, skip the content"""
|
|
print('wp core download --force --skip-content --version=')
|
|
|
|
def __format_mysql(self):
|
|
"""Replace the prefix changes in the database"""
|
|
with open(self.sql_file, 'r') as file:
|
|
content = file.read()
|
|
|
|
# Perform the replacement
|
|
modified_content = content.replace(self.plugin_prefix, "wp_")
|
|
|
|
# Write the modified content back to the file
|
|
with open(self.sql_file, 'w') as file:
|
|
file.write(modified_content)
|
|
|
|
def __move_folders():
|
|
print('')
|
|
|
|
def __write_config():
|
|
"""Write a new wp-config.php file based on package.json"""
|
|
# TODO: Test for wp-config.php
|
|
# TODO: Shuffle salts
|
|
print('wp config shuffle-salts')
|
|
# TODO: Setup database information
|
|
|
|
def __import_mysql():
|
|
"""Import the database to the server after being processed for prefix"""
|
|
print('wp db import database.sql')
|
|
|
|
def wp_setup(self):
|
|
"""Initial setup for restore, call functions in order of need"""
|
|
self.__format_mysql()
|
|
self.__move_folders()
|
|
|
|
# Depending on if WP Cli is installed
|
|
manual = False if self.__check_wp_cli() else True
|
|
|
|
# File management
|
|
self.__download_core(manual)
|
|
|
|
# TODO: Get data from input
|
|
self.__write_config()
|
|
self.__import_mysql(manual)
|
|
|
|
return 'Completed' |