ActionScheduler_wpPostStore::claim_actions
Claim actions.
Метод класса: ActionScheduler_wpPostStore{}
Хуков нет.
Возвращает
int. The number of actions that were claimed.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->claim_actions( $claim_id, $limit, ?DateTime $before_date, $hooks, $group );
- $claim_id(строка) (обязательный)
- Claim ID.
- $limit(int) (обязательный)
- Limit.
- ?DateTime $before_date
- .
По умолчанию: null - $hooks(массив)
- Claim only actions with a hook or hooks.
По умолчанию: array() - $group(строка)
- Claim only actions in the given group.
По умолчанию: ''
Код ActionScheduler_wpPostStore::claim_actions() ActionScheduler wpPostStore::claim actions WC 10.4.3
protected function claim_actions( $claim_id, $limit, ?DateTime $before_date = null, $hooks = array(), $group = '' ) {
// Set up initial variables.
$date = null === $before_date ? as_get_datetime_object() : clone $before_date;
$limit_ids = ! empty( $group );
$ids = $limit_ids ? $this->get_actions_by_group( $group, $limit, $date ) : array();
// If limiting by IDs and no posts found, then return early since we have nothing to update.
if ( $limit_ids && 0 === count( $ids ) ) {
return 0;
}
/**
* Global wpdb object.
*
* @var wpdb $wpdb
*/
global $wpdb;
/*
* Build up custom query to update the affected posts. Parameters are built as a separate array
* to make it easier to identify where they are in the query.
*
* We can't use $wpdb->update() here because of the "ID IN ..." clause.
*/
$update = "UPDATE {$wpdb->posts} SET post_password = %s, post_modified_gmt = %s, post_modified = %s";
$params = array(
$claim_id,
current_time( 'mysql', true ),
current_time( 'mysql' ),
);
// Build initial WHERE clause.
$where = "WHERE post_type = %s AND post_status = %s AND post_password = ''";
$params[] = self::POST_TYPE;
$params[] = ActionScheduler_Store::STATUS_PENDING;
if ( ! empty( $hooks ) ) {
$placeholders = array_fill( 0, count( $hooks ), '%s' );
$where .= ' AND post_title IN (' . join( ', ', $placeholders ) . ')';
$params = array_merge( $params, array_values( $hooks ) );
}
/*
* Add the IDs to the WHERE clause. IDs not escaped because they came directly from a prior DB query.
*
* If we're not limiting by IDs, then include the post_date_gmt clause.
*/
if ( $limit_ids ) {
$where .= ' AND ID IN (' . join( ',', $ids ) . ')';
} else {
$where .= ' AND post_date_gmt <= %s';
$params[] = $date->format( 'Y-m-d H:i:s' );
}
// Add the ORDER BY clause and,ms limit.
$order = 'ORDER BY menu_order ASC, post_date_gmt ASC, ID ASC LIMIT %d';
$params[] = $limit;
// Run the query and gather results.
$rows_affected = $wpdb->query( $wpdb->prepare( "{$update} {$where} {$order}", $params ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
if ( false === $rows_affected ) {
throw new RuntimeException( __( 'Unable to claim actions. Database error.', 'woocommerce' ) );
}
return (int) $rows_affected;
}