コード例 #1
0
 /**
  * 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_search_by_group()
 {
     $store = new ActionScheduler_wpPostStore();
     $schedule = new ActionScheduler_SimpleSchedule(new DateTime('tomorrow'));
     $abc = $store->save_action(new ActionScheduler_Action('my_hook', array(1), $schedule, 'abc'));
     $def = $store->save_action(new ActionScheduler_Action('my_hook', array(1), $schedule, 'def'));
     $ghi = $store->save_action(new ActionScheduler_Action('my_hook', array(1), $schedule, 'ghi'));
     $this->assertEquals($abc, $store->find_action('my_hook', array('group' => 'abc')));
     $this->assertEquals($def, $store->find_action('my_hook', array('group' => 'def')));
     $this->assertEquals($ghi, $store->find_action('my_hook', array('group' => 'ghi')));
 }