Skip to content

Commit 3d72e7e

Browse files
authored
Workflow Changes
1 parent c517338 commit 3d72e7e

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

bin/db.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Fallback MySQL database driver for WordPress tests
4+
*
5+
* This is a simplified version of the wp-mysqli driver, used as a fallback
6+
* when the download from the original source fails.
7+
*
8+
* @package Simple_WP_Optimizer
9+
*/
10+
11+
if ( ! defined( 'WP_USE_EXT_MYSQL' ) ) {
12+
define( 'WP_USE_EXT_MYSQL', false );
13+
}
14+
15+
// Ensure mysqli extension is available
16+
if ( ! function_exists( 'mysqli_connect' ) ) {
17+
trigger_error( 'This PHP installation does not have the mysqli extension enabled. Please enable it or contact your hosting provider.', E_USER_ERROR );
18+
}
19+
20+
// Force using mysqli
21+
if ( defined( 'WP_USE_EXT_MYSQL' ) && WP_USE_EXT_MYSQL ) {
22+
$GLOBALS['wpdb'] = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
23+
} else {
24+
// Nothing to do - WordPress 3.9+ uses mysqli by default
25+
}

bin/install-wp-tests.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,48 @@ install_wp() {
171171
fi
172172

173173
echo "Downloading extra MySQL database driver..."
174+
# Create directory if it doesn't exist
175+
mkdir -p $WP_CORE_DIR/wp-content/
176+
177+
# Try to download the db.php file with verification
174178
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
175179

180+
# Check if download was successful and file is not empty
181+
if [ ! -s "$WP_CORE_DIR/wp-content/db.php" ]; then
182+
echo "Warning: Downloaded db.php file is empty or download failed."
183+
184+
# Check if we have a local copy in the repository
185+
if [ -f "bin/db.php" ]; then
186+
echo "Using local fallback copy of db.php from bin/db.php"
187+
cp bin/db.php $WP_CORE_DIR/wp-content/db.php
188+
elif [ -f "${0%/*}/db.php" ]; then
189+
# Try to find db.php in the same directory as the script
190+
echo "Using local fallback copy of db.php from script directory"
191+
cp "${0%/*}/db.php" $WP_CORE_DIR/wp-content/db.php
192+
else
193+
# Create a simple db.php file inline as last resort
194+
echo "Creating a minimal db.php file as fallback"
195+
cat > $WP_CORE_DIR/wp-content/db.php << 'EOL'
196+
<?php
197+
/**
198+
* Fallback database driver to ensure tests can run
199+
*/
200+
if ( ! defined( 'WP_USE_EXT_MYSQL' ) ) {
201+
define( 'WP_USE_EXT_MYSQL', false );
202+
}
203+
EOL
204+
fi
205+
206+
# Verify that db.php exists and is not empty
207+
if [ ! -s "$WP_CORE_DIR/wp-content/db.php" ]; then
208+
echo "Error: Failed to create a valid db.php file. Tests may not work correctly."
209+
else
210+
echo "Fallback db.php file created successfully."
211+
fi
212+
else
213+
echo "db.php downloaded successfully."
214+
fi
215+
176216
echo "WordPress core installation complete!"
177217
}
178218

0 commit comments

Comments
 (0)