Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makeservices: easywp delete tables option #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions makeservices/easywp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ if [[ -z "$sqlpass" ]]; then
fi
echo "SQL set up and the password can be found in wp-config.php ..."

tables=$(mysql --user="$USER" --password="$sqlpass" --execute="show tables" "$USER" | grep -E "^wp_" || echo "")
if ! [[ -z "$tables" ]]; then
echo
echo -e "\033[33mThere appears to be an existing WordPress installation. Would you like to clean the database?\033[00m\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print out the name of the tables to be deleted in here too? Then at least it might be clear if it's deleting tables that it shouldn't.

I'm unclear if this is too much information for the user, but given this is deleting those tables, it seems reasonable to me to list them first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's pretty reasonable to delete everything that starts with wp_ without listing them. We don't really want to overload users.

read -rp "Do you want to continue? [y/N] " wordpresskiller
wordpresskiller=${wordpresskiller,,}
if ! [[ "$wordpresskiller" =~ ^(yes|y) ]]; then
echo "If you want to run this script and keep the tables intact, rename the existing tables from wp_* to something else."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it would be useful before asking the user if they want to delete everything than at the stage when they have shied away from it, although it's useful here too I suppose so that they know what to do to continue to the later steps in the script.

exit 0
fi

echo "$tables" | tr ' ' '\n' | while read -r table; do
mysql --user="$USER" --password="$sqlpass" --execute="DROP TABLE $table" "$USER"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use mysqldump to back up the tables before dropping them.

done
fi

# Install WordPress and create config file
wp core download
wp config create --dbname="$user" --dbuser="$user" --dbpass="$sqlpass" --dbhost=mysql --dbcharset=utf8mb4
Expand Down