/**
  * @param string $hook The hook to trigger when this action runs
  * @param array $args Args to pass when the hook is triggered
  * @param int $first Unix timestamp for the first run
  * @param int $schedule A cron definition string
  * @param string $group A group to put the action in
  *
  * @return string The ID of the stored action
  */
 public function cron($hook, $args = array(), $first = NULL, $schedule = NULL, $group = '')
 {
     if (empty($schedule)) {
         return $this->single($hook, $args, $first, $group);
     }
     $date = ActionScheduler::get_datetime_object($first);
     $cron = CronExpression::factory($schedule);
     $schedule = new ActionScheduler_CronSchedule($date, $cron);
     $action = new ActionScheduler_Action($hook, $args, $schedule, $group);
     return $this->store($action);
 }
コード例 #2
0
 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());
 }
コード例 #3
0
 /**
  * Initialize the plugin
  *
  * @static
  * @param string $plugin_file
  * @return void
  */
 public static function init($plugin_file)
 {
     self::$plugin_file = $plugin_file;
     spl_autoload_register(array(__CLASS__, 'autoload'));
     $store = self::store();
     add_action('init', array($store, 'init'), 1, 0);
     $logger = self::logger();
     add_action('init', array($logger, 'init'), 1, 0);
     $runner = self::runner();
     add_action('init', array($runner, 'init'), 1, 0);
     $admin_view = self::admin_view();
     add_action('init', array($admin_view, 'init'), 0, 0);
     // run before $store::init()
     require_once self::plugin_path('functions.php');
 }
 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);
         }
     }
 }
コード例 #5
0
ファイル: action-scheduler.php プロジェクト: bself/nuimage-wp
 function action_scheduler_initialize_1_dot_4_dev()
 {
     require_once 'classes/ActionScheduler.php';
     ActionScheduler::init(__FILE__);
 }
 public function test_filtering_of_get_comments()
 {
     $post_id = $this->factory->post->create_object(array('post_title' => __FUNCTION__));
     $comment_id = $this->factory->comment->create_object(array('comment_post_ID' => $post_id, 'comment_author' => __CLASS__, 'comment_content' => __FUNCTION__));
     // Verify that we're getting the expected comment before we add logging comments
     $comments = get_comments();
     $this->assertCount(1, $comments);
     $this->assertEquals($comment_id, $comments[0]->comment_ID);
     $action_id = wc_schedule_single_action(time(), 'a hook');
     $logger = ActionScheduler::logger();
     $message = 'Logging that something happened';
     $log_id = $logger->log($action_id, $message);
     // Verify that logging comments are excluded from general comment queries
     $comments = get_comments();
     $this->assertCount(1, $comments);
     $this->assertEquals($comment_id, $comments[0]->comment_ID);
     // Verify that logging comments are returned when asking for them specifically
     $comments = get_comments(array('type' => ActionScheduler_wpCommentLogger::TYPE));
     // Expecting two: one when the action is created, another when we added our custom log
     $this->assertCount(2, $comments);
     $this->assertContains($log_id, wp_list_pluck($comments, 'comment_ID'));
 }
コード例 #7
0
    /**
     * 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 
                }
            }
        }
    }
コード例 #8
0
ファイル: functions.php プロジェクト: DustinHartzler/TheCLEFT
/**
 * 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;
}