Skip to content

Commit 779f0a8

Browse files
authored
Merge pull request #227 from EngineScript/copilot/rename-seen-old-php-vers
fix(php-update): remove underscore prefixes, fix multi-version summary messages
2 parents 73ffb33 + a008420 commit 779f0a8

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

scripts/update/php-update.sh

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ fi
3636

3737
# Auto-detect currently installed PHP-FPM version
3838
OLD_PHP_VERS=()
39-
declare -A _SEEN_OLD_PHP_VERS=()
39+
declare -A SEEN_OLD_PHP_VERS=()
4040
for ver in "${SUPPORTED_PHP_VERSIONS[@]}"; do
4141
if [[ "${ver}" != "${NEW_PHP_VER}" ]] && dpkg -l | grep -q "php${ver}-fpm"; then
42-
if [[ -z "${_SEEN_OLD_PHP_VERS["${ver}"]+x}" ]]; then
42+
if [[ -z "${SEEN_OLD_PHP_VERS["${ver}"]+x}" ]]; then
4343
OLD_PHP_VERS+=("${ver}")
44-
_SEEN_OLD_PHP_VERS["${ver}"]=1
44+
SEEN_OLD_PHP_VERS["${ver}"]=1
4545
fi
4646
fi
4747
done
@@ -133,33 +133,33 @@ echo "Updating Nginx configuration for PHP ${NEW_PHP_VER}..."
133133

134134
# Update php-fpm.conf
135135
if [[ -f "/etc/nginx/globals/php-fpm.conf" ]]; then
136-
for _OLD_VER in "${MIGRATION_SOURCE_PHP_VERS[@]}"; do
137-
sed -E -i "s|php${_OLD_VER}(-fpm)?|php${NEW_PHP_VER}\1|g" "/etc/nginx/globals/php-fpm.conf"
136+
for OLD_VER in "${MIGRATION_SOURCE_PHP_VERS[@]}"; do
137+
sed -E -i "s|php${OLD_VER}(-fpm)?|php${NEW_PHP_VER}\1|g" "/etc/nginx/globals/php-fpm.conf"
138138
done
139139
fi
140140

141141
# Update all nginx site configurations
142142
for config_file in /etc/nginx/sites-available/*; do
143143
if [[ -f "$config_file" ]]; then
144-
for _OLD_VER in "${MIGRATION_SOURCE_PHP_VERS[@]}"; do
145-
sed -E -i "s|php${_OLD_VER}(-fpm)?|php${NEW_PHP_VER}\1|g" "$config_file"
144+
for OLD_VER in "${MIGRATION_SOURCE_PHP_VERS[@]}"; do
145+
sed -E -i "s|php${OLD_VER}(-fpm)?|php${NEW_PHP_VER}\1|g" "$config_file"
146146
done
147147
fi
148148
done
149149

150150
# Update phpSysInfo configuration
151151
if [[ -f "/var/www/admin/tools/phpsysinfo/phpsysinfo.ini" ]]; then
152152
echo "Updating phpSysInfo configuration..."
153-
for _OLD_VER in "${MIGRATION_SOURCE_PHP_VERS[@]}"; do
154-
sed -E -i "s|php${_OLD_VER}(-fpm)?|php${NEW_PHP_VER}\1|g" "/var/www/admin/tools/phpsysinfo/phpsysinfo.ini"
153+
for OLD_VER in "${MIGRATION_SOURCE_PHP_VERS[@]}"; do
154+
sed -E -i "s|php${OLD_VER}(-fpm)?|php${NEW_PHP_VER}\1|g" "/var/www/admin/tools/phpsysinfo/phpsysinfo.ini"
155155
done
156156
fi
157157

158158
# Update admin control panel API configuration
159159
if [[ -f "/var/www/admin/control-panel/api.php" ]]; then
160160
echo "Updating admin control panel API configuration..."
161-
for _OLD_VER in "${MIGRATION_SOURCE_PHP_VERS[@]}"; do
162-
sed -E -i "s|php${_OLD_VER}(-fpm)?|php${NEW_PHP_VER}\1|g" "/var/www/admin/control-panel/api.php"
161+
for OLD_VER in "${MIGRATION_SOURCE_PHP_VERS[@]}"; do
162+
sed -E -i "s|php${OLD_VER}(-fpm)?|php${NEW_PHP_VER}\1|g" "/var/www/admin/control-panel/api.php"
163163
done
164164
fi
165165

@@ -232,13 +232,17 @@ echo ""
232232
echo ""
233233
echo "============================================================="
234234
echo ""
235-
echo "PHP upgrade from ${OLD_PHP_VER} to ${NEW_PHP_VER} completed successfully."
235+
echo "PHP upgrade from ${MIGRATION_SOURCE_PHP_VERS[*]} to ${NEW_PHP_VER} completed successfully."
236236
echo ""
237237
echo "Changes made:"
238238
echo " - Installed PHP ${NEW_PHP_VER} and extensions"
239239
echo " - Applied EngineScript configuration for PHP ${NEW_PHP_VER}"
240240
echo " - Updated Nginx configuration"
241-
echo " - Removed PHP ${OLD_PHP_VER} installation"
241+
if [[ ${#MIGRATION_SOURCE_PHP_VERS[@]} -gt 0 ]]; then
242+
echo " - Removed PHP version(s): ${MIGRATION_SOURCE_PHP_VERS[*]}"
243+
else
244+
echo " - Removed PHP ${OLD_PHP_VER} installation"
245+
fi
242246
echo ""
243247
echo "============================================================="
244248
echo ""

0 commit comments

Comments
 (0)