Skip to content

Commit a17fa51

Browse files
Merge branch 'WordPress:trunk' into fix-wp-tests-charset-etc
2 parents bf6a7ac + 783790c commit a17fa51

12 files changed

Lines changed: 43 additions & 100 deletions

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
],
6666
"wp-test-php": [
6767
"@wp-test-ensure-env @no_additional_args",
68-
"rm -rf wordpress/src/wp-content/database/.ht.sqlite.php @no_additional_args",
68+
"rm -rf wordpress/src/wp-content/database/.ht.sqlite @no_additional_args",
6969
"npm --prefix wordpress run test:php -- @additional_args"
7070
],
7171
"wp-test-e2e": [
@@ -74,7 +74,7 @@
7474
],
7575
"wp-test-clean": [
7676
"npm --prefix wordpress run env:clean",
77-
"rm -rf wordpress/src/wp-content/database/.ht.sqlite.php"
77+
"rm -rf wordpress/src/wp-content/database/.ht.sqlite"
7878
]
7979
}
8080
}

constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
if ( defined( 'DB_FILE' ) ) {
4949
define( 'FQDB', FQDBDIR . DB_FILE );
5050
} else {
51-
define( 'FQDB', FQDBDIR . '.ht.sqlite.php' );
51+
define( 'FQDB', FQDBDIR . '.ht.sqlite' );
5252
}
5353
}
5454

db.copy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ add_action(
4646
if ( ! function_exists( 'activate_plugin' ) ) {
4747
require_once ABSPATH . 'wp-admin/includes/plugin.php';
4848
}
49-
if ( is_plugin_inactive( '{SQLITE_PLUGIN}' ) ) {
49+
50+
$plugin_path = WP_PLUGIN_DIR . '/' . '{SQLITE_PLUGIN}';
51+
52+
if ( file_exists( $plugin_path ) && is_plugin_inactive( '{SQLITE_PLUGIN}' ) ) {
5053
// If `activate_plugin()` returns a value other than null (like WP_Error),
5154
// the plugin could not be found. Try with a hardcoded string,
5255
// because that probably means the file was directly copy-pasted.

load.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: SQLite Database Integration
44
* Description: SQLite database driver drop-in.
55
* Author: The WordPress Team
6-
* Version: 2.2.19
6+
* Version: 2.2.20
77
* Requires PHP: 7.2
88
* Textdomain: sqlite-database-integration
99
*

php-polyfills.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22
/**
3-
* Polyfills for php 7 & 8 functions
3+
* Polyfills for PHP 8.0 string functions.
4+
*
5+
* Implementation follows the Symfony polyfill-php80 package.
6+
*
7+
* @see https://github.com/symfony/polyfill-php80
48
*
59
* @package wp-sqlite-integration
610
*/
@@ -17,7 +21,7 @@
1721
* @return bool
1822
*/
1923
function str_starts_with( string $haystack, string $needle ) {
20-
return empty( $needle ) || 0 === strpos( $haystack, $needle );
24+
return 0 === strncmp( $haystack, $needle, strlen( $needle ) );
2125
}
2226
}
2327

@@ -33,7 +37,7 @@ function str_starts_with( string $haystack, string $needle ) {
3337
* @return bool
3438
*/
3539
function str_contains( string $haystack, string $needle ) {
36-
return empty( $needle ) || false !== strpos( $haystack, $needle );
40+
return '' === $needle || false !== strpos( $haystack, $needle );
3741
}
3842
}
3943

@@ -49,6 +53,16 @@ function str_contains( string $haystack, string $needle ) {
4953
* @return bool
5054
*/
5155
function str_ends_with( string $haystack, string $needle ) {
52-
return empty( $needle ) || substr( $haystack, -strlen( $needle ) === $needle );
56+
if ( '' === $needle || $needle === $haystack ) {
57+
return true;
58+
}
59+
60+
if ( '' === $haystack ) {
61+
return false;
62+
}
63+
64+
$needle_length = strlen( $needle );
65+
66+
return $needle_length <= strlen( $haystack ) && 0 === substr_compare( $haystack, $needle, -$needle_length );
5367
}
5468
}

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributors: wordpressdotorg, aristath, janjakes, zieladam, berislav.grgic
44
Requires at least: 6.4
55
Tested up to: 6.9
66
Requires PHP: 7.2
7-
Stable tag: 2.2.19
7+
Stable tag: 2.2.20
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010
Tags: performance, database

tests/WP_SQLite_Driver_Tests.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ public function setUp(): void {
1515
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
1616

1717
$this->engine = new WP_SQLite_Driver(
18-
new WP_SQLite_Connection(
19-
array(
20-
'pdo' => $this->sqlite,
21-
'application_id' => 42, // Test application ID.
22-
)
23-
),
18+
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
2419
'wp'
2520
);
2621
$this->engine->query(
@@ -56,11 +51,6 @@ private function assertQueryError( $sql, $error_message ) {
5651
$this->assertSame( $error_message, $exception->getMessage() );
5752
}
5853

59-
public function testApplicationID() {
60-
$app_id = $this->sqlite->query( 'PRAGMA application_id' )->fetchColumn();
61-
$this->assertSame( 42, (int) $app_id );
62-
}
63-
6454
public function testRegexp() {
6555
$this->assertQuery(
6656
"INSERT INTO _options (option_name, option_value) VALUES ('rss_0123456789abcdef0123456789abcdef', '1');"

tests/bootstrap.php

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
<?php
22

3-
// Configure the test environment.
4-
error_reporting( E_ALL );
5-
define( 'FQDB', ':memory:' );
6-
define( 'FQDBDIR', __DIR__ . '/../testdb' );
7-
3+
require_once __DIR__ . '/../php-polyfills.php';
84
require_once __DIR__ . '/wp-sqlite-schema.php';
9-
require_once __DIR__ . '/../constants.php';
105
require_once __DIR__ . '/../wp-pdo-mysql-on-sqlite.php';
116
require_once __DIR__ . '/../wp-includes/sqlite/class-wp-sqlite-query-rewriter.php';
127
require_once __DIR__ . '/../wp-includes/sqlite/class-wp-sqlite-lexer.php';
@@ -20,6 +15,11 @@
2015
define( 'WP_SQLITE_UNSAFE_ENABLE_UNSUPPORTED_VERSIONS', true );
2116
}
2217

18+
// Configure the test environment.
19+
error_reporting( E_ALL );
20+
define( 'FQDB', ':memory:' );
21+
define( 'FQDBDIR', __DIR__ . '/../testdb' );
22+
2323
// Polyfill WPDB globals.
2424
$GLOBALS['table_prefix'] = 'wptests_';
2525
$GLOBALS['wpdb'] = new class() {
@@ -51,57 +51,6 @@ function apply_filters( $tag, $value, ...$args ) {
5151
}
5252
}
5353

54-
/**
55-
* Polyfills for php 7 & 8 functions
56-
*/
57-
58-
if ( ! function_exists( 'str_starts_with' ) ) {
59-
/**
60-
* Check if a string starts with a specific substring.
61-
*
62-
* @param string $haystack The string to search in.
63-
* @param string $needle The string to search for.
64-
*
65-
* @see https://www.php.net/manual/en/function.str-starts-with
66-
*
67-
* @return bool
68-
*/
69-
function str_starts_with( string $haystack, string $needle ) {
70-
return empty( $needle ) || 0 === strpos( $haystack, $needle );
71-
}
72-
}
73-
74-
if ( ! function_exists( 'str_contains' ) ) {
75-
/**
76-
* Check if a string contains a specific substring.
77-
*
78-
* @param string $haystack The string to search in.
79-
* @param string $needle The string to search for.
80-
*
81-
* @see https://www.php.net/manual/en/function.str-contains
82-
*
83-
* @return bool
84-
*/
85-
function str_contains( string $haystack, string $needle ) {
86-
return empty( $needle ) || false !== strpos( $haystack, $needle );
87-
}
88-
}
89-
90-
if ( ! function_exists( 'str_ends_with' ) ) {
91-
/**
92-
* Check if a string ends with a specific substring.
93-
*
94-
* @param string $haystack The string to search in.
95-
* @param string $needle The string to search for.
96-
*
97-
* @see https://www.php.net/manual/en/function.str-ends-with
98-
*
99-
* @return bool
100-
*/
101-
function str_ends_with( string $haystack, string $needle ) {
102-
return empty( $needle ) || substr( $haystack, -strlen( $needle ) ) === $needle;
103-
}
104-
}
10554
if ( extension_loaded( 'mbstring' ) ) {
10655

10756
if ( ! function_exists( 'mb_str_starts_with' ) ) {

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
*
66
* This constant needs to be updated on plugin release!
77
*/
8-
define( 'SQLITE_DRIVER_VERSION', '2.2.19' );
8+
define( 'SQLITE_DRIVER_VERSION', '2.2.20' );

wp-includes/sqlite-ast/class-wp-sqlite-connection.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class WP_SQLite_Connection {
6363
* @type int|null $timeout Optional. SQLite timeout in seconds.
6464
* The time to wait for a writable lock.
6565
* @type string|null $journal_mode Optional. SQLite journal mode.
66-
* @type int|null $application_id Optional. SQLite application ID.
6766
* }
6867
*
6968
* @throws InvalidArgumentException When some connection options are invalid.
@@ -97,10 +96,6 @@ public function __construct( array $options ) {
9796
if ( $journal_mode && in_array( $journal_mode, self::SQLITE_JOURNAL_MODES, true ) ) {
9897
$this->query( 'PRAGMA journal_mode = ' . $journal_mode );
9998
}
100-
101-
if ( isset( $options['application_id'] ) ) {
102-
$this->query( 'PRAGMA application_id = ' . (int) $options['application_id'] );
103-
}
10499
}
105100

106101
/**

0 commit comments

Comments
 (0)