Skip to content

Commit 61f52b0

Browse files
committed
Adds script to remove all connatix data...
1 parent f25bec7 commit 61f52b0

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/bin/bash
2+
3+
# Default environment.
4+
FUNC=""
5+
COMMNAND=''
6+
TARGETED_ENV='dev-env exec --slug 3013-production'
7+
8+
############################################################
9+
# Usage #
10+
############################################################
11+
_command_usage() {
12+
printf "\n\t- %% %s <env-option> <env-command>" "$FUNC"
13+
printf "\n\t- Where <env-option> can be:"
14+
printf "\n\t\t- 0 => Use second input as option."
15+
printf "\n\t\t- 1 => Use Default environment (dev-cms)."
16+
printf "\n\t\t- 2 => Use Preprod environment."
17+
printf "\n\t\t- 3 => Use Production environment."
18+
printf "\n\t\t- * => Use Local Develop Environment."
19+
printf "\n\t- %% %s [-h]\n" "$FUNC"
20+
}
21+
22+
############################################################
23+
# Help #
24+
############################################################
25+
_help() {
26+
# Display Help
27+
printf "\nCommand used to remove Connatix Content from a WordPress VIP Go environment."
28+
printf "\n--------------------------------------------------------------------------------------------------------------\n"
29+
printf "\nSoftware Dependencies:"
30+
printf "\n\tNode:\t\t\tv16.0.0+"
31+
printf "\n\tnpm:\t\t\tv8.1.4+"
32+
printf "\n\t@automattic/vip:\t2.3.0+"
33+
printf "\n\tDocker:\t\t\tv20.10.8+"
34+
printf "\n\nSyntax:"
35+
_command_usage
36+
printf "Options:"
37+
printf "\n\t-h Print this Help."
38+
printf "\n\nExamples:"
39+
printf "\n\t- %% ./%s" "$FUNC"
40+
printf "\n\t- %% ./%s 0 '%s'" "$FUNC" "dev-env exec --slug 3013-production"
41+
printf "\n\t- %% bash %s 1" "$FUNC"
42+
printf "\n--------------------------------------------------------------------------------------------------------------\n"
43+
}
44+
45+
_set_func_called() {
46+
if [ -z "$FUNC" ]; then
47+
FUNC="$1"
48+
fi
49+
}
50+
51+
# The mapping is as follows:
52+
# - 0 => Use second input as option.
53+
# - 1 => Use Local Develop Environment.
54+
# - 2 => Use Preprod environment.
55+
# - 3 => Use Production environment.
56+
# - * => Use Default environment (dev-cms).
57+
environment_specifier() {
58+
if [ $# -lt 1 ]; then
59+
printf "\nUsage:"
60+
_command_usage
61+
COMMNAND="usage";
62+
return 1;
63+
fi
64+
65+
# Check if help is an option only if this is not a redundant call.
66+
if [ "$1" != "x" ]; then
67+
while getopts ":h" option; do
68+
case $option in
69+
h) # Display Help
70+
_help
71+
COMMNAND="help";
72+
return 0
73+
;;
74+
*)
75+
;;
76+
esac
77+
done
78+
fi
79+
80+
# Set the TARGETED_ENV variable.
81+
case "$1" in
82+
0)
83+
PASSED_ENV="$2"
84+
if [ -n "$PASSED_ENV" ]; then
85+
TARGETED_ENV="$PASSED_ENV"
86+
fi
87+
;;
88+
89+
1)
90+
TARGETED_ENV='@3013.develop'
91+
;;
92+
93+
2)
94+
TARGETED_ENV='@3013.preprod'
95+
;;
96+
97+
3)
98+
TARGETED_ENV='@3013.production'
99+
;;
100+
101+
*)
102+
;;
103+
esac
104+
}
105+
106+
delete_all_connatix_videos() {
107+
_set_func_called "$0"
108+
environment_specifier "$@"
109+
if [ -n "$COMMNAND" ]; then
110+
return 0;
111+
fi
112+
printf "Deleting Connatix Videos on env[%s]\n" "$TARGETED_ENV"
113+
114+
i=0
115+
until [ "$i" -gt 93 ]
116+
do
117+
printf "Loop number %s on env[%s]\n" "$i" "$TARGETED_ENV"
118+
vip "$TARGETED_ENV" -- wp post delete --force $(vip $TARGETED_ENV -- wp post list --posts_per_page=999 --post_type='connatix-videos' --format=ids)
119+
((i=i+1))
120+
done
121+
}
122+
123+
delete_all_connatix_playlists() {
124+
_set_func_called "$0"
125+
environment_specifier "$@"
126+
if [ -n "$COMMNAND" ]; then
127+
return 0;
128+
fi
129+
130+
printf "Deleting Connatix Playlists on env[%s]\n" "$TARGETED_ENV"
131+
vip "$TARGETED_ENV" -- wp post delete --force $(vip $TARGETED_ENV -- wp post list --posts_per_page=999 --post_type='connatix-playlists' --format=ids)
132+
}
133+
134+
delete_all_connatix_players() {
135+
_set_func_called "$0"
136+
environment_specifier "$@"
137+
if [ -n "$COMMNAND" ]; then
138+
return 0;
139+
fi
140+
141+
printf "Deleting Connatix Players on env[%s]\n" "$TARGETED_ENV"
142+
vip "$TARGETED_ENV" -- wp term delete 'connatix-player' $(vip $TARGETED_ENV -- wp term list 'connatix-player' --format=ids)
143+
}
144+
145+
delete_all_connatix_content() {
146+
_set_func_called "$0"
147+
environment_specifier "$@"
148+
if [ -n "$COMMNAND" ]; then
149+
return 0;
150+
fi
151+
152+
printf "Deleting all Connatix Data on env[%s]\n" "$TARGETED_ENV\n"
153+
delete_all_connatix_players 'x'
154+
delete_all_connatix_playlists 'x'
155+
delete_all_connatix_videos 'x'
156+
}

0 commit comments

Comments
 (0)