Merged in feature/314-dev-dev01 (pull request #24)
auto-patch 314-dev-dev01-2024-01-25T04_09_02 * auto-patch 314-dev-dev01-2024-01-25T04_09_02
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Yoast\WP\Lib;
|
||||
|
||||
use ArrayAccess;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use ReturnTypeWillChange;
|
||||
use wpdb;
|
||||
use Yoast\WP\SEO\Config\Migration_Status;
|
||||
@@ -48,15 +51,15 @@ use Yoast\WP\SEO\Config\Migration_Status;
|
||||
*
|
||||
* @see http://www.php-fig.org/psr/psr-1/
|
||||
*/
|
||||
class ORM implements \ArrayAccess {
|
||||
class ORM implements ArrayAccess {
|
||||
|
||||
/*
|
||||
* --- CLASS CONSTANTS ---
|
||||
*/
|
||||
|
||||
const CONDITION_FRAGMENT = 0;
|
||||
public const CONDITION_FRAGMENT = 0;
|
||||
|
||||
const CONDITION_VALUES = 1;
|
||||
public const CONDITION_VALUES = 1;
|
||||
|
||||
/*
|
||||
* --- INSTANCE PROPERTIES ---
|
||||
@@ -270,13 +273,13 @@ class ORM implements \ArrayAccess {
|
||||
|
||||
$show_errors = $wpdb->show_errors;
|
||||
|
||||
if ( YoastSEO()->classes->get( Migration_Status::class )->get_error( 'free' ) ) {
|
||||
if ( \YoastSEO()->classes->get( Migration_Status::class )->get_error( 'free' ) ) {
|
||||
$wpdb->show_errors = false;
|
||||
}
|
||||
|
||||
$parameters = \array_filter(
|
||||
$parameters,
|
||||
static function( $parameter ) {
|
||||
static function ( $parameter ) {
|
||||
return $parameter !== null;
|
||||
}
|
||||
);
|
||||
@@ -537,7 +540,7 @@ class ORM implements \ArrayAccess {
|
||||
if ( ! \is_numeric( $result->{$alias} ) ) {
|
||||
$return_value = $result->{$alias};
|
||||
}
|
||||
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Reason: This loose comparison seems intended.
|
||||
// phpcs:ignore Universal.Operators.StrictComparisons -- Reason: This loose comparison seems intentional.
|
||||
elseif ( (int) $result->{$alias} == (float) $result->{$alias} ) {
|
||||
$return_value = (int) $result->{$alias};
|
||||
}
|
||||
@@ -634,8 +637,8 @@ class ORM implements \ArrayAccess {
|
||||
*
|
||||
* @return int The amount of null columns.
|
||||
*
|
||||
* @throws \Exception Primary key ID contains null value(s).
|
||||
* @throws \Exception Primary key ID missing from row or is null.
|
||||
* @throws Exception Primary key ID contains null value(s).
|
||||
* @throws Exception Primary key ID missing from row or is null.
|
||||
*/
|
||||
public function count_null_id_columns() {
|
||||
if ( \is_array( $this->get_id_column_name() ) ) {
|
||||
@@ -1155,7 +1158,7 @@ class ORM implements \ArrayAccess {
|
||||
protected function get_compound_id_column_values( $value ) {
|
||||
$filtered = [];
|
||||
foreach ( $this->get_id_column_name() as $key ) {
|
||||
$filtered[ $key ] = isset( $value[ $key ] ) ? $value[ $key ] : null;
|
||||
$filtered[ $key ] = ( $value[ $key ] ?? null );
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
@@ -1257,7 +1260,7 @@ class ORM implements \ArrayAccess {
|
||||
}
|
||||
$firstsub = true;
|
||||
foreach ( $value as $key => $item ) {
|
||||
$op = \is_string( $operator ) ? $operator : ( isset( $operator[ $key ] ) ? $operator[ $key ] : '=' );
|
||||
$op = \is_string( $operator ) ? $operator : ( $operator[ $key ] ?? '=' );
|
||||
if ( $op === '=' && $item === null ) {
|
||||
$op = 'IS';
|
||||
}
|
||||
@@ -1976,6 +1979,8 @@ class ORM implements \ArrayAccess {
|
||||
|
||||
/**
|
||||
* Resets the Idiorm instance state.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function reset_idiorm_state() {
|
||||
$this->values = [];
|
||||
@@ -2012,13 +2017,13 @@ class ORM implements \ArrayAccess {
|
||||
if ( \is_array( $key ) ) {
|
||||
$result = [];
|
||||
foreach ( $key as $column ) {
|
||||
$result[ $column ] = isset( $this->data[ $column ] ) ? $this->data[ $column ] : null;
|
||||
$result[ $column ] = ( $this->data[ $column ] ?? null );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
else {
|
||||
return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null;
|
||||
return ( $this->data[ $key ] ?? null );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2042,8 +2047,8 @@ class ORM implements \ArrayAccess {
|
||||
*
|
||||
* @return array|mixed|null
|
||||
*
|
||||
* @throws \Exception Primary key ID contains null value(s).
|
||||
* @throws \Exception Primary key ID missing from row or is null.
|
||||
* @throws Exception Primary key ID contains null value(s).
|
||||
* @throws Exception Primary key ID missing from row or is null.
|
||||
*/
|
||||
public function id( $disallow_null = false ) {
|
||||
$id = $this->get( $this->get_id_column_name() );
|
||||
@@ -2051,14 +2056,12 @@ class ORM implements \ArrayAccess {
|
||||
if ( \is_array( $id ) ) {
|
||||
foreach ( $id as $id_part ) {
|
||||
if ( $id_part === null ) {
|
||||
throw new \Exception( 'Primary key ID contains null value(s)' );
|
||||
throw new Exception( 'Primary key ID contains null value(s)' );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( $id === null ) {
|
||||
throw new \Exception( 'Primary key ID missing from row or is null' );
|
||||
}
|
||||
elseif ( $id === null ) {
|
||||
throw new Exception( 'Primary key ID missing from row or is null' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2114,10 +2117,8 @@ class ORM implements \ArrayAccess {
|
||||
if ( $expr === false && isset( $this->expr_fields[ $field ] ) ) {
|
||||
unset( $this->expr_fields[ $field ] );
|
||||
}
|
||||
else {
|
||||
if ( $expr === true ) {
|
||||
$this->expr_fields[ $field ] = true;
|
||||
}
|
||||
elseif ( $expr === true ) {
|
||||
$this->expr_fields[ $field ] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2149,8 +2150,8 @@ class ORM implements \ArrayAccess {
|
||||
*
|
||||
* @return bool True on success.
|
||||
*
|
||||
* @throws \Exception Primary key ID contains null value(s).
|
||||
* @throws \Exception Primary key ID missing from row or is null.
|
||||
* @throws Exception Primary key ID contains null value(s).
|
||||
* @throws Exception Primary key ID missing from row or is null.
|
||||
*/
|
||||
public function save() {
|
||||
global $wpdb;
|
||||
@@ -2204,14 +2205,14 @@ class ORM implements \ArrayAccess {
|
||||
*
|
||||
* @return array The distinct set of columns that are dirty in at least one of the models.
|
||||
*
|
||||
* @throws \InvalidArgumentException Instance to be inserted is not a new one.
|
||||
* @throws InvalidArgumentException Instance to be inserted is not a new one.
|
||||
*/
|
||||
public function get_dirty_column_names( $models ) {
|
||||
$dirty_column_names = [];
|
||||
|
||||
foreach ( $models as $model ) {
|
||||
if ( ! $model->orm->is_new() ) {
|
||||
throw new \InvalidArgumentException( 'Instance to be inserted is not a new one' );
|
||||
throw new InvalidArgumentException( 'Instance to be inserted is not a new one' );
|
||||
}
|
||||
|
||||
// Remove any expression fields as they are already baked into the query.
|
||||
@@ -2233,13 +2234,13 @@ class ORM implements \ArrayAccess {
|
||||
*
|
||||
* @return bool True for successful insert, false for failed.
|
||||
*
|
||||
* @throws \InvalidArgumentException Invalid instances to be inserted.
|
||||
* @throws \InvalidArgumentException Instance to be inserted is not a new one.
|
||||
* @throws InvalidArgumentException Invalid instances to be inserted.
|
||||
* @throws InvalidArgumentException Instance to be inserted is not a new one.
|
||||
*/
|
||||
public function insert_many( $models ) {
|
||||
// Validate the input first.
|
||||
if ( ! \is_array( $models ) ) {
|
||||
throw new \InvalidArgumentException( 'Invalid instances to be inserted' );
|
||||
throw new InvalidArgumentException( 'Invalid instances to be inserted' );
|
||||
}
|
||||
|
||||
if ( empty( $models ) ) {
|
||||
@@ -2251,7 +2252,7 @@ class ORM implements \ArrayAccess {
|
||||
/**
|
||||
* Filter: 'wpseo_chunk_bulked_insert_queries' - Allow filtering the chunk size of each bulked INSERT query.
|
||||
*
|
||||
* @api int The chunk size of the bulked INSERT queries.
|
||||
* @param int $chunk_size The chunk size of the bulked INSERT queries.
|
||||
*/
|
||||
$chunk = \apply_filters( 'wpseo_chunk_bulk_insert_queries', 100 );
|
||||
$chunk = ! \is_int( $chunk ) ? 100 : $chunk;
|
||||
@@ -2276,7 +2277,7 @@ class ORM implements \ArrayAccess {
|
||||
}
|
||||
|
||||
// Only register the value if it is not null.
|
||||
if ( ! is_null( $model->orm->dirty_fields[ $dirty_column ] ) ) {
|
||||
if ( ! \is_null( $model->orm->dirty_fields[ $dirty_column ] ) ) {
|
||||
$model_values[] = $model->orm->dirty_fields[ $dirty_column ];
|
||||
}
|
||||
}
|
||||
@@ -2415,8 +2416,8 @@ class ORM implements \ArrayAccess {
|
||||
*
|
||||
* @return string The delete query.
|
||||
*
|
||||
* @throws \Exception Primary key ID contains null value(s).
|
||||
* @throws \Exception Primary key ID missing from row or is null.
|
||||
* @throws Exception Primary key ID contains null value(s).
|
||||
* @throws Exception Primary key ID missing from row or is null.
|
||||
*/
|
||||
public function delete() {
|
||||
$query = [ 'DELETE FROM', $this->quote_identifier( $this->table_name ), $this->add_id_column_conditions() ];
|
||||
@@ -2477,6 +2478,8 @@ class ORM implements \ArrayAccess {
|
||||
*
|
||||
* @param string|int $offset Key.
|
||||
* @param mixed $value Value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetSet( $offset, $value ) {
|
||||
@@ -2490,6 +2493,8 @@ class ORM implements \ArrayAccess {
|
||||
* Removes the given key from the data.
|
||||
*
|
||||
* @param mixed $offset Key.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
#[ReturnTypeWillChange]
|
||||
public function offsetUnset( $offset ) {
|
||||
@@ -2517,6 +2522,8 @@ class ORM implements \ArrayAccess {
|
||||
*
|
||||
* @param string|int $key Key.
|
||||
* @param mixed $value Value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __set( $key, $value ) {
|
||||
$this->offsetSet( $key, $value );
|
||||
@@ -2526,6 +2533,8 @@ class ORM implements \ArrayAccess {
|
||||
* Handles magic unset via offset.
|
||||
*
|
||||
* @param mixed $key Key.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __unset( $key ) {
|
||||
$this->offsetUnset( $key );
|
||||
|
||||
Reference in New Issue
Block a user