Skip to content

Commit

Permalink
makeservices: easywp delete tables option
Browse files Browse the repository at this point in the history
Helpful if the user has an old instance of wordpress that they aren't
interested in.
  • Loading branch information
kkuehlz committed Aug 28, 2019
1 parent 13ff417 commit a6cd9ff
Showing 1 changed file with 16 additions and 0 deletions.
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"
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."
exit 0
fi

echo $tables | tr ' ' '\n' | while read table; do
mysql --user="$USER" --password="$sqlpass" --execute="DROP TABLE $table" "$USER"
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

0 comments on commit a6cd9ff

Please sign in to comment.