Constants

STATUS_COMPLETE

STATUS_COMPLETE = 'complete'

STATUS_PENDING

STATUS_PENDING = 'pending'

STATUS_RUNNING

STATUS_RUNNING = 'in-progress'

STATUS_FAILED

STATUS_FAILED = 'failed'

STATUS_CANCELED

STATUS_CANCELED = 'canceled'

DEFAULT_CLASS

DEFAULT_CLASS = 'ActionScheduler_wpPostStore'

DEMARKATION_OPTION

DEMARKATION_OPTION = 'action_scheduler_hybrid_store_demarkation'

Properties

$max_args_length

$max_args_length : int

Maximum length of args.

Type

normal

$store

$store : \ActionScheduler_Store

ActionScheduler_Store instance.

Type

normal

$primary_store

$primary_store : \ActionScheduler_Store

Primary store instance.

Type

normal

$secondary_store

$secondary_store : \ActionScheduler_Store

Secondary store instance.

Type

normal

$migration_runner

$migration_runner : \Action_Scheduler\Migration\Runner

Runner instance.

Type

normal

$demarkation_id

$demarkation_id : int

The dividing line between IDs of actions created by the primary and secondary stores.

Type

normal — Methods that accept an action ID will compare the ID against this to determine which store will contain that ID. In almost all cases, the ID should come from the primary store, but if client code is bypassing the API functions and fetching IDs from elsewhere, then there is a chance that an unmigrated ID might be requested.

Methods

save_action()

save_action(\ActionScheduler_Action  $action, \DateTime|null  $date = null) : int

Save an action to the primary store.

Parameters

\ActionScheduler_Action $action

Action object to be saved.

\DateTime|null $date

Optional. Schedule date. Default null.

Returns

int —

The action ID

fetch_action()

fetch_action(int  $action_id) : \ActionScheduler_Action

Retrieve an existing action whether migrated or not.

Parameters

int $action_id

Action ID.

Returns

\ActionScheduler_Action

find_action()

find_action(string  $hook, array  $params = array()) : string

Find the first matching action from the secondary store.

If it exists, migrate it to the primary store immediately. After it migrates, the secondary store will logically contain the next matching action, so return the result thence.

Parameters

string $hook

Action's hook.

array $params

Action's arguments.

Returns

string

query_actions()

query_actions(array  $query = array(), string  $query_type = 'select') : int[]

Find actions matching the query in the secondary source first.

If any are found, migrate them immediately. Then the secondary store will contain the canonical results.

Parameters

array $query

Query arguments.

string $query_type

Whether to select or count the results. Default, select.

Returns

int[]

query_action()

query_action(array  $query) : int|null

Run query to get a single action ID.

Parameters

array $query

Query parameters.

Returns

int|null

action_counts()

action_counts() : array

Get a count of all actions in the store, grouped by status

Returns

array —

Set of 'status' => int $count pairs for statuses with 1 or more actions of that status.

extra_action_counts()

extra_action_counts() : array

Get additional action counts.

  • add past-due actions

Returns

array

cancel_action()

cancel_action(int  $action_id) : mixed

Cancel an existing action whether migrated or not.

Parameters

int $action_id

Action ID.

Returns

mixed

delete_action()

delete_action(int  $action_id) : mixed

Delete an existing action whether migrated or not.

Parameters

int $action_id

Action ID.

Returns

mixed

get_date()

get_date(int  $action_id) : \DateTime

Get the schedule date an existing action whether migrated or not.

Parameters

int $action_id

Action ID.

Returns

\DateTime —

The date the action is schedule to run, or the date that it ran.

stake_claim()

stake_claim(int  $max_actions = 10, null|\DateTime  $before_date = null, string[]  $hooks = array(), string  $group = '') : \ActionScheduler_ActionClaim

If any actions would have been claimed by the secondary store, migrate them immediately, then ask the primary store for the canonical claim.

Parameters

int $max_actions

Maximum number of actions to claim.

null|\DateTime $before_date

Latest timestamp of actions to claim.

string[] $hooks

Hook of actions to claim.

string $group

Group of actions to claim.

Returns

\ActionScheduler_ActionClaim

get_claim_count()

get_claim_count() : int

Get the claim count from the table data store.

Returns

int

release_claim()

release_claim(\ActionScheduler_ActionClaim  $claim) : mixed

Release a claim in the table data store.

Parameters

\ActionScheduler_ActionClaim $claim

Claim object.

Returns

mixed

unclaim_action()

unclaim_action(int  $action_id) : mixed

Release claims on an action in the table data store.

Parameters

int $action_id

Action ID.

Returns

mixed

mark_failure()

mark_failure(int  $action_id) : mixed

Mark an existing action as failed whether migrated or not.

Parameters

int $action_id

Action ID.

Returns

mixed

log_execution()

log_execution(int  $action_id) : mixed

Log the execution of an existing action whether migrated or not.

Parameters

int $action_id

Action ID.

Returns

mixed

mark_complete()

mark_complete(int  $action_id) : mixed

Mark an existing action complete whether migrated or not.

Parameters

int $action_id

Action ID.

Returns

mixed

get_status()

get_status(int  $action_id) : string

Get an existing action status whether migrated or not.

Parameters

int $action_id

Action ID.

Returns

string

get_claim_id()

get_claim_id(int  $action_id) : mixed

Retrieve the claim ID for an action from the table data store.

Parameters

int $action_id

Action ID.

Returns

mixed

find_actions_by_claim_id()

find_actions_by_claim_id(int  $claim_id) : array

Retrieve a list of action IDs by claim.

Parameters

int $claim_id

Claim ID.

Returns

array

cancel_actions_by_hook()

cancel_actions_by_hook(string  $hook) : void

Cancel pending actions by hook.

Parameters

string $hook

Hook name.

cancel_actions_by_group()

cancel_actions_by_group(string  $group) : void

Cancel pending actions by group.

Parameters

string $group

Group slug.

get_status_labels()

get_status_labels() : array<string,string>

Get status labels.

Returns

array

has_pending_actions_due()

has_pending_actions_due() : string

Check if there are any pending scheduled actions due to run.

Returns

string

init()

init() : mixed

Initialize the table data store tables.

Returns

mixed

mark_migrated()

mark_migrated(int  $action_id) : mixed

Callable function to mark an action as migrated optionally overridden in derived classes.

Parameters

int $action_id

Action ID.

Returns

mixed

instance()

instance() : \ActionScheduler_Store

Get instance.

Returns

\ActionScheduler_Store

mark_failed_fetch_action()

mark_failed_fetch_action(int  $action_id) : mixed

Mark an action that failed to fetch correctly as failed.

Parameters

int $action_id

The ID of the action.

Returns

mixed

__construct()

__construct(\Config|null  $config = null) : mixed

ActionScheduler_HybridStore constructor.

Parameters

\Config|null $config

Migration config object.

Returns

mixed

set_autoincrement()

set_autoincrement(string  $table_name, string  $table_suffix) : void

When the actions table is created, set its autoincrement value to be one higher than the posts table to ensure that there are no ID collisions.

Parameters

string $table_name

Table name.

string $table_suffix

Suffix of table name.

validate_sql_comparator()

validate_sql_comparator(string  $comparison_operator) : string

Validate SQL operator.

Parameters

string $comparison_operator

Operator.

Returns

string

get_scheduled_date_string()

get_scheduled_date_string(\ActionScheduler_Action  $action, null|\DateTime  $scheduled_date = null) : string

Get the time MySQL formatted date/time string for an action's (next) scheduled date.

Parameters

\ActionScheduler_Action $action

Action.

null|\DateTime $scheduled_date

Action's schedule date (optional).

Returns

string

get_scheduled_date_string_local()

get_scheduled_date_string_local(\ActionScheduler_Action|null  $action, null|\DateTime  $scheduled_date = null) : string

Get the time MySQL formatted date/time string for an action's (next) scheduled date.

Parameters

\ActionScheduler_Action|null $action

Action.

null|\DateTime $scheduled_date

Action's scheduled date (optional).

Returns

string

validate_args()

validate_args(mixed  $args, int  $action_id) : mixed

Validate that we could decode action arguments.

Parameters

mixed $args

The decoded arguments.

int $action_id

The action ID.

Throws

\ActionScheduler_InvalidActionException

When the decoded arguments are invalid.

Returns

mixed

validate_schedule()

validate_schedule(mixed  $schedule, int  $action_id) : mixed

Validate a ActionScheduler_Schedule object.

Parameters

mixed $schedule

The unserialized ActionScheduler_Schedule object.

int $action_id

The action ID.

Throws

\ActionScheduler_InvalidActionException

When the schedule is invalid.

Returns

mixed

validate_action()

validate_action(\ActionScheduler_Action  $action) : mixed

InnoDB indexes have a maximum size of 767 bytes by default, which is only 191 characters with utf8mb4.

Previously, AS wasn't concerned about args length, as we used the (unindex) post_content column. However, with custom tables, we use an indexed VARCHAR column instead.

Parameters

\ActionScheduler_Action $action

Action to be validated.

Throws

\InvalidArgumentException

When json encoded args is too long.

Returns

mixed

hook()

hook() : mixed

Add base hooks

Returns

mixed

unhook()

unhook() : mixed

Remove base hooks

Returns

mixed

get_local_timezone()

get_local_timezone() : \DateTimeZone

Get the site's local time.

Returns

\DateTimeZone

get_store_from_action_id()

get_store_from_action_id(int  $action_id, bool  $primary_first = false) : \ActionScheduler_Store

Return which store an action is stored in.

Parameters

int $action_id

ID of the action.

bool $primary_first

Optional flag indicating search the primary store first.

Returns

\ActionScheduler_Store

bulk_cancel_actions()

bulk_cancel_actions(int[]  $action_ids) : void

Cancel a set of action IDs.

Parameters

int[] $action_ids

List of action IDs.

set_demarkation_id()

set_demarkation_id(int  $id = null) : int

Store the demarkation id in WP options.

Parameters

int $id

The ID to set as the demarkation point between the two stores Leave null to use the next ID from the WP posts table.

Returns

int —

The new ID.

migrate()

migrate(array  $action_ids) : mixed

Migrate a list of actions to the table data store.

Parameters

array $action_ids

List of action IDs.

Returns

mixed