Skip to content

Bump Travis CI OS from trusty to xenial #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
os: linux
dist: trusty
dist: xenial

language: php
php: 7.4

services:
- mysql

notifications:
email:
on_success: never
Expand Down Expand Up @@ -71,6 +74,7 @@ jobs:
- stage: test
php: 5.6
env: WP_VERSION=3.7.11
dist: trusty
- stage: test
php: 5.6
env: WP_VERSION=trunk
Expand Down
29 changes: 29 additions & 0 deletions features/db-query.feature
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,32 @@ Feature: Query the database with WordPress' MySQL config
"""
Debug (db): Running shell command: /usr/bin/env mysql --no-defaults --no-auto-rehash
"""

Scenario: SQL modes do not include any of the modes incompatible with WordPress
Given a WP install

When I try `wp db query 'SELECT @@SESSION.sql_mode;' --debug`
Then STDOUT should not contain:
"""
NO_ZERO_DATE
"""
And STDOUT should not contain:
"""
ONLY_FULL_GROUP_BY
"""
And STDOUT should not contain:
"""
STRICT_TRANS_TABLES
"""
And STDOUT should not contain:
"""
STRICT_ALL_TABLES
"""
And STDOUT should not contain:
"""
TRADITIONAL
"""
And STDOUT should not contain:
"""
ANSI
"""
52 changes: 45 additions & 7 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public function check( $_, $assoc_args ) {
$assoc_args
);

WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
WP_CLI::success( 'Database checked.' );
}

Expand Down Expand Up @@ -277,6 +278,7 @@ public function optimize( $_, $assoc_args ) {
$assoc_args
);

WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
WP_CLI::success( 'Database optimized.' );
}

Expand Down Expand Up @@ -320,6 +322,7 @@ public function repair( $_, $assoc_args ) {
$assoc_args
);

WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
WP_CLI::success( 'Database repaired.' );
}

Expand Down Expand Up @@ -354,7 +357,7 @@ public function repair( $_, $assoc_args ) {
*
* @alias connect
*/
public function cli( $args, $assoc_args ) {
public function cli( $_, $assoc_args ) {

$command = sprintf( '/usr/bin/env mysql%s --no-auto-rehash', $this->get_defaults_flag_string( $assoc_args ) );
WP_CLI::debug( "Running shell command: {$command}", 'db' );
Expand All @@ -363,6 +366,7 @@ public function cli( $args, $assoc_args ) {
$assoc_args['database'] = DB_NAME;
}

WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
self::run( $command, $assoc_args );
}

Expand Down Expand Up @@ -436,6 +440,7 @@ public function query( $args, $assoc_args ) {
$assoc_args['execute'] = $this->get_sql_mode_query( $assoc_args ) . $assoc_args['execute'];
}

WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
self::run( $command, $assoc_args );
}

Expand Down Expand Up @@ -581,6 +586,7 @@ public function export( $args, $assoc_args ) {
// Remove parameters not needed for SQL run.
unset( $assoc_args['porcelain'] );

WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
self::run( $escaped_command, $assoc_args );

if ( $porcelain ) {
Expand Down Expand Up @@ -654,6 +660,7 @@ public function import( $args, $assoc_args ) {

$command = sprintf( '/usr/bin/env mysql%s --no-auto-rehash', $this->get_defaults_flag_string( $assoc_args ) );
WP_CLI::debug( "Running shell command: {$command}", 'db' );
WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );

self::run( $command, $mysql_args );

Expand Down Expand Up @@ -984,7 +991,7 @@ public function size( $args, $assoc_args ) {
}

if ( ! empty( $size_format ) && ! $tables && ! $format && ! $human_readable && true !== $all_tables && true !== $all_tables_with_prefix ) {
WP_CLI::Line( filter_var( $rows[0]['Size'], FILTER_SANITIZE_NUMBER_INT ) );
WP_CLI::line( filter_var( $rows[0]['Size'], FILTER_SANITIZE_NUMBER_INT ) );
} else {
// Display the rows.
$args = [
Expand Down Expand Up @@ -1442,7 +1449,7 @@ private static function get_create_query() {
/**
* Run a single query via the 'mysql' binary.
*
* This includes necessary setup to make sure the queries behave similar
* This includes the necessary setup to make sure the queries behave similar
* to what WPDB produces.
*
* @param string $query Query to execute.
Expand All @@ -1452,6 +1459,8 @@ protected function run_query( $query, $assoc_args = [] ) {
// Ensure that the SQL mode is compatible with WPDB.
$query = $this->get_sql_mode_query( $assoc_args ) . $query;

WP_CLI::debug( "Query: {$query}", 'db' );

self::run(
sprintf(
'/usr/bin/env mysql%s --no-auto-rehash',
Expand Down Expand Up @@ -1783,12 +1792,32 @@ protected function get_sql_mode_query( $assoc_args, $modes = [] ) {

$modes = array_change_key_case( $modes, CASE_UPPER );

$is_mode_adaptation_needed = false;
foreach ( $modes as $i => $mode ) {
if ( in_array( $mode, $this->sql_incompatible_modes, true ) ) {
unset( $modes[ $i ] );
$is_mode_adaptation_needed = true;
}
}

if ( ! $is_mode_adaptation_needed ) {
WP_CLI::debug(
sprintf(
'SQL modes look fine: %s',
json_encode( $modes )
)
);
return '';
}

WP_CLI::debug(
sprintf(
'SQL mode adaptation is needed: %s => %s',
json_encode( $this->get_current_sql_modes( $assoc_args ) ),
json_encode( $modes )
)
);

$modes_str = implode( ',', $modes );

return "SET SESSION sql_mode='{$modes_str}';";
Expand All @@ -1803,9 +1832,18 @@ protected function get_sql_mode_query( $assoc_args, $modes = [] ) {
protected function get_current_sql_modes( $assoc_args ) {
static $modes = null;

// Make sure the provided argument don't interfere with the expected
// Make sure the provided arguments don't interfere with the expected
// output here.
unset( $assoc_args['column-names'], $assoc_args['html'] );
$args = $assoc_args;
unset(
$args['column-names'],
$args['result-format'],
$args['json'],
$args['html'],
$args['table'],
$args['tabbed'],
$args['vertical']
);

if ( null === $modes ) {
$modes = [];
Expand All @@ -1815,7 +1853,7 @@ protected function get_current_sql_modes( $assoc_args ) {
'/usr/bin/env mysql%s --no-auto-rehash --batch --skip-column-names',
$this->get_defaults_flag_string( $assoc_args )
),
array_merge( $assoc_args, [ 'execute' => 'SELECT @@SESSION.sql_mode' ] ),
array_merge( $args, [ 'execute' => 'SELECT @@SESSION.sql_mode' ] ),
false
);

Expand All @@ -1831,7 +1869,7 @@ protected function get_current_sql_modes( $assoc_args ) {
$modes = array_filter(
array_map(
'trim',
preg_split( "/\r\n|\n|\r/", $stdout )
preg_split( "/\r\n|\n|\r|,/", $stdout )
)
);
}
Expand Down