-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.php
More file actions
84 lines (67 loc) · 2.63 KB
/
install.php
File metadata and controls
84 lines (67 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Installs WordPress for the purpose of the unit-tests
*
* @todo Reuse the init/load code in init.php
*/
error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT );
$multisite = in_array( 'run_ms_tests', $argv, true );
define( 'WP_INSTALLING', true );
/*
* Cron tries to make an HTTP request to the site, which always fails,
* because tests are run in CLI mode only.
*/
define( 'DISABLE_WP_CRON', true );
require_once __DIR__.'/includes/load-wp.php';
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
require_once ABSPATH . 'wp-includes/class-wpdb.php';
/*
* default_storage_engine and storage_engine are the same option, but storage_engine
* was deprecated in MySQL (and MariaDB) 5.5.3, and removed in 5.7.
*/
global $wpdb;
if ( version_compare( $wpdb->db_version(), '5.5.3', '>=' ) ) {
$wpdb->query( 'SET default_storage_engine = InnoDB' );
} else {
$wpdb->query( 'SET storage_engine = InnoDB' );
}
$wpdb->select( DB_NAME, $wpdb->dbh );
echo 'Installing...' . PHP_EOL;
$wpdb->query( 'SET foreign_key_checks = 0' );
foreach ( $wpdb->tables() as $table => $prefixed_table ) {
//phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
}
foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) {
//phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DROP TABLE IF EXISTS $prefixed_table" );
// We need to create references to ms global tables.
if ( $multisite ) {
$wpdb->$table = $prefixed_table;
}
}
$wpdb->query( 'SET foreign_key_checks = 1' );
function _set_default_permalink_structure_for_tests() {
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
}
// Prefill a permalink structure so that WP doesn't try to determine one itself.
add_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' );
// Delete dummy permalink structure, as prefilled above.
if ( ! is_multisite() ) {
delete_option( 'permalink_structure' );
}
remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
if ( $multisite ) {
global $wp_rewrite;
echo 'Installing network...' . PHP_EOL;
define( 'WP_INSTALLING_NETWORK', true );
$title = WP_TESTS_TITLE . ' Network';
$subdomain_install = false;
install_network();
$error = populate_network( 1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install );
if ( is_wp_error( $error ) ) {
wp_die( $error );
}
$wp_rewrite->set_permalink_structure( '' );
}