Passed
Pull Request — master (#281)
by Kiran
04:07
created
libraries/action-scheduler/classes/ActionScheduler_WPCommentCleaner.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -7,109 +7,109 @@
 block discarded – undo
7 7
  */
8 8
 class ActionScheduler_WPCommentCleaner {
9 9
 
10
-	/**
11
-	 * Post migration hook used to cleanup the WP comment table.
12
-	 *
13
-	 * @var string
14
-	 */
15
-	protected static $cleanup_hook = 'action_scheduler/cleanup_wp_comment_logs';
16
-
17
-	/**
18
-	 * An instance of the ActionScheduler_wpCommentLogger class to interact with the comments table.
19
-	 *
20
-	 * This instance should only be used as an interface. It should not be initialized.
21
-	 *
22
-	 * @var ActionScheduler_wpCommentLogger
23
-	 */
24
-	protected static $wp_comment_logger = null;
25
-
26
-	/**
27
-	 * The key used to store the cached value of whether there are logs in the WP comment table.
28
-	 *
29
-	 * @var string
30
-	 */
31
-	protected static $has_logs_option_key = 'as_has_wp_comment_logs';
32
-
33
-	/**
34
-	 * Initialize the class and attach callbacks.
35
-	 */
36
-	public static function init() {
37
-		if ( empty( self::$wp_comment_logger ) ) {
38
-			self::$wp_comment_logger = new ActionScheduler_wpCommentLogger();
39
-		}
40
-
41
-		add_action( self::$cleanup_hook, array( __CLASS__, 'delete_all_action_comments' ) );
42
-
43
-		// While there are orphaned logs left in the comments table, we need to attach the callbacks which filter comment counts.
44
-		add_action( 'pre_get_comments', array( self::$wp_comment_logger, 'filter_comment_queries' ), 10, 1 );
45
-		add_action( 'wp_count_comments', array( self::$wp_comment_logger, 'filter_comment_count' ), 20, 2 ); // run after WC_Comments::wp_count_comments() to make sure we exclude order notes and action logs
46
-		add_action( 'comment_feed_where', array( self::$wp_comment_logger, 'filter_comment_feed' ), 10, 2 );
47
-
48
-		// Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
49
-		add_action( 'load-tools_page_action-scheduler', array( __CLASS__, 'register_admin_notice' ) );
50
-		add_action( 'load-woocommerce_page_wc-status', array( __CLASS__, 'register_admin_notice' ) );
51
-	}
52
-
53
-	/**
54
-	 * Determines if there are log entries in the wp comments table.
55
-	 *
56
-	 * Uses the flag set on migration completion set by @see self::maybe_schedule_cleanup().
57
-	 *
58
-	 * @return boolean Whether there are scheduled action comments in the comments table.
59
-	 */
60
-	public static function has_logs() {
61
-		return 'yes' === get_option( self::$has_logs_option_key );
62
-	}
63
-
64
-	/**
65
-	 * Schedules the WP Post comment table cleanup to run in 6 months if it's not already scheduled.
66
-	 * Attached to the migration complete hook 'action_scheduler/migration_complete'.
67
-	 */
68
-	public static function maybe_schedule_cleanup() {
69
-		if ( (bool) get_comments( array( 'type' => ActionScheduler_wpCommentLogger::TYPE, 'number' => 1, 'fields' => 'ids' ) ) ) {
70
-			update_option( self::$has_logs_option_key, 'yes' );
71
-
72
-			if ( ! as_next_scheduled_action( self::$cleanup_hook ) ) {
73
-				as_schedule_single_action( gmdate( 'U' ) + ( 6 * MONTH_IN_SECONDS ), self::$cleanup_hook );
74
-			}
75
-		}
76
-	}
77
-
78
-	/**
79
-	 * Delete all action comments from the WP Comments table.
80
-	 */
81
-	public static function delete_all_action_comments() {
82
-		global $wpdb;
83
-		$wpdb->delete( $wpdb->comments, array( 'comment_type' => ActionScheduler_wpCommentLogger::TYPE, 'comment_agent' => ActionScheduler_wpCommentLogger::AGENT ) );
84
-		delete_option( self::$has_logs_option_key );
85
-	}
86
-
87
-	/**
88
-	 * Registers admin notices about the orphaned action logs.
89
-	 */
90
-	public static function register_admin_notice() {
91
-		add_action( 'admin_notices', array( __CLASS__, 'print_admin_notice' ) );
92
-	}
10
+    /**
11
+     * Post migration hook used to cleanup the WP comment table.
12
+     *
13
+     * @var string
14
+     */
15
+    protected static $cleanup_hook = 'action_scheduler/cleanup_wp_comment_logs';
16
+
17
+    /**
18
+     * An instance of the ActionScheduler_wpCommentLogger class to interact with the comments table.
19
+     *
20
+     * This instance should only be used as an interface. It should not be initialized.
21
+     *
22
+     * @var ActionScheduler_wpCommentLogger
23
+     */
24
+    protected static $wp_comment_logger = null;
25
+
26
+    /**
27
+     * The key used to store the cached value of whether there are logs in the WP comment table.
28
+     *
29
+     * @var string
30
+     */
31
+    protected static $has_logs_option_key = 'as_has_wp_comment_logs';
32
+
33
+    /**
34
+     * Initialize the class and attach callbacks.
35
+     */
36
+    public static function init() {
37
+        if ( empty( self::$wp_comment_logger ) ) {
38
+            self::$wp_comment_logger = new ActionScheduler_wpCommentLogger();
39
+        }
40
+
41
+        add_action( self::$cleanup_hook, array( __CLASS__, 'delete_all_action_comments' ) );
42
+
43
+        // While there are orphaned logs left in the comments table, we need to attach the callbacks which filter comment counts.
44
+        add_action( 'pre_get_comments', array( self::$wp_comment_logger, 'filter_comment_queries' ), 10, 1 );
45
+        add_action( 'wp_count_comments', array( self::$wp_comment_logger, 'filter_comment_count' ), 20, 2 ); // run after WC_Comments::wp_count_comments() to make sure we exclude order notes and action logs
46
+        add_action( 'comment_feed_where', array( self::$wp_comment_logger, 'filter_comment_feed' ), 10, 2 );
47
+
48
+        // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
49
+        add_action( 'load-tools_page_action-scheduler', array( __CLASS__, 'register_admin_notice' ) );
50
+        add_action( 'load-woocommerce_page_wc-status', array( __CLASS__, 'register_admin_notice' ) );
51
+    }
52
+
53
+    /**
54
+     * Determines if there are log entries in the wp comments table.
55
+     *
56
+     * Uses the flag set on migration completion set by @see self::maybe_schedule_cleanup().
57
+     *
58
+     * @return boolean Whether there are scheduled action comments in the comments table.
59
+     */
60
+    public static function has_logs() {
61
+        return 'yes' === get_option( self::$has_logs_option_key );
62
+    }
63
+
64
+    /**
65
+     * Schedules the WP Post comment table cleanup to run in 6 months if it's not already scheduled.
66
+     * Attached to the migration complete hook 'action_scheduler/migration_complete'.
67
+     */
68
+    public static function maybe_schedule_cleanup() {
69
+        if ( (bool) get_comments( array( 'type' => ActionScheduler_wpCommentLogger::TYPE, 'number' => 1, 'fields' => 'ids' ) ) ) {
70
+            update_option( self::$has_logs_option_key, 'yes' );
71
+
72
+            if ( ! as_next_scheduled_action( self::$cleanup_hook ) ) {
73
+                as_schedule_single_action( gmdate( 'U' ) + ( 6 * MONTH_IN_SECONDS ), self::$cleanup_hook );
74
+            }
75
+        }
76
+    }
77
+
78
+    /**
79
+     * Delete all action comments from the WP Comments table.
80
+     */
81
+    public static function delete_all_action_comments() {
82
+        global $wpdb;
83
+        $wpdb->delete( $wpdb->comments, array( 'comment_type' => ActionScheduler_wpCommentLogger::TYPE, 'comment_agent' => ActionScheduler_wpCommentLogger::AGENT ) );
84
+        delete_option( self::$has_logs_option_key );
85
+    }
86
+
87
+    /**
88
+     * Registers admin notices about the orphaned action logs.
89
+     */
90
+    public static function register_admin_notice() {
91
+        add_action( 'admin_notices', array( __CLASS__, 'print_admin_notice' ) );
92
+    }
93 93
 	
94
-	/**
95
-	 * Prints details about the orphaned action logs and includes information on where to learn more.
96
-	 */
97
-	public static function print_admin_notice() {
98
-		$next_cleanup_message        = '';
99
-		$next_scheduled_cleanup_hook = as_next_scheduled_action( self::$cleanup_hook );
100
-
101
-		if ( $next_scheduled_cleanup_hook ) {
102
-			/* translators: %s: date interval */
103
-			$next_cleanup_message = sprintf( __( 'This data will be deleted in %s.', 'action-scheduler' ), human_time_diff( gmdate( 'U' ), $next_scheduled_cleanup_hook ) );
104
-		}
105
-
106
-		$notice = sprintf(
107
-			/* translators: 1: next cleanup message 2: github issue URL */
108
-			__( 'Action Scheduler has migrated data to custom tables; however, orphaned log entries exist in the WordPress Comments table. %1$s <a href="%2$s">Learn more &raquo;</a>', 'action-scheduler' ),
109
-			$next_cleanup_message,
110
-			'https://github.com/woocommerce/action-scheduler/issues/368'
111
-		);
112
-
113
-		echo '<div class="notice notice-warning"><p>' . wp_kses_post( $notice ) . '</p></div>';
114
-	}
94
+    /**
95
+     * Prints details about the orphaned action logs and includes information on where to learn more.
96
+     */
97
+    public static function print_admin_notice() {
98
+        $next_cleanup_message        = '';
99
+        $next_scheduled_cleanup_hook = as_next_scheduled_action( self::$cleanup_hook );
100
+
101
+        if ( $next_scheduled_cleanup_hook ) {
102
+            /* translators: %s: date interval */
103
+            $next_cleanup_message = sprintf( __( 'This data will be deleted in %s.', 'action-scheduler' ), human_time_diff( gmdate( 'U' ), $next_scheduled_cleanup_hook ) );
104
+        }
105
+
106
+        $notice = sprintf(
107
+            /* translators: 1: next cleanup message 2: github issue URL */
108
+            __( 'Action Scheduler has migrated data to custom tables; however, orphaned log entries exist in the WordPress Comments table. %1$s <a href="%2$s">Learn more &raquo;</a>', 'action-scheduler' ),
109
+            $next_cleanup_message,
110
+            'https://github.com/woocommerce/action-scheduler/issues/368'
111
+        );
112
+
113
+        echo '<div class="notice notice-warning"><p>' . wp_kses_post( $notice ) . '</p></div>';
114
+    }
115 115
 }
Please login to merge, or discard this patch.
action-scheduler/classes/actions/ActionScheduler_FinishedAction.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@
 block discarded – undo
5 5
  */
6 6
 class ActionScheduler_FinishedAction extends ActionScheduler_Action {
7 7
 
8
-	public function execute() {
9
-		// don't execute
10
-	}
8
+    public function execute() {
9
+        // don't execute
10
+    }
11 11
 
12
-	public function is_finished() {
13
-		return TRUE;
14
-	}
12
+    public function is_finished() {
13
+        return TRUE;
14
+    }
15 15
 }
16
- 
17 16
\ No newline at end of file
17
+    
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
action-scheduler/classes/actions/ActionScheduler_CanceledAction.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@
 block discarded – undo
8 8
  */
9 9
 class ActionScheduler_CanceledAction extends ActionScheduler_FinishedAction {
10 10
 
11
-	/**
12
-	 * @param string $hook
13
-	 * @param array $args
14
-	 * @param ActionScheduler_Schedule $schedule
15
-	 * @param string $group
16
-	 */
17
-	public function __construct( $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) {
18
-		parent::__construct( $hook, $args, $schedule, $group );
19
-		if ( is_null( $schedule ) ) {
20
-			$this->set_schedule( new ActionScheduler_NullSchedule() );
21
-		}
22
-	}
11
+    /**
12
+     * @param string $hook
13
+     * @param array $args
14
+     * @param ActionScheduler_Schedule $schedule
15
+     * @param string $group
16
+     */
17
+    public function __construct( $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) {
18
+        parent::__construct( $hook, $args, $schedule, $group );
19
+        if ( is_null( $schedule ) ) {
20
+            $this->set_schedule( new ActionScheduler_NullSchedule() );
21
+        }
22
+    }
23 23
 }
Please login to merge, or discard this patch.
libraries/action-scheduler/classes/actions/ActionScheduler_Action.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -4,72 +4,72 @@
 block discarded – undo
4 4
  * Class ActionScheduler_Action
5 5
  */
6 6
 class ActionScheduler_Action {
7
-	protected $hook = '';
8
-	protected $args = array();
9
-	/** @var ActionScheduler_Schedule */
10
-	protected $schedule = NULL;
11
-	protected $group = '';
7
+    protected $hook = '';
8
+    protected $args = array();
9
+    /** @var ActionScheduler_Schedule */
10
+    protected $schedule = NULL;
11
+    protected $group = '';
12 12
 
13
-	public function __construct( $hook, array $args = array(), ActionScheduler_Schedule $schedule = NULL, $group = '' ) {
14
-		$schedule = empty( $schedule ) ? new ActionScheduler_NullSchedule() : $schedule;
15
-		$this->set_hook($hook);
16
-		$this->set_schedule($schedule);
17
-		$this->set_args($args);
18
-		$this->set_group($group);
19
-	}
13
+    public function __construct( $hook, array $args = array(), ActionScheduler_Schedule $schedule = NULL, $group = '' ) {
14
+        $schedule = empty( $schedule ) ? new ActionScheduler_NullSchedule() : $schedule;
15
+        $this->set_hook($hook);
16
+        $this->set_schedule($schedule);
17
+        $this->set_args($args);
18
+        $this->set_group($group);
19
+    }
20 20
 
21
-	public function execute() {
22
-		return do_action_ref_array($this->get_hook(), $this->get_args());
23
-	}
21
+    public function execute() {
22
+        return do_action_ref_array($this->get_hook(), $this->get_args());
23
+    }
24 24
 
25
-	/**
26
-	 * @param string $hook
27
-	 */
28
-	protected function set_hook( $hook ) {
29
-		$this->hook = $hook;
30
-	}
25
+    /**
26
+     * @param string $hook
27
+     */
28
+    protected function set_hook( $hook ) {
29
+        $this->hook = $hook;
30
+    }
31 31
 
32
-	public function get_hook() {
33
-		return $this->hook;
34
-	}
32
+    public function get_hook() {
33
+        return $this->hook;
34
+    }
35 35
 
36
-	protected function set_schedule( ActionScheduler_Schedule $schedule ) {
37
-		$this->schedule = $schedule;
38
-	}
36
+    protected function set_schedule( ActionScheduler_Schedule $schedule ) {
37
+        $this->schedule = $schedule;
38
+    }
39 39
 
40
-	/**
41
-	 * @return ActionScheduler_Schedule
42
-	 */
43
-	public function get_schedule() {
44
-		return $this->schedule;
45
-	}
40
+    /**
41
+     * @return ActionScheduler_Schedule
42
+     */
43
+    public function get_schedule() {
44
+        return $this->schedule;
45
+    }
46 46
 
47
-	protected function set_args( array $args ) {
48
-		$this->args = $args;
49
-	}
47
+    protected function set_args( array $args ) {
48
+        $this->args = $args;
49
+    }
50 50
 
51
-	public function get_args() {
52
-		return $this->args;
53
-	}
51
+    public function get_args() {
52
+        return $this->args;
53
+    }
54 54
 
55
-	/**
56
-	 * @param string $group
57
-	 */
58
-	protected function set_group( $group ) {
59
-		$this->group = $group;
60
-	}
55
+    /**
56
+     * @param string $group
57
+     */
58
+    protected function set_group( $group ) {
59
+        $this->group = $group;
60
+    }
61 61
 
62
-	/**
63
-	 * @return string
64
-	 */
65
-	public function get_group() {
66
-		return $this->group;
67
-	}
62
+    /**
63
+     * @return string
64
+     */
65
+    public function get_group() {
66
+        return $this->group;
67
+    }
68 68
 
69
-	/**
70
-	 * @return bool If the action has been finished
71
-	 */
72
-	public function is_finished() {
73
-		return FALSE;
74
-	}
69
+    /**
70
+     * @return bool If the action has been finished
71
+     */
72
+    public function is_finished() {
73
+        return FALSE;
74
+    }
75 75
 }
Please login to merge, or discard this patch.
libraries/action-scheduler/classes/actions/ActionScheduler_NullAction.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@
 block discarded – undo
5 5
  */
6 6
 class ActionScheduler_NullAction extends ActionScheduler_Action {
7 7
 
8
-	public function __construct( $hook = '', array $args = array(), ActionScheduler_Schedule $schedule = NULL ) {
9
-		$this->set_schedule( new ActionScheduler_NullSchedule() );
10
-	}
8
+    public function __construct( $hook = '', array $args = array(), ActionScheduler_Schedule $schedule = NULL ) {
9
+        $this->set_schedule( new ActionScheduler_NullSchedule() );
10
+    }
11 11
 
12
-	public function execute() {
13
-		// don't execute
14
-	}
12
+    public function execute() {
13
+        // don't execute
14
+    }
15 15
 }
16
- 
17 16
\ No newline at end of file
17
+    
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php 1 patch
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -6,149 +6,149 @@
 block discarded – undo
6 6
  */
7 7
 class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {
8 8
 
9
-	private static $admin_view = NULL;
10
-
11
-	private static $screen_id = 'tools_page_action-scheduler';
12
-
13
-	/** @var ActionScheduler_ListTable */
14
-	protected $list_table;
15
-
16
-	/**
17
-	 * @return ActionScheduler_AdminView
18
-	 * @codeCoverageIgnore
19
-	 */
20
-	public static function instance() {
21
-
22
-		if ( empty( self::$admin_view ) ) {
23
-			$class = apply_filters('action_scheduler_admin_view_class', 'ActionScheduler_AdminView');
24
-			self::$admin_view = new $class();
25
-		}
26
-
27
-		return self::$admin_view;
28
-	}
29
-
30
-	/**
31
-	 * @codeCoverageIgnore
32
-	 */
33
-	public function init() {
34
-		if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) {
35
-
36
-			if ( class_exists( 'WooCommerce' ) ) {
37
-				add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) );
38
-				add_action( 'woocommerce_system_status_report', array( $this, 'system_status_report' ) );
39
-				add_filter( 'woocommerce_admin_status_tabs', array( $this, 'register_system_status_tab' ) );
40
-			}
41
-
42
-			add_action( 'admin_menu', array( $this, 'register_menu' ) );
43
-
44
-			add_action( 'current_screen', array( $this, 'add_help_tabs' ) );
45
-		}
46
-	}
47
-
48
-	public function system_status_report() {
49
-		$table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() );
50
-		$table->render();
51
-	}
52
-
53
-	/**
54
-	 * Registers action-scheduler into WooCommerce > System status.
55
-	 *
56
-	 * @param array $tabs An associative array of tab key => label.
57
-	 * @return array $tabs An associative array of tab key => label, including Action Scheduler's tabs
58
-	 */
59
-	public function register_system_status_tab( array $tabs ) {
60
-		$tabs['action-scheduler'] = __( 'Scheduled Actions', 'action-scheduler' );
61
-
62
-		return $tabs;
63
-	}
64
-
65
-	/**
66
-	 * Include Action Scheduler's administration under the Tools menu.
67
-	 *
68
-	 * A menu under the Tools menu is important for backward compatibility (as that's
69
-	 * where it started), and also provides more convenient access than the WooCommerce
70
-	 * System Status page, and for sites where WooCommerce isn't active.
71
-	 */
72
-	public function register_menu() {
73
-		$hook_suffix = add_submenu_page(
74
-			'tools.php',
75
-			__( 'Scheduled Actions', 'action-scheduler' ),
76
-			__( 'Scheduled Actions', 'action-scheduler' ),
77
-			'manage_options',
78
-			'action-scheduler',
79
-			array( $this, 'render_admin_ui' )
80
-		);
81
-		add_action( 'load-' . $hook_suffix , array( $this, 'process_admin_ui' ) );
82
-	}
83
-
84
-	/**
85
-	 * Triggers processing of any pending actions.
86
-	 */
87
-	public function process_admin_ui() {
88
-		$this->get_list_table();
89
-	}
90
-
91
-	/**
92
-	 * Renders the Admin UI
93
-	 */
94
-	public function render_admin_ui() {
95
-		$table = $this->get_list_table();
96
-		$table->display_page();
97
-	}
98
-
99
-	/**
100
-	 * Get the admin UI object and process any requested actions.
101
-	 *
102
-	 * @return ActionScheduler_ListTable
103
-	 */
104
-	protected function get_list_table() {
105
-		if ( null === $this->list_table ) {
106
-			$this->list_table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
107
-			$this->list_table->process_actions();
108
-		}
109
-
110
-		return $this->list_table;
111
-	}
112
-
113
-	/**
114
-	 * Provide more information about the screen and its data in the help tab.
115
-	 */
116
-	public function add_help_tabs() {
117
-		$screen = get_current_screen();
118
-
119
-		if ( ! $screen || self::$screen_id != $screen->id ) {
120
-			return;
121
-		}
122
-
123
-		$as_version = ActionScheduler_Versions::instance()->latest_version();
124
-		$screen->add_help_tab(
125
-			array(
126
-				'id'      => 'action_scheduler_about',
127
-				'title'   => __( 'About', 'action-scheduler' ),
128
-				'content' =>
129
-					'<h2>' . sprintf( __( 'About Action Scheduler %s', 'action-scheduler' ), $as_version ) . '</h2>' .
130
-					'<p>' .
131
-						__( 'Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'action-scheduler' ) .
132
-					'</p>',
133
-			)
134
-		);
135
-
136
-		$screen->add_help_tab(
137
-			array(
138
-				'id'      => 'action_scheduler_columns',
139
-				'title'   => __( 'Columns', 'action-scheduler' ),
140
-				'content' =>
141
-					'<h2>' . __( 'Scheduled Action Columns', 'action-scheduler' ) . '</h2>' .
142
-					'<ul>' .
143
-					sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Hook', 'action-scheduler' ), __( 'Name of the action hook that will be triggered.', 'action-scheduler' ) ) .
144
-					sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Status', 'action-scheduler' ), __( 'Action statuses are Pending, Complete, Canceled, Failed', 'action-scheduler' ) ) .
145
-					sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Arguments', 'action-scheduler' ), __( 'Optional data array passed to the action hook.', 'action-scheduler' ) ) .
146
-					sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Group', 'action-scheduler' ), __( 'Optional action group.', 'action-scheduler' ) ) .
147
-					sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Recurrence', 'action-scheduler' ), __( 'The action\'s schedule frequency.', 'action-scheduler' ) ) .
148
-					sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Scheduled', 'action-scheduler' ), __( 'The date/time the action is/was scheduled to run.', 'action-scheduler' ) ) .
149
-					sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Log', 'action-scheduler' ), __( 'Activity log for the action.', 'action-scheduler' ) ) .
150
-					'</ul>',
151
-			)
152
-		);
153
-	}
9
+    private static $admin_view = NULL;
10
+
11
+    private static $screen_id = 'tools_page_action-scheduler';
12
+
13
+    /** @var ActionScheduler_ListTable */
14
+    protected $list_table;
15
+
16
+    /**
17
+     * @return ActionScheduler_AdminView
18
+     * @codeCoverageIgnore
19
+     */
20
+    public static function instance() {
21
+
22
+        if ( empty( self::$admin_view ) ) {
23
+            $class = apply_filters('action_scheduler_admin_view_class', 'ActionScheduler_AdminView');
24
+            self::$admin_view = new $class();
25
+        }
26
+
27
+        return self::$admin_view;
28
+    }
29
+
30
+    /**
31
+     * @codeCoverageIgnore
32
+     */
33
+    public function init() {
34
+        if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) {
35
+
36
+            if ( class_exists( 'WooCommerce' ) ) {
37
+                add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) );
38
+                add_action( 'woocommerce_system_status_report', array( $this, 'system_status_report' ) );
39
+                add_filter( 'woocommerce_admin_status_tabs', array( $this, 'register_system_status_tab' ) );
40
+            }
41
+
42
+            add_action( 'admin_menu', array( $this, 'register_menu' ) );
43
+
44
+            add_action( 'current_screen', array( $this, 'add_help_tabs' ) );
45
+        }
46
+    }
47
+
48
+    public function system_status_report() {
49
+        $table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() );
50
+        $table->render();
51
+    }
52
+
53
+    /**
54
+     * Registers action-scheduler into WooCommerce > System status.
55
+     *
56
+     * @param array $tabs An associative array of tab key => label.
57
+     * @return array $tabs An associative array of tab key => label, including Action Scheduler's tabs
58
+     */
59
+    public function register_system_status_tab( array $tabs ) {
60
+        $tabs['action-scheduler'] = __( 'Scheduled Actions', 'action-scheduler' );
61
+
62
+        return $tabs;
63
+    }
64
+
65
+    /**
66
+     * Include Action Scheduler's administration under the Tools menu.
67
+     *
68
+     * A menu under the Tools menu is important for backward compatibility (as that's
69
+     * where it started), and also provides more convenient access than the WooCommerce
70
+     * System Status page, and for sites where WooCommerce isn't active.
71
+     */
72
+    public function register_menu() {
73
+        $hook_suffix = add_submenu_page(
74
+            'tools.php',
75
+            __( 'Scheduled Actions', 'action-scheduler' ),
76
+            __( 'Scheduled Actions', 'action-scheduler' ),
77
+            'manage_options',
78
+            'action-scheduler',
79
+            array( $this, 'render_admin_ui' )
80
+        );
81
+        add_action( 'load-' . $hook_suffix , array( $this, 'process_admin_ui' ) );
82
+    }
83
+
84
+    /**
85
+     * Triggers processing of any pending actions.
86
+     */
87
+    public function process_admin_ui() {
88
+        $this->get_list_table();
89
+    }
90
+
91
+    /**
92
+     * Renders the Admin UI
93
+     */
94
+    public function render_admin_ui() {
95
+        $table = $this->get_list_table();
96
+        $table->display_page();
97
+    }
98
+
99
+    /**
100
+     * Get the admin UI object and process any requested actions.
101
+     *
102
+     * @return ActionScheduler_ListTable
103
+     */
104
+    protected function get_list_table() {
105
+        if ( null === $this->list_table ) {
106
+            $this->list_table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
107
+            $this->list_table->process_actions();
108
+        }
109
+
110
+        return $this->list_table;
111
+    }
112
+
113
+    /**
114
+     * Provide more information about the screen and its data in the help tab.
115
+     */
116
+    public function add_help_tabs() {
117
+        $screen = get_current_screen();
118
+
119
+        if ( ! $screen || self::$screen_id != $screen->id ) {
120
+            return;
121
+        }
122
+
123
+        $as_version = ActionScheduler_Versions::instance()->latest_version();
124
+        $screen->add_help_tab(
125
+            array(
126
+                'id'      => 'action_scheduler_about',
127
+                'title'   => __( 'About', 'action-scheduler' ),
128
+                'content' =>
129
+                    '<h2>' . sprintf( __( 'About Action Scheduler %s', 'action-scheduler' ), $as_version ) . '</h2>' .
130
+                    '<p>' .
131
+                        __( 'Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'action-scheduler' ) .
132
+                    '</p>',
133
+            )
134
+        );
135
+
136
+        $screen->add_help_tab(
137
+            array(
138
+                'id'      => 'action_scheduler_columns',
139
+                'title'   => __( 'Columns', 'action-scheduler' ),
140
+                'content' =>
141
+                    '<h2>' . __( 'Scheduled Action Columns', 'action-scheduler' ) . '</h2>' .
142
+                    '<ul>' .
143
+                    sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Hook', 'action-scheduler' ), __( 'Name of the action hook that will be triggered.', 'action-scheduler' ) ) .
144
+                    sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Status', 'action-scheduler' ), __( 'Action statuses are Pending, Complete, Canceled, Failed', 'action-scheduler' ) ) .
145
+                    sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Arguments', 'action-scheduler' ), __( 'Optional data array passed to the action hook.', 'action-scheduler' ) ) .
146
+                    sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Group', 'action-scheduler' ), __( 'Optional action group.', 'action-scheduler' ) ) .
147
+                    sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Recurrence', 'action-scheduler' ), __( 'The action\'s schedule frequency.', 'action-scheduler' ) ) .
148
+                    sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Scheduled', 'action-scheduler' ), __( 'The date/time the action is/was scheduled to run.', 'action-scheduler' ) ) .
149
+                    sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Log', 'action-scheduler' ), __( 'Activity log for the action.', 'action-scheduler' ) ) .
150
+                    '</ul>',
151
+            )
152
+        );
153
+    }
154 154
 }
Please login to merge, or discard this patch.
libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -5,175 +5,175 @@
 block discarded – undo
5 5
  */
6 6
 class ActionScheduler_ActionFactory {
7 7
 
8
-	/**
9
-	 * @param string $status The action's status in the data store
10
-	 * @param string $hook The hook to trigger when this action runs
11
-	 * @param array $args Args to pass to callbacks when the hook is triggered
12
-	 * @param ActionScheduler_Schedule $schedule The action's schedule
13
-	 * @param string $group A group to put the action in
14
-	 *
15
-	 * @return ActionScheduler_Action An instance of the stored action
16
-	 */
17
-	public function get_stored_action( $status, $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) {
8
+    /**
9
+     * @param string $status The action's status in the data store
10
+     * @param string $hook The hook to trigger when this action runs
11
+     * @param array $args Args to pass to callbacks when the hook is triggered
12
+     * @param ActionScheduler_Schedule $schedule The action's schedule
13
+     * @param string $group A group to put the action in
14
+     *
15
+     * @return ActionScheduler_Action An instance of the stored action
16
+     */
17
+    public function get_stored_action( $status, $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) {
18 18
 
19
-		switch ( $status ) {
20
-			case ActionScheduler_Store::STATUS_PENDING :
21
-				$action_class = 'ActionScheduler_Action';
22
-				break;
23
-			case ActionScheduler_Store::STATUS_CANCELED :
24
-				$action_class = 'ActionScheduler_CanceledAction';
25
-				if ( ! is_null( $schedule ) && ! is_a( $schedule, 'ActionScheduler_CanceledSchedule' ) ) {
26
-					$schedule = new ActionScheduler_CanceledSchedule( $schedule->get_date() );
27
-				}
28
-				break;
29
-			default :
30
-				$action_class = 'ActionScheduler_FinishedAction';
31
-				break;
32
-		}
19
+        switch ( $status ) {
20
+            case ActionScheduler_Store::STATUS_PENDING :
21
+                $action_class = 'ActionScheduler_Action';
22
+                break;
23
+            case ActionScheduler_Store::STATUS_CANCELED :
24
+                $action_class = 'ActionScheduler_CanceledAction';
25
+                if ( ! is_null( $schedule ) && ! is_a( $schedule, 'ActionScheduler_CanceledSchedule' ) ) {
26
+                    $schedule = new ActionScheduler_CanceledSchedule( $schedule->get_date() );
27
+                }
28
+                break;
29
+            default :
30
+                $action_class = 'ActionScheduler_FinishedAction';
31
+                break;
32
+        }
33 33
 
34
-		$action_class = apply_filters( 'action_scheduler_stored_action_class', $action_class, $status, $hook, $args, $schedule, $group );
34
+        $action_class = apply_filters( 'action_scheduler_stored_action_class', $action_class, $status, $hook, $args, $schedule, $group );
35 35
 
36
-		$action = new $action_class( $hook, $args, $schedule, $group );
36
+        $action = new $action_class( $hook, $args, $schedule, $group );
37 37
 
38
-		/**
39
-		 * Allow 3rd party code to change the instantiated action for a given hook, args, schedule and group.
40
-		 *
41
-		 * @param ActionScheduler_Action $action The instantiated action.
42
-		 * @param string $hook The instantiated action's hook.
43
-		 * @param array $args The instantiated action's args.
44
-		 * @param ActionScheduler_Schedule $schedule The instantiated action's schedule.
45
-		 * @param string $group The instantiated action's group.
46
-		 */
47
-		return apply_filters( 'action_scheduler_stored_action_instance', $action, $hook, $args, $schedule, $group );
48
-	}
38
+        /**
39
+         * Allow 3rd party code to change the instantiated action for a given hook, args, schedule and group.
40
+         *
41
+         * @param ActionScheduler_Action $action The instantiated action.
42
+         * @param string $hook The instantiated action's hook.
43
+         * @param array $args The instantiated action's args.
44
+         * @param ActionScheduler_Schedule $schedule The instantiated action's schedule.
45
+         * @param string $group The instantiated action's group.
46
+         */
47
+        return apply_filters( 'action_scheduler_stored_action_instance', $action, $hook, $args, $schedule, $group );
48
+    }
49 49
 
50
-	/**
51
-	 * Enqueue an action to run one time, as soon as possible (rather a specific scheduled time).
52
-	 *
53
-	 * This method creates a new action with the NULLSchedule. This schedule maps to a MySQL datetime string of
54
-	 * 0000-00-00 00:00:00. This is done to create a psuedo "async action" type that is fully backward compatible.
55
-	 * Existing queries to claim actions claim by date, meaning actions scheduled for 0000-00-00 00:00:00 will
56
-	 * always be claimed prior to actions scheduled for a specific date. This makes sure that any async action is
57
-	 * given priority in queue processing. This has the added advantage of making sure async actions can be
58
-	 * claimed by both the existing WP Cron and WP CLI runners, as well as a new async request runner.
59
-	 *
60
-	 * @param string $hook The hook to trigger when this action runs
61
-	 * @param array $args Args to pass when the hook is triggered
62
-	 * @param string $group A group to put the action in
63
-	 *
64
-	 * @return string The ID of the stored action
65
-	 */
66
-	public function async( $hook, $args = array(), $group = '' ) {
67
-		$schedule = new ActionScheduler_NullSchedule();
68
-		$action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
69
-		return $this->store( $action );
70
-	}
50
+    /**
51
+     * Enqueue an action to run one time, as soon as possible (rather a specific scheduled time).
52
+     *
53
+     * This method creates a new action with the NULLSchedule. This schedule maps to a MySQL datetime string of
54
+     * 0000-00-00 00:00:00. This is done to create a psuedo "async action" type that is fully backward compatible.
55
+     * Existing queries to claim actions claim by date, meaning actions scheduled for 0000-00-00 00:00:00 will
56
+     * always be claimed prior to actions scheduled for a specific date. This makes sure that any async action is
57
+     * given priority in queue processing. This has the added advantage of making sure async actions can be
58
+     * claimed by both the existing WP Cron and WP CLI runners, as well as a new async request runner.
59
+     *
60
+     * @param string $hook The hook to trigger when this action runs
61
+     * @param array $args Args to pass when the hook is triggered
62
+     * @param string $group A group to put the action in
63
+     *
64
+     * @return string The ID of the stored action
65
+     */
66
+    public function async( $hook, $args = array(), $group = '' ) {
67
+        $schedule = new ActionScheduler_NullSchedule();
68
+        $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
69
+        return $this->store( $action );
70
+    }
71 71
 
72
-	/**
73
-	 * @param string $hook The hook to trigger when this action runs
74
-	 * @param array $args Args to pass when the hook is triggered
75
-	 * @param int $when Unix timestamp when the action will run
76
-	 * @param string $group A group to put the action in
77
-	 *
78
-	 * @return string The ID of the stored action
79
-	 */
80
-	public function single( $hook, $args = array(), $when = null, $group = '' ) {
81
-		$date = as_get_datetime_object( $when );
82
-		$schedule = new ActionScheduler_SimpleSchedule( $date );
83
-		$action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
84
-		return $this->store( $action );
85
-	}
72
+    /**
73
+     * @param string $hook The hook to trigger when this action runs
74
+     * @param array $args Args to pass when the hook is triggered
75
+     * @param int $when Unix timestamp when the action will run
76
+     * @param string $group A group to put the action in
77
+     *
78
+     * @return string The ID of the stored action
79
+     */
80
+    public function single( $hook, $args = array(), $when = null, $group = '' ) {
81
+        $date = as_get_datetime_object( $when );
82
+        $schedule = new ActionScheduler_SimpleSchedule( $date );
83
+        $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
84
+        return $this->store( $action );
85
+    }
86 86
 
87
-	/**
88
-	 * Create the first instance of an action recurring on a given interval.
89
-	 *
90
-	 * @param string $hook The hook to trigger when this action runs
91
-	 * @param array $args Args to pass when the hook is triggered
92
-	 * @param int $first Unix timestamp for the first run
93
-	 * @param int $interval Seconds between runs
94
-	 * @param string $group A group to put the action in
95
-	 *
96
-	 * @return string The ID of the stored action
97
-	 */
98
-	public function recurring( $hook, $args = array(), $first = null, $interval = null, $group = '' ) {
99
-		if ( empty($interval) ) {
100
-			return $this->single( $hook, $args, $first, $group );
101
-		}
102
-		$date = as_get_datetime_object( $first );
103
-		$schedule = new ActionScheduler_IntervalSchedule( $date, $interval );
104
-		$action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
105
-		return $this->store( $action );
106
-	}
87
+    /**
88
+     * Create the first instance of an action recurring on a given interval.
89
+     *
90
+     * @param string $hook The hook to trigger when this action runs
91
+     * @param array $args Args to pass when the hook is triggered
92
+     * @param int $first Unix timestamp for the first run
93
+     * @param int $interval Seconds between runs
94
+     * @param string $group A group to put the action in
95
+     *
96
+     * @return string The ID of the stored action
97
+     */
98
+    public function recurring( $hook, $args = array(), $first = null, $interval = null, $group = '' ) {
99
+        if ( empty($interval) ) {
100
+            return $this->single( $hook, $args, $first, $group );
101
+        }
102
+        $date = as_get_datetime_object( $first );
103
+        $schedule = new ActionScheduler_IntervalSchedule( $date, $interval );
104
+        $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
105
+        return $this->store( $action );
106
+    }
107 107
 
108
-	/**
109
-	 * Create the first instance of an action recurring on a Cron schedule.
110
-	 *
111
-	 * @param string $hook The hook to trigger when this action runs
112
-	 * @param array $args Args to pass when the hook is triggered
113
-	 * @param int $base_timestamp The first instance of the action will be scheduled
114
-	 *        to run at a time calculated after this timestamp matching the cron
115
-	 *        expression. This can be used to delay the first instance of the action.
116
-	 * @param int $schedule A cron definition string
117
-	 * @param string $group A group to put the action in
118
-	 *
119
-	 * @return string The ID of the stored action
120
-	 */
121
-	public function cron( $hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '' ) {
122
-		if ( empty($schedule) ) {
123
-			return $this->single( $hook, $args, $base_timestamp, $group );
124
-		}
125
-		$date = as_get_datetime_object( $base_timestamp );
126
-		$cron = CronExpression::factory( $schedule );
127
-		$schedule = new ActionScheduler_CronSchedule( $date, $cron );
128
-		$action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
129
-		return $this->store( $action );
130
-	}
108
+    /**
109
+     * Create the first instance of an action recurring on a Cron schedule.
110
+     *
111
+     * @param string $hook The hook to trigger when this action runs
112
+     * @param array $args Args to pass when the hook is triggered
113
+     * @param int $base_timestamp The first instance of the action will be scheduled
114
+     *        to run at a time calculated after this timestamp matching the cron
115
+     *        expression. This can be used to delay the first instance of the action.
116
+     * @param int $schedule A cron definition string
117
+     * @param string $group A group to put the action in
118
+     *
119
+     * @return string The ID of the stored action
120
+     */
121
+    public function cron( $hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '' ) {
122
+        if ( empty($schedule) ) {
123
+            return $this->single( $hook, $args, $base_timestamp, $group );
124
+        }
125
+        $date = as_get_datetime_object( $base_timestamp );
126
+        $cron = CronExpression::factory( $schedule );
127
+        $schedule = new ActionScheduler_CronSchedule( $date, $cron );
128
+        $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
129
+        return $this->store( $action );
130
+    }
131 131
 
132
-	/**
133
-	 * Create a successive instance of a recurring or cron action.
134
-	 *
135
-	 * Importantly, the action will be rescheduled to run based on the current date/time.
136
-	 * That means when the action is scheduled to run in the past, the next scheduled date
137
-	 * will be pushed forward. For example, if a recurring action set to run every hour
138
-	 * was scheduled to run 5 seconds ago, it will be next scheduled for 1 hour in the
139
-	 * future, which is 1 hour and 5 seconds from when it was last scheduled to run.
140
-	 *
141
-	 * Alternatively, if the action is scheduled to run in the future, and is run early,
142
-	 * likely via manual intervention, then its schedule will change based on the time now.
143
-	 * For example, if a recurring action set to run every day, and is run 12 hours early,
144
-	 * it will run again in 24 hours, not 36 hours.
145
-	 *
146
-	 * This slippage is less of an issue with Cron actions, as the specific run time can
147
-	 * be set for them to run, e.g. 1am each day. In those cases, and entire period would
148
-	 * need to be missed before there was any change is scheduled, e.g. in the case of an
149
-	 * action scheduled for 1am each day, the action would need to run an entire day late.
150
-	 *
151
-	 * @param ActionScheduler_Action $action The existing action.
152
-	 *
153
-	 * @return string The ID of the stored action
154
-	 * @throws InvalidArgumentException If $action is not a recurring action.
155
-	 */
156
-	public function repeat( $action ) {
157
-		$schedule = $action->get_schedule();
158
-		$next     = $schedule->get_next( as_get_datetime_object() );
132
+    /**
133
+     * Create a successive instance of a recurring or cron action.
134
+     *
135
+     * Importantly, the action will be rescheduled to run based on the current date/time.
136
+     * That means when the action is scheduled to run in the past, the next scheduled date
137
+     * will be pushed forward. For example, if a recurring action set to run every hour
138
+     * was scheduled to run 5 seconds ago, it will be next scheduled for 1 hour in the
139
+     * future, which is 1 hour and 5 seconds from when it was last scheduled to run.
140
+     *
141
+     * Alternatively, if the action is scheduled to run in the future, and is run early,
142
+     * likely via manual intervention, then its schedule will change based on the time now.
143
+     * For example, if a recurring action set to run every day, and is run 12 hours early,
144
+     * it will run again in 24 hours, not 36 hours.
145
+     *
146
+     * This slippage is less of an issue with Cron actions, as the specific run time can
147
+     * be set for them to run, e.g. 1am each day. In those cases, and entire period would
148
+     * need to be missed before there was any change is scheduled, e.g. in the case of an
149
+     * action scheduled for 1am each day, the action would need to run an entire day late.
150
+     *
151
+     * @param ActionScheduler_Action $action The existing action.
152
+     *
153
+     * @return string The ID of the stored action
154
+     * @throws InvalidArgumentException If $action is not a recurring action.
155
+     */
156
+    public function repeat( $action ) {
157
+        $schedule = $action->get_schedule();
158
+        $next     = $schedule->get_next( as_get_datetime_object() );
159 159
 
160
-		if ( is_null( $next ) || ! $schedule->is_recurring() ) {
161
-			throw new InvalidArgumentException( __( 'Invalid action - must be a recurring action.', 'action-scheduler' ) );
162
-		}
160
+        if ( is_null( $next ) || ! $schedule->is_recurring() ) {
161
+            throw new InvalidArgumentException( __( 'Invalid action - must be a recurring action.', 'action-scheduler' ) );
162
+        }
163 163
 
164
-		$schedule_class = get_class( $schedule );
165
-		$new_schedule = new $schedule( $next, $schedule->get_recurrence(), $schedule->get_first_date() );
166
-		$new_action = new ActionScheduler_Action( $action->get_hook(), $action->get_args(), $new_schedule, $action->get_group() );
167
-		return $this->store( $new_action );
168
-	}
164
+        $schedule_class = get_class( $schedule );
165
+        $new_schedule = new $schedule( $next, $schedule->get_recurrence(), $schedule->get_first_date() );
166
+        $new_action = new ActionScheduler_Action( $action->get_hook(), $action->get_args(), $new_schedule, $action->get_group() );
167
+        return $this->store( $new_action );
168
+    }
169 169
 
170
-	/**
171
-	 * @param ActionScheduler_Action $action
172
-	 *
173
-	 * @return string The ID of the stored action
174
-	 */
175
-	protected function store( ActionScheduler_Action $action ) {
176
-		$store = ActionScheduler_Store::instance();
177
-		return $store->save_action( $action );
178
-	}
170
+    /**
171
+     * @param ActionScheduler_Action $action
172
+     *
173
+     * @return string The ID of the stored action
174
+     */
175
+    protected function store( ActionScheduler_Action $action ) {
176
+        $store = ActionScheduler_Store::instance();
177
+        return $store->save_action( $action );
178
+    }
179 179
 }
Please login to merge, or discard this patch.
includes/libraries/action-scheduler/classes/migration/BatchFetcher.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -16,71 +16,71 @@
 block discarded – undo
16 16
  * @codeCoverageIgnore
17 17
  */
18 18
 class BatchFetcher {
19
-	/** var ActionScheduler_Store */
20
-	private $store;
19
+    /** var ActionScheduler_Store */
20
+    private $store;
21 21
 
22
-	/**
23
-	 * BatchFetcher constructor.
24
-	 *
25
-	 * @param ActionScheduler_Store $source_store Source store object.
26
-	 */
27
-	public function __construct( Store $source_store ) {
28
-		$this->store = $source_store;
29
-	}
22
+    /**
23
+     * BatchFetcher constructor.
24
+     *
25
+     * @param ActionScheduler_Store $source_store Source store object.
26
+     */
27
+    public function __construct( Store $source_store ) {
28
+        $this->store = $source_store;
29
+    }
30 30
 
31
-	/**
32
-	 * Retrieve a list of actions.
33
-	 *
34
-	 * @param int $count The number of actions to retrieve
35
-	 *
36
-	 * @return int[] A list of action IDs
37
-	 */
38
-	public function fetch( $count = 10 ) {
39
-		foreach ( $this->get_query_strategies( $count ) as $query ) {
40
-			$action_ids = $this->store->query_actions( $query );
41
-			if ( ! empty( $action_ids ) ) {
42
-				return $action_ids;
43
-			}
44
-		}
31
+    /**
32
+     * Retrieve a list of actions.
33
+     *
34
+     * @param int $count The number of actions to retrieve
35
+     *
36
+     * @return int[] A list of action IDs
37
+     */
38
+    public function fetch( $count = 10 ) {
39
+        foreach ( $this->get_query_strategies( $count ) as $query ) {
40
+            $action_ids = $this->store->query_actions( $query );
41
+            if ( ! empty( $action_ids ) ) {
42
+                return $action_ids;
43
+            }
44
+        }
45 45
 
46
-		return [];
47
-	}
46
+        return [];
47
+    }
48 48
 
49
-	/**
50
-	 * Generate a list of prioritized of action search parameters.
51
-	 *
52
-	 * @param int $count Number of actions to find.
53
-	 *
54
-	 * @return array
55
-	 */
56
-	private function get_query_strategies( $count ) {
57
-		$now  = as_get_datetime_object();
58
-		$args = [
59
-			'date'     => $now,
60
-			'per_page' => $count,
61
-			'offset'   => 0,
62
-			'orderby'  => 'date',
63
-			'order'    => 'ASC',
64
-		];
49
+    /**
50
+     * Generate a list of prioritized of action search parameters.
51
+     *
52
+     * @param int $count Number of actions to find.
53
+     *
54
+     * @return array
55
+     */
56
+    private function get_query_strategies( $count ) {
57
+        $now  = as_get_datetime_object();
58
+        $args = [
59
+            'date'     => $now,
60
+            'per_page' => $count,
61
+            'offset'   => 0,
62
+            'orderby'  => 'date',
63
+            'order'    => 'ASC',
64
+        ];
65 65
 
66
-		$priorities = [
67
-			Store::STATUS_PENDING,
68
-			Store::STATUS_FAILED,
69
-			Store::STATUS_CANCELED,
70
-			Store::STATUS_COMPLETE,
71
-			Store::STATUS_RUNNING,
72
-			'', // any other unanticipated status
73
-		];
66
+        $priorities = [
67
+            Store::STATUS_PENDING,
68
+            Store::STATUS_FAILED,
69
+            Store::STATUS_CANCELED,
70
+            Store::STATUS_COMPLETE,
71
+            Store::STATUS_RUNNING,
72
+            '', // any other unanticipated status
73
+        ];
74 74
 
75
-		foreach ( $priorities as $status ) {
76
-			yield wp_parse_args( [
77
-				'status'       => $status,
78
-				'date_compare' => '<=',
79
-			], $args );
80
-			yield wp_parse_args( [
81
-				'status'       => $status,
82
-				'date_compare' => '>=',
83
-			], $args );
84
-		}
85
-	}
75
+        foreach ( $priorities as $status ) {
76
+            yield wp_parse_args( [
77
+                'status'       => $status,
78
+                'date_compare' => '<=',
79
+            ], $args );
80
+            yield wp_parse_args( [
81
+                'status'       => $status,
82
+                'date_compare' => '>=',
83
+            ], $args );
84
+        }
85
+    }
86 86
 }
87 87
\ No newline at end of file
Please login to merge, or discard this patch.
includes/libraries/action-scheduler/classes/migration/Config.php 1 patch
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -17,152 +17,152 @@
 block discarded – undo
17 17
  * A config builder for the ActionScheduler\Migration\Runner class
18 18
  */
19 19
 class Config {
20
-	/** @var ActionScheduler_Store */
21
-	private $source_store;
22
-
23
-	/** @var ActionScheduler_Logger */
24
-	private $source_logger;
25
-
26
-	/** @var ActionScheduler_Store */
27
-	private $destination_store;
28
-
29
-	/** @var ActionScheduler_Logger */
30
-	private $destination_logger;
31
-
32
-	/** @var Progress bar */
33
-	private $progress_bar;
34
-
35
-	/** @var bool */
36
-	private $dry_run = false;
37
-
38
-	/**
39
-	 * Config constructor.
40
-	 */
41
-	public function __construct() {
42
-
43
-	}
44
-
45
-	/**
46
-	 * Get the configured source store.
47
-	 *
48
-	 * @return ActionScheduler_Store
49
-	 */
50
-	public function get_source_store() {
51
-		if ( empty( $this->source_store ) ) {
52
-			throw new \RuntimeException( __( 'Source store must be configured before running a migration', 'action-scheduler' ) );
53
-		}
54
-
55
-		return $this->source_store;
56
-	}
57
-
58
-	/**
59
-	 * Set the configured source store.
60
-	 *
61
-	 * @param ActionScheduler_Store $store Source store object.
62
-	 */
63
-	public function set_source_store( Store $store ) {
64
-		$this->source_store = $store;
65
-	}
66
-
67
-	/**
68
-	 * Get the configured source loger.
69
-	 *
70
-	 * @return ActionScheduler_Logger
71
-	 */
72
-	public function get_source_logger() {
73
-		if ( empty( $this->source_logger ) ) {
74
-			throw new \RuntimeException( __( 'Source logger must be configured before running a migration', 'action-scheduler' ) );
75
-		}
76
-
77
-		return $this->source_logger;
78
-	}
79
-
80
-	/**
81
-	 * Set the configured source logger.
82
-	 *
83
-	 * @param ActionScheduler_Logger $logger
84
-	 */
85
-	public function set_source_logger( Logger $logger ) {
86
-		$this->source_logger = $logger;
87
-	}
88
-
89
-	/**
90
-	 * Get the configured destination store.
91
-	 *
92
-	 * @return ActionScheduler_Store
93
-	 */
94
-	public function get_destination_store() {
95
-		if ( empty( $this->destination_store ) ) {
96
-			throw new \RuntimeException( __( 'Destination store must be configured before running a migration', 'action-scheduler' ) );
97
-		}
98
-
99
-		return $this->destination_store;
100
-	}
101
-
102
-	/**
103
-	 * Set the configured destination store.
104
-	 *
105
-	 * @param ActionScheduler_Store $store
106
-	 */
107
-	public function set_destination_store( Store $store ) {
108
-		$this->destination_store = $store;
109
-	}
110
-
111
-	/**
112
-	 * Get the configured destination logger.
113
-	 *
114
-	 * @return ActionScheduler_Logger
115
-	 */
116
-	public function get_destination_logger() {
117
-		if ( empty( $this->destination_logger ) ) {
118
-			throw new \RuntimeException( __( 'Destination logger must be configured before running a migration', 'action-scheduler' ) );
119
-		}
120
-
121
-		return $this->destination_logger;
122
-	}
123
-
124
-	/**
125
-	 * Set the configured destination logger.
126
-	 *
127
-	 * @param ActionScheduler_Logger $logger
128
-	 */
129
-	public function set_destination_logger( Logger $logger ) {
130
-		$this->destination_logger = $logger;
131
-	}
132
-
133
-	/**
134
-	 * Get flag indicating whether it's a dry run.
135
-	 *
136
-	 * @return bool
137
-	 */
138
-	public function get_dry_run() {
139
-		return $this->dry_run;
140
-	}
141
-
142
-	/**
143
-	 * Set flag indicating whether it's a dry run.
144
-	 *
145
-	 * @param bool $dry_run
146
-	 */
147
-	public function set_dry_run( $dry_run ) {
148
-		$this->dry_run = (bool) $dry_run;
149
-	}
150
-
151
-	/**
152
-	 * Get progress bar object.
153
-	 *
154
-	 * @return ActionScheduler\WPCLI\ProgressBar
155
-	 */
156
-	public function get_progress_bar() {
157
-		return $this->progress_bar;
158
-	}
159
-
160
-	/**
161
-	 * Set progress bar object.
162
-	 *
163
-	 * @param ActionScheduler\WPCLI\ProgressBar $progress_bar
164
-	 */
165
-	public function set_progress_bar( ProgressBar $progress_bar ) {
166
-		$this->progress_bar = $progress_bar;
167
-	}
20
+    /** @var ActionScheduler_Store */
21
+    private $source_store;
22
+
23
+    /** @var ActionScheduler_Logger */
24
+    private $source_logger;
25
+
26
+    /** @var ActionScheduler_Store */
27
+    private $destination_store;
28
+
29
+    /** @var ActionScheduler_Logger */
30
+    private $destination_logger;
31
+
32
+    /** @var Progress bar */
33
+    private $progress_bar;
34
+
35
+    /** @var bool */
36
+    private $dry_run = false;
37
+
38
+    /**
39
+     * Config constructor.
40
+     */
41
+    public function __construct() {
42
+
43
+    }
44
+
45
+    /**
46
+     * Get the configured source store.
47
+     *
48
+     * @return ActionScheduler_Store
49
+     */
50
+    public function get_source_store() {
51
+        if ( empty( $this->source_store ) ) {
52
+            throw new \RuntimeException( __( 'Source store must be configured before running a migration', 'action-scheduler' ) );
53
+        }
54
+
55
+        return $this->source_store;
56
+    }
57
+
58
+    /**
59
+     * Set the configured source store.
60
+     *
61
+     * @param ActionScheduler_Store $store Source store object.
62
+     */
63
+    public function set_source_store( Store $store ) {
64
+        $this->source_store = $store;
65
+    }
66
+
67
+    /**
68
+     * Get the configured source loger.
69
+     *
70
+     * @return ActionScheduler_Logger
71
+     */
72
+    public function get_source_logger() {
73
+        if ( empty( $this->source_logger ) ) {
74
+            throw new \RuntimeException( __( 'Source logger must be configured before running a migration', 'action-scheduler' ) );
75
+        }
76
+
77
+        return $this->source_logger;
78
+    }
79
+
80
+    /**
81
+     * Set the configured source logger.
82
+     *
83
+     * @param ActionScheduler_Logger $logger
84
+     */
85
+    public function set_source_logger( Logger $logger ) {
86
+        $this->source_logger = $logger;
87
+    }
88
+
89
+    /**
90
+     * Get the configured destination store.
91
+     *
92
+     * @return ActionScheduler_Store
93
+     */
94
+    public function get_destination_store() {
95
+        if ( empty( $this->destination_store ) ) {
96
+            throw new \RuntimeException( __( 'Destination store must be configured before running a migration', 'action-scheduler' ) );
97
+        }
98
+
99
+        return $this->destination_store;
100
+    }
101
+
102
+    /**
103
+     * Set the configured destination store.
104
+     *
105
+     * @param ActionScheduler_Store $store
106
+     */
107
+    public function set_destination_store( Store $store ) {
108
+        $this->destination_store = $store;
109
+    }
110
+
111
+    /**
112
+     * Get the configured destination logger.
113
+     *
114
+     * @return ActionScheduler_Logger
115
+     */
116
+    public function get_destination_logger() {
117
+        if ( empty( $this->destination_logger ) ) {
118
+            throw new \RuntimeException( __( 'Destination logger must be configured before running a migration', 'action-scheduler' ) );
119
+        }
120
+
121
+        return $this->destination_logger;
122
+    }
123
+
124
+    /**
125
+     * Set the configured destination logger.
126
+     *
127
+     * @param ActionScheduler_Logger $logger
128
+     */
129
+    public function set_destination_logger( Logger $logger ) {
130
+        $this->destination_logger = $logger;
131
+    }
132
+
133
+    /**
134
+     * Get flag indicating whether it's a dry run.
135
+     *
136
+     * @return bool
137
+     */
138
+    public function get_dry_run() {
139
+        return $this->dry_run;
140
+    }
141
+
142
+    /**
143
+     * Set flag indicating whether it's a dry run.
144
+     *
145
+     * @param bool $dry_run
146
+     */
147
+    public function set_dry_run( $dry_run ) {
148
+        $this->dry_run = (bool) $dry_run;
149
+    }
150
+
151
+    /**
152
+     * Get progress bar object.
153
+     *
154
+     * @return ActionScheduler\WPCLI\ProgressBar
155
+     */
156
+    public function get_progress_bar() {
157
+        return $this->progress_bar;
158
+    }
159
+
160
+    /**
161
+     * Set progress bar object.
162
+     *
163
+     * @param ActionScheduler\WPCLI\ProgressBar $progress_bar
164
+     */
165
+    public function set_progress_bar( ProgressBar $progress_bar ) {
166
+        $this->progress_bar = $progress_bar;
167
+    }
168 168
 }
Please login to merge, or discard this patch.