Skip to content

Commit 4e2919d

Browse files
authored
Merge pull request #15 from creativecommons/prep-for-migrate-with-attachments
Prep for migration with attachments
2 parents f1d6bb5 + a100f01 commit 4e2919d

File tree

3 files changed

+75
-23
lines changed

3 files changed

+75
-23
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# WordPress variables
2-
WP_VERSION=6.2
2+
WP_VERSION=6.3
33

44
# Setup WordPress variables
55
WP_ADMIN_EMAIL=

docker-compose.yml

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ services:
5353
- ../mp:/var/www/git/mp:ro
5454
# WordPress
5555
- wp_data:/var/www/html
56+
# Migration cache
57+
- ./cache:/var/www/html/cache:ro
5658

5759
database:
5860
container_name: cc-wordpress-db
@@ -118,7 +120,10 @@ services:
118120
- backend
119121
user: xfs
120122
volumes:
123+
# WordPress
121124
- wp_data:/var/www/html
125+
# Migration cache
126+
- ./cache:/var/www/html/cache:ro
122127

123128
volumes:
124129
db_data:

setup-wordpress.sh

+69-22
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ trap '_es=${?};
2626
source .env
2727
OPT_DATE_FORMAT=Y-m-d
2828
OPT_TIME_FORMAT='H:i'
29-
OPT_DEFAULT_COMMENT_STATUS=''
29+
OPT_DEFAULT_COMMENT_STATUS=closed
3030
PLUGINS_ACTIVATE='
3131
acf-menu-chooser
3232
advanced-custom-fields
@@ -81,12 +81,54 @@ activate_themes() {
8181
echo
8282
}
8383

84+
8485
composer_install() {
8586
header 'Composer install'
8687
docker compose run --rm composer install 2>/dev/null
8788
echo
8889
}
8990

91+
92+
container_info() {
93+
local _key _val IFS
94+
header 'Container info'
95+
96+
# composer
97+
printf "\033[1m%s\033[0m container - %s\n" \
98+
'composer' 'A Dependency Manager for PHP'
99+
container_print 'Composer version' "$(docker compose run --rm composer \
100+
--no-ansi --version 2>/dev/null | sed -e's/^Composer version //')"
101+
echo
102+
103+
# web
104+
printf "\033[1m%s\033[0m container - %s\n" 'web' 'WordPress'
105+
print_var WEB_WP_URL
106+
print_var WEB_WP_DIR
107+
container_print 'WordPress version:' "$(wpcli core version)"
108+
echo
109+
110+
# wordpress-cli
111+
printf "\033[1m%s\033[0m container - %s\n" \
112+
'wordpress-cli' 'The command line interface for WordPress'
113+
IFS=$'\n'
114+
for _line in $(wpcli --info | sort)
115+
do
116+
_key="${_line%%:*}"
117+
# '| xargs' is used to trim whitespace
118+
_val="$( echo "${_line#*:}" | xargs)"
119+
[[ -n "${_val}" ]] || continue
120+
[[ "${_key}" =~ ^WP-CLI ]] || continue
121+
container_print "${_key}:" "${_val}"
122+
done
123+
echo
124+
}
125+
126+
127+
container_print() {
128+
printf "\033[36m%19s\033[0m %s\n" "${1}" "${2}"
129+
}
130+
131+
90132
enable_permalinks() {
91133
header 'Enable post name permalinks'
92134
if wpcli --no-color --quiet rewrite list 2> /dev/null \
@@ -108,8 +150,8 @@ error_exit() {
108150

109151

110152
header() {
111-
# Print 80 character wide black on white heading
112-
printf "\033[1m\033[7m %-80s\033[0m\n" "${@}"
153+
# Print 80 character wide black on white heading with time
154+
printf "\033[1m\033[7m %-71s$(date '+%T') \033[0m\n" "${@}"
113155
}
114156

115157

@@ -119,9 +161,9 @@ install_wordpress() {
119161
if [[ -n "${WP_ADMIN_EMAIL}" ]] && [[ -n "${WP_ADMIN_EMAIL}" ]] \
120162
&& [[ -n "${WP_ADMIN_EMAIL}" ]]
121163
then
122-
echo "WP_ADMIN_EMAIL: ${WP_ADMIN_EMAIL}"
123-
echo "WP_ADMIN_USER: ${WP_ADMIN_USER}"
124-
echo "WP_ADMIN_PASS: ${WP_ADMIN_PASS}"
164+
print_var WP_ADMIN_EMAIL
165+
print_var WP_ADMIN_USER
166+
print_var WP_ADMIN_PASS
125167
else
126168
_err='The following variables must be set in .env (see .env.example):'
127169
_err="${_err} WP_ADMIN_EMAIL, WP_ADMIN_USER, WP_ADMIN_PASS"
@@ -149,6 +191,19 @@ no_op() {
149191
}
150192

151193

194+
optimize_tables() {
195+
header 'Optimize WordPress database tables'
196+
wpcli db optimize --color \
197+
| sed -e'/Table does not support optimize/d' -e'/^status : OK/d'
198+
echo
199+
}
200+
201+
202+
print_var() {
203+
printf "\033[36m%19s\033[0m %s\n" "${1}:" "${!1}"
204+
}
205+
206+
152207
remove_themes() {
153208
local _theme
154209
header 'Remove extraneous WordPress themes'
@@ -173,45 +228,36 @@ update_wordpress_options() {
173228
_date_format=$(wpcli option get date_format)
174229
if [[ "${OPT_DATE_FORMAT}" != "${_date_format}" ]]
175230
then
176-
echo "Update date_format: '${OPT_DATE_FORMAT}'"
231+
echo "Update date_format: ${OPT_DATE_FORMAT}"
177232
wpcli option update date_format "${OPT_DATE_FORMAT}"
178233
else
179-
no_op "date_format is already: '${OPT_DATE_FORMAT}'"
234+
no_op "date_format: ${OPT_DATE_FORMAT}"
180235
fi
181236

182237
_default_comment_status=$(wpcli option get default_comment_status)
183238
if [[ "${OPT_DEFAULT_COMMENT_STATUS}" != "${_default_comment_status}" ]]
184239
then
185-
echo -n "Update default_comment_status: ${OPT_DEFAULT_COMMENT_STATUS}"
186-
echo ' (disabled)'
240+
echo "Update default_comment_status: ${OPT_DEFAULT_COMMENT_STATUS}"
187241
wpcli option update default_comment_status \
188242
"${OPT_DEFAULT_COMMENT_STATUS}"
189243
else
190-
_noop='default_comment_status is already:'
191-
_noop="${_noop} '${OPT_DEFAULT_COMMENT_STATUS}' (disabled)"
244+
_noop="default_comment_status: ${OPT_DEFAULT_COMMENT_STATUS}"
192245
no_op "${_noop}"
193246
fi
194247

195248
_time_format=$(wpcli option get time_format)
196249
if [[ "${OPT_TIME_FORMAT}" != "${_time_format}" ]]
197250
then
198-
echo "Update time_format: '${OPT_TIME_FORMAT}'"
251+
echo "Update time_format: ${OPT_TIME_FORMAT}"
199252
wpcli option update time_format "${OPT_TIME_FORMAT}"
200253
else
201-
no_op "time_format is already: '${OPT_TIME_FORMAT}'"
254+
no_op "time_format: ${OPT_TIME_FORMAT}"
202255
fi
203256

204257
echo
205258
}
206259

207260

208-
utils_info() {
209-
header 'Utilities info'
210-
docker compose run --rm composer --version 2>/dev/null
211-
wpcli --info
212-
echo
213-
}
214-
215261
wordpress_update_db() {
216262
header 'Update WordPress database'
217263
wpcli core update-db
@@ -247,7 +293,7 @@ wpcli() {
247293

248294
#### MAIN #####################################################################
249295

250-
utils_info
296+
container_info
251297
composer_install
252298
install_wordpress
253299
update_wordpress_options
@@ -256,5 +302,6 @@ activate_plugins
256302
activate_themes
257303
enable_permalinks
258304
wordpress_update_db
305+
optimize_tables
259306
wordpress_db_check
260307
wordpress_status

0 commit comments

Comments
 (0)