Skip to content

Commit 21696dc

Browse files
authored
Merge pull request #1201 from xwp/bugfix/remove-unnecessary-db-calls
"Install::verify_db()" removed.
2 parents 5fd40b7 + c98fad9 commit 21696dc

File tree

4 files changed

+33
-102
lines changed

4 files changed

+33
-102
lines changed

classes/class-install.php

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ public function __construct( $plugin ) {
7171
$this->db_version = $this->get_db_version();
7272
$this->stream_url = self_admin_url( $this->plugin->admin->admin_parent_page . '&page=' . $this->plugin->admin->settings_page_slug );
7373

74-
// Check DB and display an admin notice if there are tables missing.
75-
add_action( 'init', array( $this, 'verify_db' ) );
76-
77-
// Install the plugin.
78-
add_action( 'wp_stream_before_db_notices', array( $this, 'check' ) );
79-
8074
register_activation_hook( $this->plugin->locations['plugin'], array( $this, 'check' ) );
8175
}
8276

@@ -137,87 +131,6 @@ public function check() {
137131
$this->update_db_option();
138132
}
139133

140-
/**
141-
* Verify that the required DB tables exists
142-
*
143-
* @return void
144-
*/
145-
public function verify_db() {
146-
/**
147-
* Filter will halt install() if set to true
148-
*
149-
* @param bool
150-
*
151-
* @return bool
152-
*/
153-
if ( apply_filters( 'wp_stream_no_tables', false ) ) {
154-
return;
155-
}
156-
157-
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
158-
require_once ABSPATH . '/wp-admin/includes/plugin.php';
159-
}
160-
161-
/**
162-
* Fires before admin notices are triggered for missing database tables.
163-
*/
164-
do_action( 'wp_stream_before_db_notices' );
165-
166-
global $wpdb;
167-
168-
$database_message = '';
169-
$uninstall_message = '';
170-
171-
// Check if all needed DB is present.
172-
$missing_tables = array();
173-
174-
foreach ( $this->plugin->db->get_table_names() as $table_name ) {
175-
$table_search = $wpdb->get_var(
176-
$wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name )
177-
);
178-
if ( $table_search !== $table_name ) {
179-
$missing_tables[] = $table_name;
180-
}
181-
}
182-
183-
if ( $missing_tables ) {
184-
$database_message .= sprintf(
185-
'%s <strong>%s</strong>',
186-
_n(
187-
'The following table is not present in the WordPress database:',
188-
'The following tables are not present in the WordPress database:',
189-
count( $missing_tables ),
190-
'stream'
191-
),
192-
esc_html( implode( ', ', $missing_tables ) )
193-
);
194-
}
195-
196-
if ( $this->plugin->is_network_activated() && current_user_can( 'manage_network_plugins' ) ) {
197-
$uninstall_message = sprintf(
198-
/* translators: %#$s: HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">") */
199-
__( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
200-
'<a href="' . network_admin_url( 'plugins.php#stream' ) . '">',
201-
'</a>'
202-
);
203-
} elseif ( current_user_can( 'activate_plugins' ) ) {
204-
$uninstall_message = sprintf(
205-
/* translators: %#$s: HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">") */
206-
__( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
207-
'<a href="' . admin_url( 'plugins.php#stream' ) . '">',
208-
'</a>'
209-
);
210-
}
211-
212-
if ( ! empty( $database_message ) ) {
213-
$this->plugin->admin->notice( $database_message );
214-
215-
if ( ! empty( $uninstall_message ) ) {
216-
$this->plugin->admin->notice( $uninstall_message );
217-
}
218-
}
219-
}
220-
221134
/**
222135
* Register a routine to be called when stream or a stream connector has been updated
223136
* It works by comparing the current version with the version previously stored in the database.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
"build-containers": "docker-compose --file docker-compose.build.yml build",
4747
"push-containers": "docker-compose --file docker-compose.build.yml push",
4848
"stop-all": "docker stop $(docker ps -a -q)",
49-
"cli": "docker-compose run --rm --user $(id -u) wordpress xwp_wait db_phpunit:3306 -t 60 --",
50-
"vcli": "vagrant ssh -- docker-compose -f /vagrant/docker-compose.yml run --rm --user $(id -u) wordpress xwp_wait db_phpunit:3306 -t 60 --",
49+
"cli": "docker-compose run --rm --user $(id -u) wordpress xwp_wait db_phpunit:3306 -s -t 300 --",
50+
"vcli": "vagrant ssh -- docker-compose -f /vagrant/docker-compose.yml run --rm --user $(id -u) wordpress xwp_wait db_phpunit:3306 -s -t 300 --",
5151
"phpunit": "npm run cli -- composer test --working-dir=wp-content/plugins/stream-src",
5252
"phpunit-multisite": "npm run cli -- composer test-multisite --working-dir=wp-content/plugins/stream-src",
5353
"vphpunit": "npm run vcli -- composer test --working-dir=wp-content/plugins/stream-src",

tests/bootstrap.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,49 @@ function xwp_filter_active_plugins_for_phpunit( $active_plugins ) {
4444
function() {
4545
// Manually load the plugin.
4646
require dirname( __DIR__ ) . '/stream.php';
47+
48+
// Install database.
49+
$plugin = wp_stream_get_instance();
50+
$plugin->install->check();
4751
}
4852
);
53+
4954
function xwp_manually_load_mercator() {
5055
define( 'MERCATOR_SKIP_CHECKS', true );
5156
require WPMU_PLUGIN_DIR . '/mercator/mercator.php';
5257
}
5358

5459
tests_add_filter( 'muplugins_loaded', 'xwp_manually_load_mercator' );
5560

61+
function xwp_install_edd() {
62+
// Install Easy Digital Downloads
63+
edd_install();
64+
65+
global $current_user, $edd_options;
66+
67+
$edd_options = get_option( 'edd_settings' );
68+
69+
$current_user = new WP_User(1);
70+
$current_user->set_role('administrator');
71+
wp_update_user( array( 'ID' => 1, 'first_name' => 'Admin', 'last_name' => 'User' ) );
72+
add_filter( 'edd_log_email_errors', '__return_false' );
73+
74+
add_filter(
75+
'pre_http_request',
76+
function( $status = false, $args = array(), $url = '') {
77+
return new WP_Error( 'no_reqs_in_unit_tests', __( 'HTTP Requests disabled for unit tests', 'easy-digital-downloads' ) );
78+
}
79+
);
80+
}
81+
5682
// @see https://core.trac.wordpress.org/browser/trunk/tests/phpunit/includes/bootstrap.php
5783
require $_tests_dir . '/includes/bootstrap.php';
5884

85+
define( 'EDD_USE_PHP_SESSIONS', false );
86+
define( 'WP_USE_THEMES', false );
87+
activate_plugin( 'easy-digital-downloads/easy-digital-downloads.php' );
88+
xwp_install_edd();
89+
5990
require __DIR__ . '/testcase.php';
6091

6192
// Base class for future tests

tests/tests/connectors/test-class-connector-edd.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@
1010
namespace WP_Stream;
1111

1212
class Test_WP_Stream_Connector_EDD extends WP_StreamTestCase {
13-
/**
14-
* Runs before all tests
15-
*/
16-
public static function wpSetUpBeforeClass() {
17-
global $wpdb;
18-
19-
$suppress = $wpdb->suppress_errors();
20-
21-
edd_install();
22-
23-
$wpdb->suppress_errors( $suppress );
24-
}
25-
2613
/**
2714
* Runs before each test
2815
*/

0 commit comments

Comments
 (0)