mirror of
https://hk.gh-proxy.com/https://github.com/CaptainCore/do.git
synced 2025-10-03 23:34:10 +08:00
👌 IMPROVE: Move reset-wp and reset-permissons under reset command
This commit is contained in:
parent
6a28be5977
commit
0cadaf1c39
3 changed files with 66 additions and 45 deletions
|
@ -1,9 +1,15 @@
|
|||
# ----------------------------------------------------
|
||||
# Reset Commands
|
||||
# Handles resetting WordPress components or permissions.
|
||||
# ----------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------
|
||||
# Resets the WordPress installation to a clean, default state.
|
||||
# ----------------------------------------------------
|
||||
function reset_site() {
|
||||
local admin_user="$1"
|
||||
local admin_email="$2"
|
||||
function reset_wp() {
|
||||
# This function now only accepts an optional email flag.
|
||||
# The admin user is selected interactively.
|
||||
local admin_email="$1"
|
||||
|
||||
# --- Pre-flight Checks ---
|
||||
if ! setup_wp_cli; then echo "❌ Error: WP-CLI not found." >&2; return 1; fi
|
||||
|
@ -11,8 +17,30 @@ function reset_site() {
|
|||
if ! command -v wget &>/dev/null; then echo "❌ Error: wget not found." >&2; return 1; fi
|
||||
if ! command -v unzip &>/dev/null; then echo "❌ Error: unzip not found." >&2; return 1; fi
|
||||
if ! command -v curl &>/dev/null; then echo "❌ Error: curl not found." >&2; return 1; fi
|
||||
if ! setup_gum; then echo "❌ Error: gum is required for the interactive admin picker." >&2; return 1; fi
|
||||
|
||||
echo "🚀 Starting WordPress Site Reset 🚀"
|
||||
|
||||
# --- Interactively Select Admin User ---
|
||||
echo "Fetching list of administrators..."
|
||||
local admin_users
|
||||
admin_users=$("$WP_CLI_CMD" user list --role=administrator --field=user_login --format=csv)
|
||||
|
||||
if [ -z "$admin_users" ]; then
|
||||
echo "❌ Error: No administrator users found to assign to the new installation." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local admin_user
|
||||
admin_user=$(echo "$admin_users" | "$GUM_CMD" choose --header "Select an administrator for the new installation")
|
||||
|
||||
if [ -z "$admin_user" ]; then
|
||||
echo "No administrator selected. Aborting reset."
|
||||
return 0
|
||||
fi
|
||||
echo "✅ Selected administrator: $admin_user"
|
||||
# --- End Select Admin User ---
|
||||
|
||||
echo "This is a destructive operation."
|
||||
# A 3-second countdown to allow the user to abort (Ctrl+C)
|
||||
for i in {3..1}; do echo -n "Continuing in $i... "; sleep 1; done; echo
|
||||
|
@ -21,10 +49,10 @@ function reset_site() {
|
|||
local url; url=$( "$WP_CLI_CMD" option get home --skip-plugins --skip-themes )
|
||||
local title; title=$( "$WP_CLI_CMD" option get blogname --skip-plugins --skip-themes )
|
||||
|
||||
# If admin_email is not supplied, get it from the current installation
|
||||
# If admin_email flag is not supplied, get it from the selected user.
|
||||
if [ -z "$admin_email" ]; then
|
||||
admin_email=$("$WP_CLI_CMD" option get admin_email --skip-plugins --skip-themes)
|
||||
echo "ℹ️ Admin email not provided. Using existing email: $admin_email"
|
||||
admin_email=$("$WP_CLI_CMD" user get "$admin_user" --field=user_email --format=csv)
|
||||
echo "ℹ️ Admin email not provided. Using email from selected user '$admin_user': $admin_email"
|
||||
fi
|
||||
|
||||
# --- Perform Reset ---
|
||||
|
@ -69,4 +97,14 @@ function reset_site() {
|
|||
echo "✅ WordPress reset complete!"
|
||||
echo " URL: $url"
|
||||
echo " Admin User: $admin_user"
|
||||
}
|
||||
}
|
||||
|
||||
# ----------------------------------------------------
|
||||
# Resets file and folder permissions to common defaults (755 for dirs, 644 for files).
|
||||
# ----------------------------------------------------
|
||||
function reset_permissions() {
|
||||
echo "Resetting file and folder permissions to defaults"
|
||||
find . -type d -exec chmod 755 {} \;
|
||||
find . -type f -exec chmod 644 {} \;
|
||||
echo "✅ Permissions have been reset."
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
# ----------------------------------------------------
|
||||
# Resets file and folder permissions to common defaults (755 for dirs, 644 for files).
|
||||
# ----------------------------------------------------
|
||||
function reset_permissions() {
|
||||
echo "Resetting file and folder permissions to defaults"
|
||||
find . -type d -exec chmod 755 {} \;
|
||||
find . -type f -exec chmod 644 {} \;
|
||||
echo "✅ Permissions have been reset."
|
||||
}
|
50
main
50
main
|
@ -789,20 +789,14 @@ function show_command_help() {
|
|||
echo "Arguments:"
|
||||
echo " [directory] (Optional) The directory to search in. Defaults to 'wp-content/'."
|
||||
;;
|
||||
reset-wp)
|
||||
echo "Resets the WordPress installation to a default state."
|
||||
reset)
|
||||
echo "Resets WordPress components or permissions."
|
||||
echo
|
||||
echo "Usage: _do reset-wp --admin_user=<username> [--admin_email=<email>]"
|
||||
echo "Usage: _do reset <subcommand> [arguments]"
|
||||
echo
|
||||
echo "Flags:"
|
||||
echo " --admin_user=<username> (Required) The username for the new administrator."
|
||||
echo " --admin_email=<email> (Optional) The email for the new administrator."
|
||||
echo " Defaults to the current site's admin email."
|
||||
;;
|
||||
reset-permissions)
|
||||
echo "Resets file and folder permissions to defaults (755 for dirs, 644 for files)."
|
||||
echo
|
||||
echo "Usage: _do reset-permissions"
|
||||
echo "Subcommands:"
|
||||
echo " wp Resets the WordPress installation to a default state."
|
||||
echo " permissions Resets file and folder permissions to defaults (755 for dirs, 644 for files)."
|
||||
;;
|
||||
suspend)
|
||||
echo "Activates or deactivates a suspend message shown to visitors."
|
||||
|
@ -903,8 +897,7 @@ function show_usage() {
|
|||
echo " install Installs helper plugins or premium plugins."
|
||||
echo " migrate Migrates a site from a backup URL or local file."
|
||||
echo " monitor Monitors server logs or errors in real-time."
|
||||
echo " reset-wp Resets the WordPress installation to a default state."
|
||||
echo " reset-permissions Resets file and folder permissions to defaults."
|
||||
echo " reset Resets WordPress components or permissions."
|
||||
echo " suspend Activates or deactivates a suspend message shown to visitors."
|
||||
echo " update Runs WordPress updates and logs the changes."
|
||||
echo " upgrade Upgrades this script to the latest version."
|
||||
|
@ -958,7 +951,6 @@ function main() {
|
|||
local update_urls_flag=""
|
||||
local now_flag=""
|
||||
local admin_user_flag=""
|
||||
local admin_email_flag=""
|
||||
local path_flag=""
|
||||
local all_files_flag=""
|
||||
local force_flag=""
|
||||
|
@ -999,10 +991,6 @@ function main() {
|
|||
admin_user_flag="${1#*=}"
|
||||
shift
|
||||
;;
|
||||
--admin_email=*)
|
||||
admin_email_flag="${1#*=}"
|
||||
shift
|
||||
;;
|
||||
--all)
|
||||
all_files_flag=true
|
||||
shift
|
||||
|
@ -1235,16 +1223,20 @@ function main() {
|
|||
php-tags)
|
||||
find_outdated_php_tags "${positional_args[1]}"
|
||||
;;
|
||||
reset-wp)
|
||||
if [[ -z "$admin_user_flag" ]]; then
|
||||
echo "Error: The 'reset-wp' command requires the --admin_user=<...> flag." >&2
|
||||
show_command_help "reset-wp"
|
||||
exit 1
|
||||
fi
|
||||
reset_site "$admin_user_flag" "$admin_email_flag"
|
||||
;;
|
||||
reset-permissions)
|
||||
reset_permissions
|
||||
reset)
|
||||
local subcommand="${positional_args[1]}"
|
||||
case "$subcommand" in
|
||||
wp)
|
||||
reset_wp "$admin_user_flag"
|
||||
;;
|
||||
permissions)
|
||||
reset_permissions
|
||||
;;
|
||||
*)
|
||||
show_command_help "reset"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
suspend)
|
||||
local arg1="${positional_args[1]}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue