Skip to content

Commit f052bb1

Browse files
CopilotPDowney
andauthored
plan: add shared fetch_wp_salts function with retry/validation
Agent-Logs-Url: https://github.com/EngineScript/EngineScript/sessions/29220c6a-26cb-4309-8b44-e054afd721f5 Co-authored-by: PDowney <[email protected]>
1 parent e19faaf commit f052bb1

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to EngineScript will be documented in this file.
44

55
Changes are organized by date, with the most recent changes listed first.
66

7+
## 2026-04-11
8+
9+
### 🔧 VHOST IMPORT BUG FIXES & IMPROVEMENTS
10+
11+
- Updated the single-zip database file detection in `scripts/functions/vhost/vhost-import.sh` to search for both `*.sql` and `*.sql.gz` patterns, so compressed database dumps are correctly found and imported instead of failing silently.
12+
- Removed the duplicate `URL_VALIDATION_REGEX` argument from the `prompt_input` call for the Site URL field; validation is now handled exclusively by the subsequent `validate_url` function call, eliminating redundant logic.
13+
- Added `DB_CHARSET="${DB_CHARSET_VALIDATED}"` after the charset `case` statement so `DB_CHARSET` is always the validated, lowercase value when used in the `wp-config.php` `sed` replacement, preventing a potential mismatch if the user supplies a mixed-case charset.
14+
- Improved the WordPress salt fetch error message to also suggest retrying the import later if the WordPress.org API is temporarily unavailable, rather than only mentioning local network/firewall issues.
15+
- Simplified `run_url_search_replace_if_present` to run `wp search-replace` directly with `--report-changed-only`, removing the preliminary `wp db search` pre-check that unnecessarily doubled full-table scans on large databases.
16+
717
## 2026-04-10
818

919
### 🔧 VHOST IMPORT CODE QUALITY IMPROVEMENTS

scripts/functions/vhost/vhost-import.sh

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ if [[ "$IMPORT_FORMAT" == "single_zip" ]]; then
257257
EXTRACT_STATUS=1
258258
fi
259259
if [[ $EXTRACT_STATUS -eq 0 ]]; then
260-
# Find exactly one .sql file within the extracted content (deterministic order)
261-
mapfile -d '' -t DB_SOURCE_CANDIDATES < <(find "${WP_EXTRACTED_PATH}" -maxdepth 1 -type f -name "*.sql" -print0 | sort -z)
260+
# Find exactly one database dump file (.sql or .sql.gz) within the extracted content (deterministic order)
261+
mapfile -d '' -t DB_SOURCE_CANDIDATES < <(find "${WP_EXTRACTED_PATH}" -maxdepth 1 -type f \( -name "*.sql" -o -name "*.sql.gz" \) -print0 | sort -z)
262262
if [[ ${#DB_SOURCE_CANDIDATES[@]} -ne 1 ]]; then
263-
echo "FAILED: Could not find exactly one .sql file within the extracted single zip content in ${WP_EXTRACTED_PATH}"
263+
echo "FAILED: Could not find exactly one database file (.sql or .sql.gz) within the extracted single zip content in ${WP_EXTRACTED_PATH}"
264264
EXTRACT_STATUS=1 # Mark as failure
265265
else
266266
DB_SOURCE_PATH="${DB_SOURCE_CANDIDATES[0]}" # Set DB path for single_zip format
@@ -379,7 +379,7 @@ while true; do
379379

380380
# Site URL input with validation
381381
while true; do
382-
new_site_url=$(prompt_input "Enter correct Site URL" "${SITE_URL}" 300 "${URL_VALIDATION_REGEX}")
382+
new_site_url=$(prompt_input "Enter correct Site URL" "${SITE_URL}" 300)
383383
if [[ -n "$new_site_url" ]]; then
384384
if validate_url "$new_site_url"; then
385385
SITE_URL="$new_site_url"
@@ -497,6 +497,7 @@ case "${DB_CHARSET_VALIDATED}" in
497497
exit 1
498498
;;
499499
esac
500+
DB_CHARSET="${DB_CHARSET_VALIDATED}"
500501
DB_COLLATION="${DB_CHARSET_VALIDATED}_unicode_ci"
501502
if [[ ! "${DB}" =~ ^[A-Za-z0-9_]+$ ]]; then
502503
echo "Error: Generated database name contains invalid characters: ${DB}" >&2
@@ -557,7 +558,7 @@ configure_redis "${SITE_URL}" "${TARGET_WP_PATH}/wp-config.php"
557558
# WP Salt Creation (Generate new salts)
558559
echo "Generating new WordPress salts..."
559560
SALT=$(curl --fail --silent --show-error --location --retry 3 --connect-timeout 10 --max-time 30 "https://api.wordpress.org/secret-key/1.1/salt/") || {
560-
echo "Error: Failed to fetch WordPress salts from api.wordpress.org. Please check your internet connection, DNS/firewall/proxy settings, and try running the import again." >&2
561+
echo "Error: Failed to fetch WordPress salts from api.wordpress.org. Please check your internet connection and DNS/firewall/proxy settings. If the issue persists, the WordPress.org API may be temporarily unavailable—please retry the import later." >&2
561562
exit 1
562563
}
563564

@@ -619,13 +620,8 @@ HTTP_ORIGINAL_URL="${HTTPS_ORIGINAL_URL/#https:\/\//http://}"
619620
run_url_search_replace_if_present() {
620621
local original_url="$1"
621622

622-
# Only run expensive full-table replacements when the source URL is present.
623-
# Use `wp db search --quiet` exit status directly to avoid an extra grep pass.
624-
if wp db search "${original_url}" --all-tables --allow-root --quiet 2>/dev/null; then
625-
wp search-replace "${original_url}" "${NEW_URL}" --all-tables --report-changed-only --allow-root
626-
else
627-
echo "Skipping search-replace: '${original_url}' not found in database text columns."
628-
fi
623+
# Run search-replace directly; --report-changed-only will emit output only for changed rows.
624+
wp search-replace "${original_url}" "${NEW_URL}" --all-tables --report-changed-only --allow-root
629625
return
630626
}
631627

0 commit comments

Comments
 (0)