Skip to content

Commit c274b57

Browse files
authored
Merge pull request #167 from wp-cli/bump-travis-server-to-xenial
Bump Travis CI OS from `trusty` to `xenial`
2 parents 9bbc2cf + 62d7855 commit c274b57

File tree

3 files changed

+79
-8
lines changed

3 files changed

+79
-8
lines changed

.travis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
os: linux
2-
dist: trusty
2+
dist: xenial
33

44
language: php
55
php: 7.4
66

7+
services:
8+
- mysql
9+
710
notifications:
811
email:
912
on_success: never
@@ -71,6 +74,7 @@ jobs:
7174
- stage: test
7275
php: 5.6
7376
env: WP_VERSION=3.7.11
77+
dist: trusty
7478
- stage: test
7579
php: 5.6
7680
env: WP_VERSION=trunk

features/db-query.feature

+29
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,32 @@ Feature: Query the database with WordPress' MySQL config
9292
"""
9393
Debug (db): Running shell command: /usr/bin/env mysql --no-defaults --no-auto-rehash
9494
"""
95+
96+
Scenario: SQL modes do not include any of the modes incompatible with WordPress
97+
Given a WP install
98+
99+
When I try `wp db query 'SELECT @@SESSION.sql_mode;' --debug`
100+
Then STDOUT should not contain:
101+
"""
102+
NO_ZERO_DATE
103+
"""
104+
And STDOUT should not contain:
105+
"""
106+
ONLY_FULL_GROUP_BY
107+
"""
108+
And STDOUT should not contain:
109+
"""
110+
STRICT_TRANS_TABLES
111+
"""
112+
And STDOUT should not contain:
113+
"""
114+
STRICT_ALL_TABLES
115+
"""
116+
And STDOUT should not contain:
117+
"""
118+
TRADITIONAL
119+
"""
120+
And STDOUT should not contain:
121+
"""
122+
ANSI
123+
"""

src/DB_Command.php

+45-7
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public function check( $_, $assoc_args ) {
234234
$assoc_args
235235
);
236236

237+
WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
237238
WP_CLI::success( 'Database checked.' );
238239
}
239240

@@ -277,6 +278,7 @@ public function optimize( $_, $assoc_args ) {
277278
$assoc_args
278279
);
279280

281+
WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
280282
WP_CLI::success( 'Database optimized.' );
281283
}
282284

@@ -320,6 +322,7 @@ public function repair( $_, $assoc_args ) {
320322
$assoc_args
321323
);
322324

325+
WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
323326
WP_CLI::success( 'Database repaired.' );
324327
}
325328

@@ -354,7 +357,7 @@ public function repair( $_, $assoc_args ) {
354357
*
355358
* @alias connect
356359
*/
357-
public function cli( $args, $assoc_args ) {
360+
public function cli( $_, $assoc_args ) {
358361

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

369+
WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
366370
self::run( $command, $assoc_args );
367371
}
368372

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

443+
WP_CLI::debug( 'Associative arguments: ' . json_encode( $assoc_args ), 'db' );
439444
self::run( $command, $assoc_args );
440445
}
441446

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

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

586592
if ( $porcelain ) {
@@ -654,6 +660,7 @@ public function import( $args, $assoc_args ) {
654660

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

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

@@ -984,7 +991,7 @@ public function size( $args, $assoc_args ) {
984991
}
985992

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

1462+
WP_CLI::debug( "Query: {$query}", 'db' );
1463+
14551464
self::run(
14561465
sprintf(
14571466
'/usr/bin/env mysql%s --no-auto-rehash',
@@ -1783,12 +1792,32 @@ protected function get_sql_mode_query( $assoc_args, $modes = [] ) {
17831792

17841793
$modes = array_change_key_case( $modes, CASE_UPPER );
17851794

1795+
$is_mode_adaptation_needed = false;
17861796
foreach ( $modes as $i => $mode ) {
17871797
if ( in_array( $mode, $this->sql_incompatible_modes, true ) ) {
17881798
unset( $modes[ $i ] );
1799+
$is_mode_adaptation_needed = true;
17891800
}
17901801
}
17911802

1803+
if ( ! $is_mode_adaptation_needed ) {
1804+
WP_CLI::debug(
1805+
sprintf(
1806+
'SQL modes look fine: %s',
1807+
json_encode( $modes )
1808+
)
1809+
);
1810+
return '';
1811+
}
1812+
1813+
WP_CLI::debug(
1814+
sprintf(
1815+
'SQL mode adaptation is needed: %s => %s',
1816+
json_encode( $this->get_current_sql_modes( $assoc_args ) ),
1817+
json_encode( $modes )
1818+
)
1819+
);
1820+
17921821
$modes_str = implode( ',', $modes );
17931822

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

1806-
// Make sure the provided argument don't interfere with the expected
1835+
// Make sure the provided arguments don't interfere with the expected
18071836
// output here.
1808-
unset( $assoc_args['column-names'], $assoc_args['html'] );
1837+
$args = $assoc_args;
1838+
unset(
1839+
$args['column-names'],
1840+
$args['result-format'],
1841+
$args['json'],
1842+
$args['html'],
1843+
$args['table'],
1844+
$args['tabbed'],
1845+
$args['vertical']
1846+
);
18091847

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

@@ -1831,7 +1869,7 @@ protected function get_current_sql_modes( $assoc_args ) {
18311869
$modes = array_filter(
18321870
array_map(
18331871
'trim',
1834-
preg_split( "/\r\n|\n|\r/", $stdout )
1872+
preg_split( "/\r\n|\n|\r|,/", $stdout )
18351873
)
18361874
);
18371875
}

0 commit comments

Comments
 (0)