/** * Utility method to check the action scheduler for dates * * @param string $type the type of scheduled action * @param string $subscription_key key of subscription in the format of order_id_item_id * @return string either 0 or mysql date */ private static function maybe_get_date_from_action_scheduler($type, $subscription) { $action_scheduler = new ActionScheduler_wpPostStore(); $action_id = $action_scheduler->find_action($type, array('subscription_key' => $subscription['subscription_key'])); if (is_numeric($action_id)) { try { $date = $action_scheduler->get_date($action_id); $formatted_date = $date->format('Y-m-d H:i:s'); } catch (Exception $e) { WCS_Upgrade_Logger::add(sprintf('-- For order %d: while fetching date from action scheduler, an error occurred. No such action id.', $subscription['order_id'])); $formatted_date = 0; } } else { $formatted_date = 0; } return $formatted_date; }
public function test_get_run_date() { $time = new DateTime('-10 minutes'); $schedule = new ActionScheduler_IntervalSchedule($time, HOUR_IN_SECONDS); $action = new ActionScheduler_Action('my_hook', array(), $schedule); $store = new ActionScheduler_wpPostStore(); $action_id = $store->save_action($action); $this->assertEquals($store->get_date($action_id)->format('U'), $time->format('U')); $action = $store->fetch_action($action_id); $action->execute(); $now = new DateTime(); $store->mark_complete($action_id); $this->assertEquals($store->get_date($action_id)->format('U'), $now->format('U')); $next = $action->get_schedule()->next($now); $new_action_id = $store->save_action($action, $next); $this->assertEquals((int) $now->format('U') + HOUR_IN_SECONDS, $store->get_date($new_action_id)->format('U')); }