Skip to content
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

fix(WPLoader) restore loadOnly to SUITE_BEFORE #715

Merged
merged 6 commits into from
Apr 7, 2024
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: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Changed

- Load WordPress at `SUITE_BEFORE` in the `WPLoader` module, I had previously changed this to `SUITE_INIT` but that was causing issues.
- Update Core PHPUnit tests
- Update SQLite plugin.

## [3.5.5] 2024-03-28;

### Changed
Expand Down
22 changes: 13 additions & 9 deletions config/typos.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[default.extend-identifiers]
RebOOter = "RebOOter"
[files]
extend-exclude = ["vendor", "includes"]
[type.css]
extend-glob = ["*.min.css", "*.min.css.map"]
check-file = false
[type.js]
extend-glob = ["*.min.js", "*.min.js.map"]
check-file = false
extend-exclude = [
".git/",
"includes/",
"vendor/",
]
ignore-hidden = false

[default.extend-identifiers]
"RebOOter" = "RebOOter"

[default.extend-words]
# To handle the hipster default blog content about bike messengers gettin' caught in the rain.
"gettin" = "gettin"
4 changes: 4 additions & 0 deletions includes/core-phpunit/includes/abstract-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ public function tear_down() {
*/
$GLOBALS['wp_sitemaps'] = null;

// Reset template globals.
$GLOBALS['wp_stylesheet_path'] = null;
$GLOBALS['wp_template_path'] = null;

$this->unregister_all_meta_keys();
remove_theme_support( 'html5' );
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
Expand Down
10 changes: 5 additions & 5 deletions includes/core-phpunit/includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
* Returns a string of the required length containing random characters. Note that
* the maximum possible string length is 32.
*
* @param int $len Optional. The required length. Default 32.
* @param int $length Optional. The required length. Default 32.
* @return string The string.
*/
function rand_str( $len = 32 ) {
return substr( md5( uniqid( rand() ) ), 0, $len );
function rand_str( $length = 32 ) {
return substr( md5( uniqid( rand() ) ), 0, $length );
}

/**
* Returns a string of the required length containing random characters.
*
* @param int $len The required length.
* @param int $length The required length.
* @return string The string.
*/
function rand_long_str( $length ) {
Expand Down Expand Up @@ -49,7 +49,7 @@ function strip_ws( $txt ) {
return trim( implode( "\n", $result ) );
}

/*
/**
* Helper class for testing code that involves actions and filters.
*
* Typical use:
Expand Down
3 changes: 1 addition & 2 deletions includes/core-phpunit/includes/wp-profiler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* A simple manually-instrumented profiler for WordPress.
*
* This records basic execution time, and a summary of the actions and SQL queries run within each block.
Expand All @@ -15,7 +15,6 @@
*
* Multiple profile blocks are permitted, and they may be nested.
*/

class WPProfiler {
public $stack;
public $profile;
Expand Down
5 changes: 3 additions & 2 deletions includes/sqlite-database-integration/activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/
function sqlite_plugin_activation_redirect( $plugin ) {
if ( plugin_basename( SQLITE_MAIN_FILE ) === $plugin ) {
wp_redirect( admin_url( 'options-general.php?page=sqlite-integration' ) );
exit;
if ( wp_safe_redirect( admin_url( 'options-general.php?page=sqlite-integration' ) ) ) {
exit;
}
}
}
add_action( 'activated_plugin', 'sqlite_plugin_activation_redirect' );
Expand Down
8 changes: 7 additions & 1 deletion includes/sqlite-database-integration/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
* @since 1.0.0
*/
function sqlite_add_admin_menu() {
add_options_page(__( 'SQLite integration', 'sqlite-database-integration' ), __( 'SQLite integration', 'sqlite-database-integration' ), 'manage_options', 'sqlite-integration', 'sqlite_integration_admin_screen');
add_options_page(
__( 'SQLite integration', 'sqlite-database-integration' ),
__( 'SQLite integration', 'sqlite-database-integration' ),
'manage_options',
'sqlite-integration',
'sqlite_integration_admin_screen'
);
}
add_action( 'admin_menu', 'sqlite_add_admin_menu' );

Expand Down
2 changes: 1 addition & 1 deletion includes/sqlite-database-integration/deactivate.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function sqlite_plugin_remove_db_file() {
// Run an action on `shutdown`, to deactivate the option in the MySQL database.
add_action(
'shutdown',
function() {
function () {
global $table_prefix;

// Get credentials for the MySQL database.
Expand Down
1 change: 1 addition & 0 deletions includes/sqlite-database-integration/health-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function sqlite_plugin_filter_site_status_tests( $tests ) {
if ( 'sqlite' === $db_engine ) {
unset( $tests['direct']['utf8mb4_support'] );
unset( $tests['direct']['sql_server'] );
unset( $tests['direct']['persistent_object_cache'] ); // Throws an error because DB_NAME is not defined.
}

return $tests;
Expand Down
6 changes: 3 additions & 3 deletions includes/sqlite-database-integration/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/**
* Plugin Name: SQLite Database Integration
* Description: SQLite database driver drop-in.
* Author: WordPress Performance Team
* Version: 2.1.2
* Requires PHP: 5.6
* Author: The WordPress Team
* Version: 2.1.7
* Requires PHP: 7.0
* Textdomain: sqlite-database-integration
*
* This feature plugin allows WordPress to use SQLite instead of MySQL as its database.
Expand Down
4 changes: 2 additions & 2 deletions includes/sqlite-database-integration/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Contributors: wordpressdotorg, aristath
Requires at least: 6.0
Tested up to: 6.4
Requires PHP: 5.6
Stable tag: 2.1.2
Stable tag: 2.1.7
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance, database

SQLite-integration plugin from the WordPress Performance Team.
SQLite integration plugin by the WordPress Team.

== Description ==

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function select( $db, $dbh = null ) {
*
* @return string escaped
*/
function _real_escape( $str ) {
public function _real_escape( $str ) {
return addslashes( $str );
}

Expand Down Expand Up @@ -278,7 +278,7 @@ public function query( $query ) {
}

$this->result = $this->dbh->query( $query );
$this->num_queries++;
++$this->num_queries;

if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
Expand Down Expand Up @@ -349,7 +349,7 @@ public function has_cap( $db_cap ) {
* @see wpdb::db_version()
*/
public function db_version() {
return '5.5';
return '8.0';
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* This file is a port of the Lexer & Tokens_List classes from the PHPMyAdmin/sql-parser library.
* This file is a port of the Lexer & TokensList classes from the PHPMyAdmin/sql-parser library.
*
* @package wp-sqlite-integration
* @see https://github.com/phpmyadmin/sql-parser
Expand Down Expand Up @@ -33,7 +33,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
public static $parser_methods = array(
const PARSER_METHODS = array(
// It is best to put the parsers in order of their complexity
// (ascending) and their occurrence rate (descending).
//
Expand Down Expand Up @@ -77,7 +77,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
public $keyword_name_indicators = array(
const KEYWORD_NAME_INDICATORS = array(
'FROM',
'SET',
'WHERE',
Expand All @@ -89,7 +89,7 @@ class WP_SQLite_Lexer {
*
* @var string[]
*/
public $operator_name_indicators = array(
const OPERATOR_NAME_INDICATORS = array(
',',
'.',
);
Expand Down Expand Up @@ -1486,7 +1486,7 @@ public function lex() {
*/
$token = null;

foreach ( static::$parser_methods as $method ) {
foreach ( self::PARSER_METHODS as $method ) {
$token = $this->$method();

if ( $token ) {
Expand Down Expand Up @@ -1668,10 +1668,10 @@ private function solve_ambiguity_on_function_keywords() {
$next = $this->tokens_get_next();
if (
( WP_SQLite_Token::TYPE_KEYWORD !== $next->type
|| ! in_array( $next->value, $this->keyword_name_indicators, true )
|| ! in_array( $next->value, self::KEYWORD_NAME_INDICATORS, true )
)
&& ( WP_SQLite_Token::TYPE_OPERATOR !== $next->type
|| ! in_array( $next->value, $this->operator_name_indicators, true )
|| ! in_array( $next->value, self::OPERATOR_NAME_INDICATORS, true )
)
&& ( null !== $next->value )
) {
Expand Down Expand Up @@ -2068,7 +2068,7 @@ public function parse_number() {
} elseif (
$this->last + 1 < $this->string_length
&& '0' === $this->str[ $this->last ]
&& ( 'x' === $this->str[ $this->last + 1 ] || 'X' === $this->str[ $this->last + 1 ] )
&& 'x' === $this->str[ $this->last + 1 ]
) {
$token .= $this->str[ $this->last++ ];
$state = 2;
Expand Down Expand Up @@ -2260,7 +2260,7 @@ public function parse_symbol() {
if ( null === $str ) {
$str = $this->parse_unknown();

if ( null === $str ) {
if ( null === $str && ! ( $flags & WP_SQLite_Token::FLAG_SYMBOL_PARAMETER ) ) {
$this->error( 'Variable name was expected.', $this->str[ $this->last ], $this->last );
}
}
Expand Down Expand Up @@ -2514,15 +2514,10 @@ public static function is_separator( $str ) {
* Constructor.
*
* @param stdClass[] $tokens The initial array of tokens.
* @param int $count The count of tokens in the initial array.
*/
public function tokens( array $tokens = array(), $count = -1 ) {
if ( empty( $tokens ) ) {
return;
}

public function tokens( array $tokens = array() ) {
$this->tokens = $tokens;
$this->tokens_count = -1 === $count ? count( $tokens ) : $count;
$this->tokens_count = count( $tokens );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function month( $field ) {
* From https://www.php.net/manual/en/datetime.format.php:
*
* n - Numeric representation of a month, without leading zeros.
* 1 through 12
* 1 through 12
*/
return intval( gmdate( 'n', strtotime( $field ) ) );
}
Expand Down Expand Up @@ -446,14 +446,14 @@ public function isnull( $field ) {
*
* As 'IF' is a reserved word for PHP, function name must be changed.
*
* @param mixed $expression the statement to be evaluated as true or false.
* @param mixed $true statement or value returned if $expression is true.
* @param mixed $false statement or value returned if $expression is false.
* @param mixed $expression The statement to be evaluated as true or false.
* @param mixed $truthy Statement or value returned if $expression is true.
* @param mixed $falsy Statement or value returned if $expression is false.
*
* @return mixed
*/
public function _if( $expression, $true, $false ) {
return ( true === $expression ) ? $true : $false;
public function _if( $expression, $truthy, $falsy ) {
return ( true === $expression ) ? $truthy : $falsy;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class WP_SQLite_Token {
*
* @var mixed|string|null
*/
public $keyword;
public $keyword = null;

/**
* The type of this token.
Expand Down Expand Up @@ -195,11 +195,10 @@ class WP_SQLite_Token {
* @param int $flags The flags of the token.
*/
public function __construct( $token, $type = 0, $flags = 0 ) {
$this->token = $token;
$this->type = $type;
$this->flags = $flags;
$this->keyword = null;
$this->value = $this->extract();
$this->token = $token;
$this->type = $type;
$this->flags = $flags;
$this->value = $this->extract();
}

/**
Expand Down Expand Up @@ -262,8 +261,8 @@ private function extract() {
case self::TYPE_NUMBER:
$ret = str_replace( '--', '', $this->token ); // e.g. ---42 === -42.
if ( $this->flags & self::FLAG_NUMBER_HEX ) {
$ret = str_replace( array( '-', '+' ), '', $this->token );
if ( $this->flags & self::FLAG_NUMBER_NEGATIVE ) {
$ret = str_replace( '-', '', $this->token );
$ret = -hexdec( $ret );
} else {
$ret = hexdec( $ret );
Expand Down
Loading
Loading