Skip to content

Commit

Permalink
Fixes #5801: PHP Deprecated notice (#5908)
Browse files Browse the repository at this point in the history
* Updated BerlinDB

* Updated berlinDB

---------

Co-authored-by: Vasilis Manthos <[email protected]>
  • Loading branch information
jeawhanlee and vmanthos authored May 26, 2023
1 parent 2482e79 commit 3b6300e
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 167 deletions.
13 changes: 10 additions & 3 deletions inc/Dependencies/Database/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package Database
* @subpackage Base
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @copyright Copyright (c) 2021
* @license https://opensource.org/licenses/MIT MIT
* @since 1.0.0
*/
namespace WP_Rocket\Dependencies\Database;
Expand All @@ -22,6 +22,7 @@
*
* @since 1.0.0
*/
#[\AllowDynamicProperties]
class Base {

/**
Expand Down Expand Up @@ -177,8 +178,14 @@ protected function first_letters( $string = '', $sep = '_' ) {

// Trim spaces off the ends
$unspace = trim( $string );

// Only non-accented table names (avoid truncation)
$accents = remove_accents( $unspace );

// Only lowercase letters are allowed
$lower = strtolower( $accents );

// Explode into parts
$parts = explode( $sep, $lower );

// Loop through parts and concatenate the first letters together
Expand Down Expand Up @@ -290,7 +297,7 @@ protected function get_db() {
* Developer note:
*
* It should be impossible for a database table to be interacted with
* before the primary database interface it is setup.
* before the primary database interface is setup.
*
* However, because applications are complicated, it is unsafe to assume
* anything, so this silently returns false instead of halting everything.
Expand Down
58 changes: 29 additions & 29 deletions inc/Dependencies/Database/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package Database
* @subpackage Column
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @copyright Copyright (c) 2021
* @license https://opensource.org/licenses/MIT MIT
* @since 1.0.0
*/
namespace WP_Rocket\Dependencies\Database;
Expand Down Expand Up @@ -433,39 +433,39 @@ private function parse_args( $args = array() ) {
$r = wp_parse_args( $args, array(

// Table
'name' => '',
'type' => '',
'length' => '',
'unsigned' => false,
'zerofill' => false,
'binary' => false,
'allow_null' => false,
'default' => '',
'extra' => '',
'encoding' => $this->get_db()->charset,
'collation' => $this->get_db()->collate,
'comment' => '',
'name' => '',
'type' => '',
'length' => '',
'unsigned' => false,
'zerofill' => false,
'binary' => false,
'allow_null' => false,
'default' => '',
'extra' => '',
'encoding' => $this->get_db()->charset,
'collation' => $this->get_db()->collate,
'comment' => '',

// Query
'pattern' => false,
'searchable' => false,
'sortable' => false,
'date_query' => false,
'transition' => false,
'in' => true,
'not_in' => true,
'pattern' => false,
'searchable' => false,
'sortable' => false,
'date_query' => false,
'transition' => false,
'in' => true,
'not_in' => true,

// Special
'primary' => false,
'created' => false,
'modified' => false,
'uuid' => false,
'primary' => false,
'created' => false,
'modified' => false,
'uuid' => false,

// Cache
'cache_key' => false,
'cache_key' => false,

// Validation
'validate' => '',
'validate' => '',

// Capabilities
'caps' => array(),
Expand Down Expand Up @@ -692,10 +692,10 @@ private function sanitize_default( $default = '' ) {
* Sanitize the pattern
*
* @since 1.0.0
* @param mixed $pattern
* @param string $pattern
* @return string
*/
private function sanitize_pattern( $pattern = false ) {
private function sanitize_pattern( $pattern = '%s' ) {

// Allowed patterns
$allowed_patterns = array( '%s', '%d', '%f' );
Expand Down
85 changes: 54 additions & 31 deletions inc/Dependencies/Database/Queries/Compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package Database
* @subpackage Compare
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @copyright Copyright (c) 2021
* @license https://opensource.org/licenses/MIT MIT
* @since 1.0.0
*/
namespace WP_Rocket\Dependencies\Database\Queries;
Expand All @@ -24,6 +24,35 @@
*/
class Compare extends Meta {

// All supported SQL comparisons
const ALL_COMPARES = array(
'=',
'!=',
'>',
'>=',
'<',
'<=',
'LIKE',
'NOT LIKE',
'IN',
'NOT IN',
'BETWEEN',
'NOT BETWEEN',
'EXISTS',
'NOT EXISTS',
'REGEXP',
'NOT REGEXP',
'RLIKE',
);

// IN and BETWEEN
const IN_BETWEEN_COMPARES = array(
'IN',
'NOT IN',
'BETWEEN',
'NOT BETWEEN'
);

/**
* Generate SQL WHERE clauses for a first-order query clause.
*
Expand All @@ -44,65 +73,57 @@ class Compare extends Meta {
public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' ) {
global $wpdb;

// Default chunks
$sql_chunks = array(
'where' => array(),
'join' => array(),
);

// Maybe format compare clause
if ( isset( $clause['compare'] ) ) {
$clause['compare'] = strtoupper( $clause['compare'] );

// Or set compare clause based on value
} else {
$clause['compare'] = isset( $clause['value'] ) && is_array( $clause['value'] ) ? 'IN' : '=';
$clause['compare'] = isset( $clause['value'] ) && is_array( $clause['value'] )
? 'IN'
: '=';
}

if ( ! in_array(
$clause['compare'], array(
'=',
'!=',
'>',
'>=',
'<',
'<=',
'LIKE',
'NOT LIKE',
'IN',
'NOT IN',
'BETWEEN',
'NOT BETWEEN',
'EXISTS',
'NOT EXISTS',
'REGEXP',
'NOT REGEXP',
'RLIKE',
), true
) ) {
// Fallback to equals
if ( ! in_array( $clause['compare'], self::ALL_COMPARES, true ) ) {
$clause['compare'] = '=';
}

if ( isset( $clause['compare_key'] ) && 'LIKE' === strtoupper( $clause['compare_key'] ) ) {
// Uppercase or equals
if ( isset( $clause['compare_key'] ) && ( 'LIKE' === strtoupper( $clause['compare_key'] ) ) ) {
$clause['compare_key'] = strtoupper( $clause['compare_key'] );
} else {
$clause['compare_key'] = '=';
}

$compare = $clause['compare'];
$compare_key = $clause['compare_key'];
// Get comparison from clause
$compare = $clause['compare'];

// Build the WHERE clause.
/** Build the WHERE clause ********************************************/

// Column name and value.
if ( array_key_exists( 'key', $clause ) && array_key_exists( 'value', $clause ) ) {
$column = sanitize_key( $clause['key'] );
$value = $clause['value'];

if ( in_array( $compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ), true ) ) {
// IN or BETWEEN
if ( in_array( $compare, self::IN_BETWEEN_COMPARES, true ) ) {
if ( ! is_array( $value ) ) {
$value = preg_split( '/[,\s]+/', $value );
}

// Anything else
} else {
$value = trim( $value );
}

// Format WHERE from compare value(s)
switch ( $compare ) {
case 'IN':
case 'NOT IN':
Expand Down Expand Up @@ -139,7 +160,8 @@ public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' )

}

if ( $where ) {
// Maybe add column, compare, & where to chunks
if ( ! empty( $where ) ) {
$sql_chunks['where'][] = "{$column} {$compare} {$where}";
}
}
Expand All @@ -152,6 +174,7 @@ public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' )
$sql_chunks['where'] = array( '( ' . implode( ' AND ', $sql_chunks['where'] ) . ' )' );
}

// Return
return $sql_chunks;
}
}
}
4 changes: 2 additions & 2 deletions inc/Dependencies/Database/Queries/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package Database
* @subpackage Date
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @copyright Copyright (c) 2021
* @license https://opensource.org/licenses/MIT MIT
* @since 1.0.0
*/
namespace WP_Rocket\Dependencies\Database\Queries;
Expand Down
4 changes: 2 additions & 2 deletions inc/Dependencies/Database/Queries/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
* @package Database
* @subpackage Meta
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @copyright Copyright (c) 2021
* @license https://opensource.org/licenses/MIT MIT
* @since 1.1.0
*/
namespace WP_Rocket\Dependencies\Database\Queries;
Expand Down
Loading

0 comments on commit 3b6300e

Please sign in to comment.