Plugin Directory

Changeset 2542151


Ignore:
Timestamp:
06/03/2021 04:42:57 PM (5 years ago)
Author:
vedjain
Message:

Tagging version 3.2.0

Location:
action-scheduler
Files:
2 added
24 edited
1 copied

Legend:

Unmodified
Added
Removed
  • action-scheduler/tags/3.2.0/action-scheduler.php

    r2340383 r2542151  
    66 * Author: Automattic
    77 * Author URI: https://automattic.com/
    8  * Version: 3.1.6
     8 * Version: 3.2.0
    99 * License: GPLv3
    1010 *
     
    2626 */
    2727
    28 if ( ! function_exists( 'action_scheduler_register_3_dot_1_dot_6' ) ) {
     28if ( ! function_exists( 'action_scheduler_register_3_dot_2_dot_0' ) ) {
    2929
    3030    if ( ! class_exists( 'ActionScheduler_Versions' ) ) {
     
    3333    }
    3434
    35     add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_1_dot_6', 0, 0 );
     35    add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_2_dot_0', 0, 0 );
    3636
    37     function action_scheduler_register_3_dot_1_dot_6() {
     37    function action_scheduler_register_3_dot_2_dot_0() {
    3838        $versions = ActionScheduler_Versions::instance();
    39         $versions->register( '3.1.6', 'action_scheduler_initialize_3_dot_1_dot_6' );
     39        $versions->register( '3.2.0', 'action_scheduler_initialize_3_dot_2_dot_0' );
    4040    }
    4141
    42     function action_scheduler_initialize_3_dot_1_dot_6() {
     42    function action_scheduler_initialize_3_dot_2_dot_0() {
    4343        require_once( 'classes/abstracts/ActionScheduler.php' );
    4444        ActionScheduler::init( __FILE__ );
     
    4747    // Support usage in themes - load this version if no plugin has loaded a version yet.
    4848    if ( did_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler' ) ) {
    49         action_scheduler_initialize_3_dot_1_dot_6();
     49        action_scheduler_initialize_3_dot_2_dot_0();
    5050        do_action( 'action_scheduler_pre_theme_init' );
    5151        ActionScheduler_Versions::initialize_latest_version();
  • action-scheduler/tags/3.2.0/classes/ActionScheduler_QueueCleaner.php

    r2340383 r2542151  
    4545                'modified_compare' => '<=',
    4646                'per_page'         => $this->get_batch_size(),
     47                'orderby'          => 'none',
    4748            ) );
    4849
     
    9192            'claimed'          => true,
    9293            'per_page'         => $this->get_batch_size(),
     94            'orderby'          => 'none',
    9395        ) );
    9496
     
    119121            'modified_compare' => '<=',
    120122            'per_page'         => $this->get_batch_size(),
     123            'orderby'          => 'none',
    121124        ) );
    122125
  • action-scheduler/tags/3.2.0/classes/ActionScheduler_wcSystemStatus.php

    r2340383 r2542151  
    9494    protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) {
    9595        $as_version = ActionScheduler_Versions::instance()->latest_version();
     96        $as_datastore = get_class( ActionScheduler_Store::instance() );
    9697        ?>
    9798
     
    99100            <thead>
    100101                <tr>
    101                     <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e( 'Action Scheduler', 'action-scheduler' ); ?><?php echo wc_help_tip( esc_html__( 'This section shows scheduled action counts.', 'action-scheduler' ) ); ?></h2></th>
     102                    <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e( 'Action Scheduler', 'action-scheduler' ); ?><?php echo wc_help_tip( esc_html__( 'This section shows details of Action Scheduler.', 'action-scheduler' ) ); ?></h2></th>
    102103                </tr>
    103104                <tr>
    104105                    <td colspan="2" data-export-label="Version"><?php esc_html_e( 'Version:', 'action-scheduler' ); ?></td>
    105106                    <td colspan="3"><?php echo esc_html( $as_version ); ?></td>
     107                </tr>
     108                <tr>
     109                    <td colspan="2" data-export-label="Data store"><?php esc_html_e( 'Data store:', 'action-scheduler' ); ?></td>
     110                    <td colspan="3"><?php echo esc_html( $as_datastore ); ?></td>
    106111                </tr>
    107112                <tr>
  • action-scheduler/tags/3.2.0/classes/abstracts/ActionScheduler_Abstract_ListTable.php

    r2340383 r2542151  
    106106     * Makes translation easier, it basically just wraps
    107107     * `_x` with some default (the package name).
    108      * 
     108     *
    109109     * @deprecated 3.0.0
    110110     */
     
    626626        echo '<form id="' . esc_attr( $this->_args['plural'] ) . '-filter" method="get">';
    627627        foreach ( $_GET as $key => $value ) {
    628             if ( '_' === $key[0] || 'paged' === $key ) {
     628            if ( '_' === $key[0] || 'paged' === $key || 'ID' === $key ) {
    629629                continue;
    630630            }
  • action-scheduler/tags/3.2.0/classes/abstracts/ActionScheduler_Store.php

    r2340383 r2542151  
    243243            $action_ids = $this->query_actions(
    244244                array(
    245                     'hook' => $hook,
    246                     'status' => self::STATUS_PENDING,
     245                    'hook'     => $hook,
     246                    'status'   => self::STATUS_PENDING,
    247247                    'per_page' => 1000,
     248                    'orderby'  => 'action_id',
    248249                )
    249250            );
     
    267268            $action_ids = $this->query_actions(
    268269                array(
    269                     'group' => $group,
    270                     'status' => self::STATUS_PENDING,
     270                    'group'    => $group,
     271                    'status'   => self::STATUS_PENDING,
    271272                    'per_page' => 1000,
     273                    'orderby'  => 'action_id',
    272274                )
    273275            );
     
    316318    public function has_pending_actions_due() {
    317319        $pending_actions = $this->query_actions( array(
    318             'date'   => as_get_datetime_object(),
    319             'status' => ActionScheduler_Store::STATUS_PENDING,
     320            'date'    => as_get_datetime_object(),
     321            'status'  => ActionScheduler_Store::STATUS_PENDING,
     322            'orderby' => 'none',
    320323        ) );
    321324
  • action-scheduler/tags/3.2.0/classes/actions/ActionScheduler_Action.php

    r2340383 r2542151  
    2020
    2121    public function execute() {
    22         return do_action_ref_array($this->get_hook(), $this->get_args());
     22        return do_action_ref_array( $this->get_hook(), array_values( $this->get_args() ) );
    2323    }
    2424
  • action-scheduler/tags/3.2.0/classes/data-stores/ActionScheduler_DBStore.php

    r2340383 r2542151  
    99 */
    1010class ActionScheduler_DBStore extends ActionScheduler_Store {
     11
     12    /**
     13     * Used to share information about the before_date property of claims internally.
     14     *
     15     * This is used in preference to passing the same information as a method param
     16     * for backwards-compatibility reasons.
     17     *
     18     * @var DateTime|null
     19     */
     20    private $claim_before_date = null;
    1121
    1222    /** @var int */
     
    359369
    360370        if ( 'select' === $select_or_count ) {
     371            if ( 'ASC' === strtoupper( $query['order'] ) ) {
     372                $order = 'ASC';
     373            } else {
     374                $order = 'DESC';
     375            }
    361376            switch ( $query['orderby'] ) {
    362377                case 'hook':
    363                     $orderby = 'a.hook';
     378                    $sql .= " ORDER BY a.hook $order";
    364379                    break;
    365380                case 'group':
    366                     $orderby = 'g.slug';
     381                    $sql .= " ORDER BY g.slug $order";
    367382                    break;
    368383                case 'modified':
    369                     $orderby = 'a.last_attempt_gmt';
     384                    $sql .= " ORDER BY a.last_attempt_gmt $order";
     385                    break;
     386                case 'none':
     387                    break;
     388                case 'action_id':
     389                    $sql .= " ORDER BY a.action_id $order";
    370390                    break;
    371391                case 'date':
    372392                default:
    373                     $orderby = 'a.scheduled_date_gmt';
     393                    $sql .= " ORDER BY a.scheduled_date_gmt $order";
    374394                    break;
    375395            }
    376             if ( strtoupper( $query[ 'order' ] ) == 'ASC' ) {
    377                 $order = 'ASC';
    378             } else {
    379                 $order = 'DESC';
    380             }
    381             $sql .= " ORDER BY $orderby $order";
     396
    382397            if ( $query[ 'per_page' ] > 0 ) {
    383398                $sql          .= " LIMIT %d, %d";
     
    510525            [
    511526                'per_page' => 1000,
    512                 'status' => self::STATUS_PENDING,
     527                'status'   => self::STATUS_PENDING,
     528                'orderby'  => 'action_id',
    513529            ]
    514530        );
     
    597613    public function stake_claim( $max_actions = 10, \DateTime $before_date = null, $hooks = array(), $group = '' ) {
    598614        $claim_id = $this->generate_claim_id();
     615
     616        $this->claim_before_date = $before_date;
    599617        $this->claim_actions( $claim_id, $max_actions, $before_date, $hooks, $group );
    600618        $action_ids = $this->find_actions_by_claim_id( $claim_id );
     619        $this->claim_before_date = null;
    601620
    602621        return new ActionScheduler_ActionClaim( $claim_id, $action_ids );
     
    712731     * Retrieve the action IDs of action in a claim.
    713732     *
    714      * @param string $claim_id Claim ID.
    715      *
    716733     * @return int[]
    717734     */
     
    720737        global $wpdb;
    721738
    722         $sql = "SELECT action_id FROM {$wpdb->actionscheduler_actions} WHERE claim_id=%d";
    723         $sql = $wpdb->prepare( $sql, $claim_id );
    724 
    725         $action_ids = $wpdb->get_col( $sql );
    726 
    727         return array_map( 'intval', $action_ids );
     739        $action_ids  = array();
     740        $before_date = isset( $this->claim_before_date ) ? $this->claim_before_date : as_get_datetime_object();
     741        $cut_off     = $before_date->format( 'Y-m-d H:i:s' );
     742
     743        $sql = $wpdb->prepare(
     744            "SELECT action_id, scheduled_date_gmt FROM {$wpdb->actionscheduler_actions} WHERE claim_id = %d",
     745            $claim_id
     746        );
     747
     748        // Verify that the scheduled date for each action is within the expected bounds (in some unusual
     749        // cases, we cannot depend on MySQL to honor all of the WHERE conditions we specify).
     750        foreach ( $wpdb->get_results( $sql ) as $claimed_action ) {
     751            if ( $claimed_action->scheduled_date_gmt <= $cut_off ) {
     752                $action_ids[] = absint( $claimed_action->action_id );
     753            }
     754        }
     755
     756        return $action_ids;
    728757    }
    729758
  • action-scheduler/tags/3.2.0/classes/data-stores/ActionScheduler_wpPostStore.php

    r2340383 r2542151  
    99    const SCHEDULE_META_KEY = '_action_manager_schedule';
    1010    const DEPENDENCIES_MET = 'as-post-store-dependencies-met';
     11
     12    /**
     13     * Used to share information about the before_date property of claims internally.
     14     *
     15     * This is used in preference to passing the same information as a method param
     16     * for backwards-compatibility reasons.
     17     *
     18     * @var DateTime|null
     19     */
     20    private $claim_before_date = null;
    1121
    1222    /** @var DateTimeZone */
     
    513523     */
    514524    public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) {
     525        $this->claim_before_date = $before_date;
    515526        $claim_id = $this->generate_claim_id();
    516527        $this->claim_actions( $claim_id, $max_actions, $before_date, $hooks, $group );
    517528        $action_ids = $this->find_actions_by_claim_id( $claim_id );
     529        $this->claim_before_date = null;
    518530
    519531        return new ActionScheduler_ActionClaim( $claim_id, $action_ids );
     
    668680        /** @var wpdb $wpdb */
    669681        global $wpdb;
    670         $sql = "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_password = %s";
     682
     683        $sql = "SELECT ID, post_date_gmt FROM {$wpdb->posts} WHERE post_type = %s AND post_password = %s";
    671684        $sql = $wpdb->prepare( $sql, array( self::POST_TYPE, $claim_id ) );
    672         $action_ids = $wpdb->get_col( $sql );
     685
     686        $action_ids  = array();
     687        $before_date = isset( $this->claim_before_date ) ? $this->claim_before_date : as_get_datetime_object();
     688        $cut_off     = $before_date->format( 'Y-m-d H:i:s' );
     689
     690        // Verify that the scheduled date for each action is within the expected bounds (in some unusual
     691        // cases, we cannot depend on MySQL to honor all of the WHERE conditions we specify).
     692        foreach ( $wpdb->get_results( $sql ) as $claimed_action ) {
     693            if ( $claimed_action->post_date_gmt <= $cut_off ) {
     694                $action_ids[] = absint( $claimed_action->ID );
     695            }
     696        }
     697
    673698        return $action_ids;
    674699    }
  • action-scheduler/tags/3.2.0/classes/migration/Controller.php

    r2340383 r2542151  
    140140     */
    141141    public function display_migration_notice() {
    142         printf( '<div class="notice notice-warning"><p>%s</p></div>', __( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) );
     142        printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) );
    143143    }
    144144
  • action-scheduler/tags/3.2.0/classes/schema/ActionScheduler_StoreSchema.php

    r2340383 r2542151  
    1616     * @var int Increment this value to trigger a schema update.
    1717     */
    18     protected $schema_version = 3;
     18    protected $schema_version = 4;
    1919
    2020    public function __construct() {
     
    5656                        KEY group_id (group_id),
    5757                        KEY last_attempt_gmt (last_attempt_gmt),
    58                         KEY claim_id (claim_id)
     58                        KEY claim_id (claim_id),
     59                        KEY `claim_id_status_scheduled_date_gmt` (`claim_id`, `status`, `scheduled_date_gmt`)
    5960                        ) $charset_collate";
    6061
  • action-scheduler/tags/3.2.0/functions.php

    r2340383 r2542151  
    210210 *        'per_page' => 5 - Number of results to return
    211211 *        'offset' => 0
    212  *        'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', or 'date'
     212 *        'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', 'date' or 'none'
    213213 *        'order' => 'ASC'
    214214 *
  • action-scheduler/tags/3.2.0/readme.txt

    r2340433 r2542151  
    11=== Action Scheduler ===
    2 Contributors: Automattic, wpmuguru
     2Contributors: Automattic, wpmuguru, claudiosanches, peterfabian1000, vedjain, jamosova, obliviousharmony, konamiman, sadowski, royho, barryhughes-1
    33Tags: scheduler, cron
    44Requires at least: 4.7
    5 Tested up to: 5.4
    6 Stable tag: 3.1.6
     5Tested up to: 5.7
     6Stable tag: 3.2.0
    77License: GPLv3
    88Requires PHP: 5.3
     
    4646Collaboration is cool. We'd love to work with you to improve Action Scheduler. [Pull Requests](https://github.com/woocommerce/action-scheduler/pulls) welcome.
    4747
     48== Changelog ==
    4849
     50= 3.2.0 - 2021-06-03 =
     51* Fix - Add "no ordering" option to as_next_scheduled_action().
     52* Fix - Add secondary scheduled date checks when claiming actions (DBStore) | #634.
     53* Fix - Add secondary scheduled date checks when claiming actions (wpPostStore) | #634.
     54* Fix - Adds a new index to the action table, reducing the potential for deadlocks (props: @glagonikas).
     55* Fix - Fix unit tests infrastructure and adapt tests to PHP 8.
     56* Fix - Identify in-use data store.
     57* Fix - Improve test_migration_is_scheduled.
     58* Fix - PHP notice on list table.
     59* Fix - Speed up clean up and batch selects.
     60* Fix - Update pending dependencies.
     61* Fix - [PHP 8.0] Only pass action arg values through to do_action_ref_array().
     62* Fix - [PHP 8] Set the PHP version to 7.1 in composer.json for PHP 8 compatibility.
     63* Fix - add is_initialized() to docs.
     64* Fix - fix file permissions.
     65* Fix - fixes #664 by replacing __ with esc_html__.
  • action-scheduler/trunk/action-scheduler.php

    r2340383 r2542151  
    66 * Author: Automattic
    77 * Author URI: https://automattic.com/
    8  * Version: 3.1.6
     8 * Version: 3.2.0
    99 * License: GPLv3
    1010 *
     
    2626 */
    2727
    28 if ( ! function_exists( 'action_scheduler_register_3_dot_1_dot_6' ) ) {
     28if ( ! function_exists( 'action_scheduler_register_3_dot_2_dot_0' ) ) {
    2929
    3030    if ( ! class_exists( 'ActionScheduler_Versions' ) ) {
     
    3333    }
    3434
    35     add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_1_dot_6', 0, 0 );
     35    add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_2_dot_0', 0, 0 );
    3636
    37     function action_scheduler_register_3_dot_1_dot_6() {
     37    function action_scheduler_register_3_dot_2_dot_0() {
    3838        $versions = ActionScheduler_Versions::instance();
    39         $versions->register( '3.1.6', 'action_scheduler_initialize_3_dot_1_dot_6' );
     39        $versions->register( '3.2.0', 'action_scheduler_initialize_3_dot_2_dot_0' );
    4040    }
    4141
    42     function action_scheduler_initialize_3_dot_1_dot_6() {
     42    function action_scheduler_initialize_3_dot_2_dot_0() {
    4343        require_once( 'classes/abstracts/ActionScheduler.php' );
    4444        ActionScheduler::init( __FILE__ );
     
    4747    // Support usage in themes - load this version if no plugin has loaded a version yet.
    4848    if ( did_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler' ) ) {
    49         action_scheduler_initialize_3_dot_1_dot_6();
     49        action_scheduler_initialize_3_dot_2_dot_0();
    5050        do_action( 'action_scheduler_pre_theme_init' );
    5151        ActionScheduler_Versions::initialize_latest_version();
  • action-scheduler/trunk/classes/ActionScheduler_QueueCleaner.php

    r2340383 r2542151  
    4545                'modified_compare' => '<=',
    4646                'per_page'         => $this->get_batch_size(),
     47                'orderby'          => 'none',
    4748            ) );
    4849
     
    9192            'claimed'          => true,
    9293            'per_page'         => $this->get_batch_size(),
     94            'orderby'          => 'none',
    9395        ) );
    9496
     
    119121            'modified_compare' => '<=',
    120122            'per_page'         => $this->get_batch_size(),
     123            'orderby'          => 'none',
    121124        ) );
    122125
  • action-scheduler/trunk/classes/ActionScheduler_wcSystemStatus.php

    r2340383 r2542151  
    9494    protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) {
    9595        $as_version = ActionScheduler_Versions::instance()->latest_version();
     96        $as_datastore = get_class( ActionScheduler_Store::instance() );
    9697        ?>
    9798
     
    99100            <thead>
    100101                <tr>
    101                     <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e( 'Action Scheduler', 'action-scheduler' ); ?><?php echo wc_help_tip( esc_html__( 'This section shows scheduled action counts.', 'action-scheduler' ) ); ?></h2></th>
     102                    <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e( 'Action Scheduler', 'action-scheduler' ); ?><?php echo wc_help_tip( esc_html__( 'This section shows details of Action Scheduler.', 'action-scheduler' ) ); ?></h2></th>
    102103                </tr>
    103104                <tr>
    104105                    <td colspan="2" data-export-label="Version"><?php esc_html_e( 'Version:', 'action-scheduler' ); ?></td>
    105106                    <td colspan="3"><?php echo esc_html( $as_version ); ?></td>
     107                </tr>
     108                <tr>
     109                    <td colspan="2" data-export-label="Data store"><?php esc_html_e( 'Data store:', 'action-scheduler' ); ?></td>
     110                    <td colspan="3"><?php echo esc_html( $as_datastore ); ?></td>
    106111                </tr>
    107112                <tr>
  • action-scheduler/trunk/classes/abstracts/ActionScheduler_Abstract_ListTable.php

    r2340383 r2542151  
    106106     * Makes translation easier, it basically just wraps
    107107     * `_x` with some default (the package name).
    108      * 
     108     *
    109109     * @deprecated 3.0.0
    110110     */
     
    626626        echo '<form id="' . esc_attr( $this->_args['plural'] ) . '-filter" method="get">';
    627627        foreach ( $_GET as $key => $value ) {
    628             if ( '_' === $key[0] || 'paged' === $key ) {
     628            if ( '_' === $key[0] || 'paged' === $key || 'ID' === $key ) {
    629629                continue;
    630630            }
  • action-scheduler/trunk/classes/abstracts/ActionScheduler_Store.php

    r2340383 r2542151  
    243243            $action_ids = $this->query_actions(
    244244                array(
    245                     'hook' => $hook,
    246                     'status' => self::STATUS_PENDING,
     245                    'hook'     => $hook,
     246                    'status'   => self::STATUS_PENDING,
    247247                    'per_page' => 1000,
     248                    'orderby'  => 'action_id',
    248249                )
    249250            );
     
    267268            $action_ids = $this->query_actions(
    268269                array(
    269                     'group' => $group,
    270                     'status' => self::STATUS_PENDING,
     270                    'group'    => $group,
     271                    'status'   => self::STATUS_PENDING,
    271272                    'per_page' => 1000,
     273                    'orderby'  => 'action_id',
    272274                )
    273275            );
     
    316318    public function has_pending_actions_due() {
    317319        $pending_actions = $this->query_actions( array(
    318             'date'   => as_get_datetime_object(),
    319             'status' => ActionScheduler_Store::STATUS_PENDING,
     320            'date'    => as_get_datetime_object(),
     321            'status'  => ActionScheduler_Store::STATUS_PENDING,
     322            'orderby' => 'none',
    320323        ) );
    321324
  • action-scheduler/trunk/classes/actions/ActionScheduler_Action.php

    r2340383 r2542151  
    2020
    2121    public function execute() {
    22         return do_action_ref_array($this->get_hook(), $this->get_args());
     22        return do_action_ref_array( $this->get_hook(), array_values( $this->get_args() ) );
    2323    }
    2424
  • action-scheduler/trunk/classes/data-stores/ActionScheduler_DBStore.php

    r2340383 r2542151  
    99 */
    1010class ActionScheduler_DBStore extends ActionScheduler_Store {
     11
     12    /**
     13     * Used to share information about the before_date property of claims internally.
     14     *
     15     * This is used in preference to passing the same information as a method param
     16     * for backwards-compatibility reasons.
     17     *
     18     * @var DateTime|null
     19     */
     20    private $claim_before_date = null;
    1121
    1222    /** @var int */
     
    359369
    360370        if ( 'select' === $select_or_count ) {
     371            if ( 'ASC' === strtoupper( $query['order'] ) ) {
     372                $order = 'ASC';
     373            } else {
     374                $order = 'DESC';
     375            }
    361376            switch ( $query['orderby'] ) {
    362377                case 'hook':
    363                     $orderby = 'a.hook';
     378                    $sql .= " ORDER BY a.hook $order";
    364379                    break;
    365380                case 'group':
    366                     $orderby = 'g.slug';
     381                    $sql .= " ORDER BY g.slug $order";
    367382                    break;
    368383                case 'modified':
    369                     $orderby = 'a.last_attempt_gmt';
     384                    $sql .= " ORDER BY a.last_attempt_gmt $order";
     385                    break;
     386                case 'none':
     387                    break;
     388                case 'action_id':
     389                    $sql .= " ORDER BY a.action_id $order";
    370390                    break;
    371391                case 'date':
    372392                default:
    373                     $orderby = 'a.scheduled_date_gmt';
     393                    $sql .= " ORDER BY a.scheduled_date_gmt $order";
    374394                    break;
    375395            }
    376             if ( strtoupper( $query[ 'order' ] ) == 'ASC' ) {
    377                 $order = 'ASC';
    378             } else {
    379                 $order = 'DESC';
    380             }
    381             $sql .= " ORDER BY $orderby $order";
     396
    382397            if ( $query[ 'per_page' ] > 0 ) {
    383398                $sql          .= " LIMIT %d, %d";
     
    510525            [
    511526                'per_page' => 1000,
    512                 'status' => self::STATUS_PENDING,
     527                'status'   => self::STATUS_PENDING,
     528                'orderby'  => 'action_id',
    513529            ]
    514530        );
     
    597613    public function stake_claim( $max_actions = 10, \DateTime $before_date = null, $hooks = array(), $group = '' ) {
    598614        $claim_id = $this->generate_claim_id();
     615
     616        $this->claim_before_date = $before_date;
    599617        $this->claim_actions( $claim_id, $max_actions, $before_date, $hooks, $group );
    600618        $action_ids = $this->find_actions_by_claim_id( $claim_id );
     619        $this->claim_before_date = null;
    601620
    602621        return new ActionScheduler_ActionClaim( $claim_id, $action_ids );
     
    712731     * Retrieve the action IDs of action in a claim.
    713732     *
    714      * @param string $claim_id Claim ID.
    715      *
    716733     * @return int[]
    717734     */
     
    720737        global $wpdb;
    721738
    722         $sql = "SELECT action_id FROM {$wpdb->actionscheduler_actions} WHERE claim_id=%d";
    723         $sql = $wpdb->prepare( $sql, $claim_id );
    724 
    725         $action_ids = $wpdb->get_col( $sql );
    726 
    727         return array_map( 'intval', $action_ids );
     739        $action_ids  = array();
     740        $before_date = isset( $this->claim_before_date ) ? $this->claim_before_date : as_get_datetime_object();
     741        $cut_off     = $before_date->format( 'Y-m-d H:i:s' );
     742
     743        $sql = $wpdb->prepare(
     744            "SELECT action_id, scheduled_date_gmt FROM {$wpdb->actionscheduler_actions} WHERE claim_id = %d",
     745            $claim_id
     746        );
     747
     748        // Verify that the scheduled date for each action is within the expected bounds (in some unusual
     749        // cases, we cannot depend on MySQL to honor all of the WHERE conditions we specify).
     750        foreach ( $wpdb->get_results( $sql ) as $claimed_action ) {
     751            if ( $claimed_action->scheduled_date_gmt <= $cut_off ) {
     752                $action_ids[] = absint( $claimed_action->action_id );
     753            }
     754        }
     755
     756        return $action_ids;
    728757    }
    729758
  • action-scheduler/trunk/classes/data-stores/ActionScheduler_wpPostStore.php

    r2340383 r2542151  
    99    const SCHEDULE_META_KEY = '_action_manager_schedule';
    1010    const DEPENDENCIES_MET = 'as-post-store-dependencies-met';
     11
     12    /**
     13     * Used to share information about the before_date property of claims internally.
     14     *
     15     * This is used in preference to passing the same information as a method param
     16     * for backwards-compatibility reasons.
     17     *
     18     * @var DateTime|null
     19     */
     20    private $claim_before_date = null;
    1121
    1222    /** @var DateTimeZone */
     
    513523     */
    514524    public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) {
     525        $this->claim_before_date = $before_date;
    515526        $claim_id = $this->generate_claim_id();
    516527        $this->claim_actions( $claim_id, $max_actions, $before_date, $hooks, $group );
    517528        $action_ids = $this->find_actions_by_claim_id( $claim_id );
     529        $this->claim_before_date = null;
    518530
    519531        return new ActionScheduler_ActionClaim( $claim_id, $action_ids );
     
    668680        /** @var wpdb $wpdb */
    669681        global $wpdb;
    670         $sql = "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_password = %s";
     682
     683        $sql = "SELECT ID, post_date_gmt FROM {$wpdb->posts} WHERE post_type = %s AND post_password = %s";
    671684        $sql = $wpdb->prepare( $sql, array( self::POST_TYPE, $claim_id ) );
    672         $action_ids = $wpdb->get_col( $sql );
     685
     686        $action_ids  = array();
     687        $before_date = isset( $this->claim_before_date ) ? $this->claim_before_date : as_get_datetime_object();
     688        $cut_off     = $before_date->format( 'Y-m-d H:i:s' );
     689
     690        // Verify that the scheduled date for each action is within the expected bounds (in some unusual
     691        // cases, we cannot depend on MySQL to honor all of the WHERE conditions we specify).
     692        foreach ( $wpdb->get_results( $sql ) as $claimed_action ) {
     693            if ( $claimed_action->post_date_gmt <= $cut_off ) {
     694                $action_ids[] = absint( $claimed_action->ID );
     695            }
     696        }
     697
    673698        return $action_ids;
    674699    }
  • action-scheduler/trunk/classes/migration/Controller.php

    r2340383 r2542151  
    140140     */
    141141    public function display_migration_notice() {
    142         printf( '<div class="notice notice-warning"><p>%s</p></div>', __( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) );
     142        printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) );
    143143    }
    144144
  • action-scheduler/trunk/classes/schema/ActionScheduler_StoreSchema.php

    r2340383 r2542151  
    1616     * @var int Increment this value to trigger a schema update.
    1717     */
    18     protected $schema_version = 3;
     18    protected $schema_version = 4;
    1919
    2020    public function __construct() {
     
    5656                        KEY group_id (group_id),
    5757                        KEY last_attempt_gmt (last_attempt_gmt),
    58                         KEY claim_id (claim_id)
     58                        KEY claim_id (claim_id),
     59                        KEY `claim_id_status_scheduled_date_gmt` (`claim_id`, `status`, `scheduled_date_gmt`)
    5960                        ) $charset_collate";
    6061
  • action-scheduler/trunk/functions.php

    r2340383 r2542151  
    210210 *        'per_page' => 5 - Number of results to return
    211211 *        'offset' => 0
    212  *        'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', or 'date'
     212 *        'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', 'date' or 'none'
    213213 *        'order' => 'ASC'
    214214 *
  • action-scheduler/trunk/readme.txt

    r2340433 r2542151  
    11=== Action Scheduler ===
    2 Contributors: Automattic, wpmuguru
     2Contributors: Automattic, wpmuguru, claudiosanches, peterfabian1000, vedjain, jamosova, obliviousharmony, konamiman, sadowski, royho, barryhughes-1
    33Tags: scheduler, cron
    44Requires at least: 4.7
    5 Tested up to: 5.4
    6 Stable tag: 3.1.6
     5Tested up to: 5.7
     6Stable tag: 3.2.0
    77License: GPLv3
    88Requires PHP: 5.3
     
    4646Collaboration is cool. We'd love to work with you to improve Action Scheduler. [Pull Requests](https://github.com/woocommerce/action-scheduler/pulls) welcome.
    4747
     48== Changelog ==
    4849
     50= 3.2.0 - 2021-06-03 =
     51* Fix - Add "no ordering" option to as_next_scheduled_action().
     52* Fix - Add secondary scheduled date checks when claiming actions (DBStore) | #634.
     53* Fix - Add secondary scheduled date checks when claiming actions (wpPostStore) | #634.
     54* Fix - Adds a new index to the action table, reducing the potential for deadlocks (props: @glagonikas).
     55* Fix - Fix unit tests infrastructure and adapt tests to PHP 8.
     56* Fix - Identify in-use data store.
     57* Fix - Improve test_migration_is_scheduled.
     58* Fix - PHP notice on list table.
     59* Fix - Speed up clean up and batch selects.
     60* Fix - Update pending dependencies.
     61* Fix - [PHP 8.0] Only pass action arg values through to do_action_ref_array().
     62* Fix - [PHP 8] Set the PHP version to 7.1 in composer.json for PHP 8 compatibility.
     63* Fix - add is_initialized() to docs.
     64* Fix - fix file permissions.
     65* Fix - fixes #664 by replacing __ with esc_html__.
Note: See TracChangeset for help on using the changeset viewer.