• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / ActionScheduler_DBStore::get_query_actions_sql() – Returns the SQL statement to query (or count) actions.

You appear to be a bot. Output may be restricted

Description

Returns the SQL statement to query (or count) actions.

Usage

$string = ActionScheduler_DBStore::get_query_actions_sql( $query, $select_or_count );

Parameters

$query
( array ) required – Filtering options.
$select_or_count
( string ) optional default: select – Whether the SQL should select and return the IDs or just the row count.

Returns

string SQL statement already properly escaped.

Source

File name: woocommerce/packages/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php
Lines:

1 to 100 of 130
  protected function get_query_actions_sql( array $query, $select_or_count = 'select' ) {

    if ( ! in_array( $select_or_count, array( 'select', 'count' ) ) ) {
      throw new InvalidArgumentException( __( 'Invalid value for select or count parameter. Cannot query actions.', 'woocommerce' ) );
    }

    $query = wp_parse_args( $query, [
      'hook'             => '',
      'args'             => null,
      'date'             => null,
      'date_compare'     => '<=',
      'modified'         => null,
      'modified_compare' => '<=',
      'group'            => '',
      'status'           => '',
      'claimed'          => null,
      'per_page'         => 5,
      'offset'           => 0,
      'orderby'          => 'date',
      'order'            => 'ASC',
    ] );

    
/** @var \wpdb $wpdb */
    global $wpdb;
    $sql  = ( 'count' === $select_or_count ) ? 'SELECT count(a.action_id)' : 'SELECT a.action_id';
    $sql .= " FROM {$wpdb->actionscheduler_actions} a";
    $sql_params = [];

    if ( ! empty( $query[ 'group' ] ) || 'group' === $query[ 'orderby' ] ) {
      $sql .= " LEFT JOIN {$wpdb->actionscheduler_groups} g ON g.group_id=a.group_id";
    }

    $sql .= " WHERE 1=1";

    if ( ! empty( $query[ 'group' ] ) ) {
      $sql          .= " AND g.slug=%s";
      $sql_params[] = $query[ 'group' ];
    }

    if ( $query[ 'hook' ] ) {
      $sql          .= " AND a.hook=%s";
      $sql_params[] = $query[ 'hook' ];
    }
    if ( ! is_null( $query[ 'args' ] ) ) {
      $sql          .= " AND a.args=%s";
      $sql_params[] = $this->get_args_for_query( $query[ 'args' ] );
    }

    if ( $query[ 'status' ] ) {
      $sql          .= " AND a.status=%s";
      $sql_params[] = $query[ 'status' ];
    }

    if ( $query[ 'date' ] instanceof \DateTime ) {
      $date = clone $query[ 'date' ];
      $date->setTimezone( new \DateTimeZone( 'UTC' ) );
      $date_string  = $date->format( 'Y-m-d H:i:s' );
      $comparator   = $this->validate_sql_comparator( $query[ 'date_compare' ] );
      $sql          .= " AND a.scheduled_date_gmt $comparator %s";
      $sql_params[] = $date_string;
    }

    if ( $query[ 'modified' ] instanceof \DateTime ) {
      $modified = clone $query[ 'modified' ];
      $modified->setTimezone( new \DateTimeZone( 'UTC' ) );
      $date_string  = $modified->format( 'Y-m-d H:i:s' );
      $comparator   = $this->validate_sql_comparator( $query[ 'modified_compare' ] );
      $sql          .= " AND a.last_attempt_gmt $comparator %s";
      $sql_params[] = $date_string;
    }

    if ( $query[ 'claimed' ] === true ) {
      $sql .= " AND a.claim_id != 0";
    } elseif ( $query[ 'claimed' ] === false ) {
      $sql .= " AND a.claim_id = 0";
    } elseif ( ! is_null( $query[ 'claimed' ] ) ) {
      $sql          .= " AND a.claim_id = %d";
      $sql_params[] = $query[ 'claimed' ];
    }

    if ( ! empty( $query['search'] ) ) {
      $sql .= " AND (a.hook LIKE %s OR (a.extended_args IS NULL AND a.args LIKE %s) OR a.extended_args LIKE %s";
      for( $i = 0; $i < 3; $i++ ) {
        $sql_params[] = sprintf( '%%%s%%', $query['search'] );
      }

      $search_claim_id = (int) $query['search'];
      if ( $search_claim_id ) {
        $sql .= ' OR a.claim_id = %d';
        $sql_params[] = $search_claim_id;
      }

      $sql .= ')';
    }

    if ( 'select' === $select_or_count ) {
      switch ( $query['orderby'] ) {
        case 'hook':
          $orderby = 'a.hook';
          break;
 
[1] [2] Next »

 View on GitHub View on Trac

Published: 6th April 2020 | Last updated: 6th April 2020

Primary Sidebar

Information

Function name: ActionScheduler_DBStore::get_query_actions_sql
Class ref: ActionScheduler_DBStore
Plugin ref: WooCommerce
Version: 5.2.2
Sourcefile: packages/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php
File ref: packages/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php
Deprecated?: No
API Letters: A,D,G,Q

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.7.1
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites