From d1559c5bb87ba7d218397d6b6f97bd846655fa87 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Fri, 31 Mar 2023 10:17:34 +0200 Subject: [PATCH 1/6] Add cleanup tool (WIP) --- .ddev/commands/web/wp-cleanup | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 .ddev/commands/web/wp-cleanup diff --git a/.ddev/commands/web/wp-cleanup b/.ddev/commands/web/wp-cleanup new file mode 100755 index 000000000..1cd25678c --- /dev/null +++ b/.ddev/commands/web/wp-cleanup @@ -0,0 +1,27 @@ +#!/bin/bash + +help-panel(){ + echo -e "-d [post_type] Delete all posts" + echo -e "\tExample: -d shop_order,product" +} + +delete-post(){ + for post in $(wp post list --post_type=$1 --format=ids --path=.ddev/wordpress); do + wp post delete $post --force --path=.ddev/wordpress + done +} + +declare -i parameter_counter=0 + +while getopts "d:h" arg; do + case $arg in + d) post_type=$OPTARG; let parameter_counter+=1;; + h) help-panel;; + esac +done + +if [ $parameter_counter -eq 1 ]; then + delete-post $post_type +else + help-panel +fi From e856369a0634fa98a4ac9492323db3931b99314a Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Fri, 31 Mar 2023 10:21:56 +0200 Subject: [PATCH 2/6] Format bash code --- .ddev/commands/web/wp-cleanup | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/.ddev/commands/web/wp-cleanup b/.ddev/commands/web/wp-cleanup index 1cd25678c..4b1d87e10 100755 --- a/.ddev/commands/web/wp-cleanup +++ b/.ddev/commands/web/wp-cleanup @@ -1,27 +1,30 @@ #!/bin/bash -help-panel(){ - echo -e "-d [post_type] Delete all posts" - echo -e "\tExample: -d shop_order,product" +help-panel() { + echo -e "-d [post_type] Delete all posts" + echo -e "\tExample: -d shop_order,product" } -delete-post(){ +delete-post() { for post in $(wp post list --post_type=$1 --format=ids --path=.ddev/wordpress); do - wp post delete $post --force --path=.ddev/wordpress - done + wp post delete $post --force --path=.ddev/wordpress + done } declare -i parameter_counter=0 while getopts "d:h" arg; do - case $arg in - d) post_type=$OPTARG; let parameter_counter+=1;; - h) help-panel;; - esac + case $arg in + d) + post_type=$OPTARG + let parameter_counter+=1 + ;; + h) help-panel ;; + esac done if [ $parameter_counter -eq 1 ]; then - delete-post $post_type + delete-post $post_type else - help-panel + help-panel fi From 07fd68ce2ccd29e9c5f298797ab1450d6dc26de6 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Fri, 31 Mar 2023 12:02:56 +0200 Subject: [PATCH 3/6] Remove all logs --- .ddev/commands/web/wp-cleanup | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/.ddev/commands/web/wp-cleanup b/.ddev/commands/web/wp-cleanup index 4b1d87e10..c11e526cc 100755 --- a/.ddev/commands/web/wp-cleanup +++ b/.ddev/commands/web/wp-cleanup @@ -1,30 +1,32 @@ #!/bin/bash help-panel() { - echo -e "-d [post_type] Delete all posts" - echo -e "\tExample: -d shop_order,product" + echo -e "-p [post type] Delete all posts" + echo -e "\tExample: -p shop_order,product" + echo -e "-l [wp-content path] Delete all logs" + echo -e "\tExample: -l uploads/wc-logs" } -delete-post() { +delete-posts() { for post in $(wp post list --post_type=$1 --format=ids --path=.ddev/wordpress); do wp post delete $post --force --path=.ddev/wordpress done } -declare -i parameter_counter=0 +delete-logs() { + rm .ddev/wordpress/wp-content/$1/*.log +} -while getopts "d:h" arg; do +declare -i param_counter=0 + +while getopts "d:l:h" arg; do case $arg in - d) - post_type=$OPTARG - let parameter_counter+=1 - ;; + d) delete-posts $OPTARG; param_counter+=1 ;; + l) delete-logs $OPTARG; param_counter+=1 ;; h) help-panel ;; esac done -if [ $parameter_counter -eq 1 ]; then - delete-post $post_type -else +if [ $param_counter -eq 0 ]; then help-panel fi From 4440dd302e60736cf7a30ef532a7dffef68492af Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Fri, 31 Mar 2023 12:07:12 +0200 Subject: [PATCH 4/6] bash format --- .ddev/commands/web/wp-cleanup | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.ddev/commands/web/wp-cleanup b/.ddev/commands/web/wp-cleanup index c11e526cc..c21250363 100755 --- a/.ddev/commands/web/wp-cleanup +++ b/.ddev/commands/web/wp-cleanup @@ -21,8 +21,14 @@ declare -i param_counter=0 while getopts "d:l:h" arg; do case $arg in - d) delete-posts $OPTARG; param_counter+=1 ;; - l) delete-logs $OPTARG; param_counter+=1 ;; + d) + delete-posts $OPTARG + param_counter+=1 + ;; + l) + delete-logs $OPTARG + param_counter+=1 + ;; h) help-panel ;; esac done From de38334e624fa34f60fd40bd5af3eeff242bfdc8 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Fri, 31 Mar 2023 12:20:54 +0200 Subject: [PATCH 5/6] Fix delete posts param --- .ddev/commands/web/wp-cleanup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.ddev/commands/web/wp-cleanup b/.ddev/commands/web/wp-cleanup index c21250363..f7e692301 100755 --- a/.ddev/commands/web/wp-cleanup +++ b/.ddev/commands/web/wp-cleanup @@ -19,9 +19,9 @@ delete-logs() { declare -i param_counter=0 -while getopts "d:l:h" arg; do +while getopts "p:l:h" arg; do case $arg in - d) + p) delete-posts $OPTARG param_counter+=1 ;; From ddf315d71a439b1158b202010c04db110d1c34f4 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Fri, 28 Apr 2023 09:18:28 +0200 Subject: [PATCH 6/6] Rename help method --- .ddev/commands/web/wp-cleanup | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.ddev/commands/web/wp-cleanup b/.ddev/commands/web/wp-cleanup index f7e692301..c6b3172d1 100755 --- a/.ddev/commands/web/wp-cleanup +++ b/.ddev/commands/web/wp-cleanup @@ -1,10 +1,10 @@ #!/bin/bash -help-panel() { - echo -e "-p [post type] Delete all posts" - echo -e "\tExample: -p shop_order,product" - echo -e "-l [wp-content path] Delete all logs" - echo -e "\tExample: -l uploads/wc-logs" +show-help() { + echo -e "\nDelete all posts -p [post type]" + echo -e "\tExample: ddev wp-cleanup -p shop_order,product" + echo -e "\nDelete all logs -l [wp-content path]" + echo -e "\tExample: ddev wp-cleanup -l uploads/wc-logs\n" } delete-posts() { @@ -29,10 +29,10 @@ while getopts "p:l:h" arg; do delete-logs $OPTARG param_counter+=1 ;; - h) help-panel ;; + h) show-help ;; esac done if [ $param_counter -eq 0 ]; then - help-panel + show-help fi