public function test_unschedule()
 {
     $time = time();
     $hook = md5(rand());
     $action_id = wc_schedule_single_action($time, $hook);
     wc_unschedule_action($hook);
     $next = wc_next_scheduled_action($hook);
     $this->assertFalse($next);
     $store = ActionScheduler::store();
     $action = $store->fetch_action($action_id);
     $this->assertNull($action->get_schedule()->next());
     $this->assertEmpty($action->get_hook());
 }
 public function setUp()
 {
     parent::setUp();
     $store = ActionScheduler::store();
     for ($i = 0; $i < 10; $i++) {
         $this->hooks[$i] = md5(rand());
         $this->args[$i] = md5(rand());
         $this->groups[$i] = md5(rand());
     }
     for ($i = 0; $i < 10; $i++) {
         for ($j = 0; $j < 10; $j++) {
             $schedule = new ActionScheduler_SimpleSchedule(new DateTime($j - 3 . 'days'));
             $group = $this->groups[($i + $j) % 10];
             $action = new ActionScheduler_Action($this->hooks[$i], array($this->args[$j]), $schedule, $group);
             $store->save_action($action);
         }
     }
 }
    /**
     * Convert an interval of seconds into a two part human friendly string.
     *
     * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning
     * even if an action is 1 day and 11 hours away, it will display "1 day". This funciton goes one step
     * further to display two degrees of accuracy.
     *
     * Based on Crontrol::interval() funciton by Edward Dale: https://wordpress.org/plugins/wp-crontrol/
     *
     * @param int $interval A interval in seconds.
     * @return string A human friendly string representation of the interval.
     */
    public static function admin_notices()
    {
        if (self::is_admin_page()) {
            if (ActionScheduler_Store::instance()->get_claim_count() >= apply_filters('action_scheduler_queue_runner_concurrent_batches', 5)) {
                ?>
<div id="message" class="updated">
	<p><?php 
                printf(__('Maximum simulatenous batches already in progress (%s queues). No actions will be processed until the current batches are complete.', 'action-scheduler'), ActionScheduler_Store::instance()->get_claim_count());
                ?>
</p>
</div>
			<?php 
            }
            if (isset($_GET['executed']) && isset($_GET['ids'])) {
                $action = ActionScheduler::store()->fetch_action($_GET['ids']);
                $action_hook_html = '<strong>' . $action->get_hook() . '</strong>';
                if (1 == $_GET['executed']) {
                    ?>
<div id="message" class="updated">
	<p><?php 
                    printf(__('Successfully executed the action: %s', 'action-scheduler'), $action_hook_html);
                    ?>
</p>
</div>
			<?php 
                } else {
                    ?>
<div id="message" class="error">
	<p><?php 
                    printf(__('Could not execute the action: %s', 'action-scheduler'), $action_hook_html);
                    ?>
</p>
</div>
			<?php 
                }
            }
        }
    }
예제 #4
0
/**
 * Find scheduled actions
 *
 * @param array $args Possible arguments, with their default values:
 *        'hook' => '' - the name of the action that will be triggered
 *        'args' => NULL - the args array that will be passed with the action
 *        'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
 *        'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '='
 *        'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
 *        'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '='
 *        'group' => '' - the group the action belongs to
 *        'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING
 *        'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID
 *        'per_page' => 5 - Number of results to return
 *        'offset' => 0
 *        'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', or 'date'
 *        'order' => 'ASC'
 *
 * @param string $return_format OBJECT, ARRAY_A, or ids
 *
 * @return array
 */
function wc_get_scheduled_actions($args = array(), $return_format = OBJECT)
{
    $store = ActionScheduler::store();
    foreach (array('date', 'modified') as $key) {
        if (isset($args[$key])) {
            $args[$key] = as_get_datetime_object($args[$key]);
        }
    }
    $ids = $store->query_actions($args);
    if ($return_format == 'ids' || $return_format == 'int') {
        return $ids;
    }
    $actions = array();
    foreach ($ids as $action_id) {
        $actions[$action_id] = $store->fetch_action($action_id);
    }
    if ($return_format == ARRAY_A) {
        foreach ($actions as $action_id => $action_object) {
            $actions[$action_id] = get_object_vars($action_object);
        }
    }
    return $actions;
}