Ą /**
* Gets the public 'Yoast\WP\SEO\Generators\Schema\Author' shared autowired service.
*
* @return \Yoast\WP\SEO\Generators\Schema\Author
*/ R__ . /**
* Gets the public 'Yoast\WP\SEO\Generators\Schema\FAQ' shared autowired service.
*
* @return \Yoast\WP\SEO\Generators\Schema\FAQ
*/ st_Dynamic_R /**
* Gets the public 'Yoast\WP\SEO\Generators\Schema\HowTo' shared autowired service.
*
* @return \Yoast\WP\SEO\Generators\Schema\HowTo
*/ 'Yoast_F Ą /**
* Gets the public 'Yoast\WP\SEO\Generators\Schema\Person' shared autowired service.
*
* @return \Yoast\WP\SEO\Generators\Schema\Person
*/ ement' Ł /**
* Gets the public 'Yoast\WP\SEO\Generators\Schema\WebPage' shared autowired service.
*
* @return \Yoast\WP\SEO\Generators\Schema\WebPage
*/ nput Ł /**
* Gets the public 'Yoast\WP\SEO\Generators\Schema\Website' shared autowired service.
*
* @return \Yoast\WP\SEO\Generators\Schema\Website
*/ p',
§ /**
* Gets the public 'Yoast\WP\SEO\Generators\Schema_Generator' shared autowired service.
*
* @return \Yoast\WP\SEO\Generators\Schema_Generator
*/ /**
* Gets the public 'Yoast\WP\SEO\Helpers\Aioseo_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Aioseo_Helper
*/ t-notificati /**
* Gets the public 'Yoast\WP\SEO\Helpers\Asset_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Asset_Helper
*/ s-yoast-plugin /**
* Gets the public 'Yoast\WP\SEO\Helpers\Blocks_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Blocks_Helper
*/ lassLoader $ Ł /**
* Gets the public 'Yoast\WP\SEO\Helpers\Capability_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Capability_Helper
*/ /**
* Gets the public 'Yoast\WP\SEO\Helpers\Curl_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Curl_Helper
*/ cf5a93::$classMa § /**
* Gets the public 'Yoast\WP\SEO\Helpers\Current_Page_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Current_Page_Helper
*/ /**
* Gets the public 'Yoast\WP\SEO\Helpers\Date_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Date_Helper
*/ æäŸăăŠăă „ /**
* Gets the public 'Yoast\WP\SEO\Helpers\Environment_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Environment_Helper
*/ ck /**
* Gets the public 'Yoast\WP\SEO\Helpers\Home_Url_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Home_Url_Helper
*/ s="emEff /**
* Gets the public 'Yoast\WP\SEO\Helpers\Image_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Image_Helper
*/ "bestOf_odd">2 /**
* Gets the public 'Yoast\WP\SEO\Helpers\Import_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Import_Helper
*/ an>ăăă Ą /**
* Gets the public 'Yoast\WP\SEO\Helpers\Indexable_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Indexable_Helper
*/ p back /**
* Gets the public 'Yoast\WP\SEO\Helpers\Indexing_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Indexing_Helper
*/ fPred_ex /**
* Gets the public 'Yoast\WP\SEO\Helpers\Language_Helper' shared autowired service.
*
* @return \Yoast\WP\SEO\Helpers\Language_Helper
*/ 7">æé«ăźăȘăăș: 2.20
insert_id;
}
/**
* Prefix given table name with $wpdb->prefix
*
* @param string $tableName
*
* @return string
*/
public static function prefix( $tableName ) {
global $wpdb;
return $wpdb->prefix . $tableName;
}
/**
* Create QueryBuilder instance
*
* @param string|RawSQL $table
* @param string|null $alias
*
* @return QueryBuilder
*/
public static function table( $table, $alias = '' ) {
$builder = new QueryBuilder();
$builder->from( $table, $alias );
return $builder;
}
/**
* Runs a transaction. If the callable works then the transaction is committed. If the callable throws an exception
* then the transaction is rolled back.
*
* @since 1.0.0
*
* @param callable $callback
*
* @return void
* @throws Exception
*/
public static function transaction( callable $callback ) {
self::beginTransaction();
try {
$callback();
} catch ( Exception $e ) {
self::rollback();
throw $e;
}
self::commit();
}
/**
* Manually starts a transaction
*
* @since 1.0.0
*
* @return void
*/
public static function beginTransaction() {
global $wpdb;
$wpdb->query( 'START TRANSACTION' );
}
/**
* Manually rolls back a transaction
*
* @since 1.0.0
*
* @return void
*/
public static function rollback() {
global $wpdb;
$wpdb->query( 'ROLLBACK' );
}
/**
* Manually commits a transaction
*
* @since 1.0.0
*
* @return void
*/
public static function commit() {
global $wpdb;
$wpdb->query( 'COMMIT' );
}
/**
* Used as a flag to tell QueryBuilder not to process the provided SQL
* If $args are provided, we will assume that dev wants to use DB::prepare method with raw SQL
*
* @param string $sql
* @param array ...$args
*
* @return RawSQL
*/
public static function raw( $sql, ...$args ) {
return new RawSQL( $sql, ...$args );
}
/**
* Runs a query callable and checks to see if any unique SQL errors occurred when it was run
*
* @since 1.0.0
*
* @param Callable $queryCaller
*
* @return mixed
* @throws DatabaseQueryException
*/
private static function runQueryWithErrorChecking( $queryCaller ) {
global $wpdb, $EZSQL_ERROR;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$errorCount = is_array( $EZSQL_ERROR ) ? count( $EZSQL_ERROR ) : 0;
$hasShowErrors = $wpdb->hide_errors();
$output = $queryCaller();
if ( $hasShowErrors ) {
$wpdb->show_errors();
}
$wpError = self::getQueryErrors( $errorCount );
if ( ! empty( $wpError->errors ) ) {
/** @var DatabaseQueryException */
$exception_class = Config::getDatabaseQueryException();
throw new $exception_class( $wpdb->last_query, $wpError->errors );
}
return $output;
}
/**
* Retrieves the SQL errors stored by WordPress
*
* @since 1.0.0
*
* @param int $initialCount
*
* @return WP_Error
*/
private static function getQueryErrors( $initialCount = 0 ) {
global $EZSQL_ERROR;
$wpError = new WP_Error();
if ( is_array( $EZSQL_ERROR ) ) {
for ( $index = $initialCount, $indexMax = count( $EZSQL_ERROR ); $index < $indexMax; $index ++ ) {
$error = $EZSQL_ERROR[ $index ];
if ( empty( $error['error_str'] ) || empty( $error['query'] ) || 0 === strpos(
$error['query'],
'DESCRIBE '
) ) {
continue;
}
$wpError->add( 'db_delta_error', $error['error_str'] );
}
}
return $wpError;
}
/**
* Get all the results from a query in batches.
*
* @since TBD
*
* @param string $query The SQL query.
* @param int $batch_size The number of results to return in each batch.
* @param Closure $fetch The function to fetch the results.
*
* @return Generator A generator to get all the results of the query.
*/
private static function run_batched_query( string $query, int $batch_size, Closure $fetch ): Generator {
// Capture the end part of the main query, the one not bound with parentheses.
preg_match( '/([^)(]*?)$/', $query, $matches );
// Does the end part of the query contain a LIMIT? Look for `LIMIT , ` or `LIMIT `.
$has_limit = (bool) preg_match( '/LIMIT\\s+\\d+\\s*(,\\s*\\d+)*$/i', $matches[1] );
if ( $has_limit ) {
yield from $fetch( $query );
return;
}
// Add a LIMIT template to the query.
$query_template = trim( $query . ' LIMIT %d, %d' );
$offset = 0;
$found_rows = 0;
$fetched = 0;
$key = 0;
// Set up the first query, make sure ot include SQL_CALC_FOUND_ROWS.
$first_query = self::prepare(
$query_template,
$offset,
$batch_size
);
// Build the first query to include SQL_CALC_FOUND_ROWS if not already present.
$first_query = preg_replace( '/^SELECT\\s*(?!SQL_CALC_FOUND_ROWS)/i', 'SELECT SQL_CALC_FOUND_ROWS ', $first_query );
$run_query = $first_query;
do {
foreach ( $fetch( $run_query ) as $result ) {
$fetched ++;
yield $key => $result;
$key ++;
}
if ( $offset === 0 ) {
// First run.
$found_rows = (int) self::get_var( 'SELECT FOUND_ROWS()' );
}
$offset += $batch_size;
// Compile the query for the next run.
$run_query = self::prepare(
$query_template,
$offset,
$batch_size
);
} while ( $fetched < $found_rows );
}
/**
* Get all the results from a query in batches.
*
* This method should be used to run an unbounded query in batches.
*
* @since TBD
*
* @param string|null $query The SQL query.
* @param string $output The required return type. One of OBJECT, ARRAY_A, ARRAY_N.
* @param int $batch_size The number of results to return in each batch.
*
* @return Generator A generator to get all the results of the query.
*/
public static function generate_results( string $query = null, string $output = OBJECT, int $batch_size = 20 ): Generator {
yield from self::run_batched_query( $query, $batch_size, static function ( string $run_query ) use ( $output ) {
return self::get_results( $run_query, $output );
} );
}
/**
* Get all the values in a column from a query in batches.
*
* @since TBD
*
* @param string|null $query The SQL query.
* @param int $x The column number to return.
* @param int $batch_size The number of results to return in each batch.
*
* @return Generator The values of the column.
*/
public function generate_col( string $query = null, int $x = 0, int $batch_size = 50 ): Generator {
yield from self::run_batched_query( $query, $batch_size, static function ( string $run_query ) use ( $x ) {
return self::get_col( $run_query, $x );
} );
}
}