Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
Cron-Control
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
WP Plugins
Cron-Control
Commits
19283be4
Commit
19283be4
authored
Sep 22, 2017
by
Erick Hitter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix internal consistency in what we call these things
parent
12c12329
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
30 deletions
+30
-30
includes/class-internal-events.php
includes/class-internal-events.php
+30
-30
No files found.
includes/class-internal-events.php
View file @
19283be4
...
...
@@ -20,7 +20,7 @@ class Internal_Events extends Singleton {
*
* @var array
*/
private
$internal_
job
s
=
array
();
private
$internal_
event
s
=
array
();
/**
* Schedules for internal events
...
...
@@ -29,7 +29,7 @@ class Internal_Events extends Singleton {
*
* @var array
*/
private
$internal_
job
s_schedules
=
array
();
private
$internal_
event
s_schedules
=
array
();
/**
* Register hooks
...
...
@@ -44,8 +44,8 @@ class Internal_Events extends Singleton {
add_action
(
'rest_api_init'
,
array
(
$this
,
'schedule_internal_events'
)
);
add_filter
(
'cron_schedules'
,
array
(
$this
,
'register_internal_events_schedules'
)
);
foreach
(
$this
->
internal_
jobs
as
$internal_job
)
{
add_action
(
$internal_
job
[
'action'
],
$internal_job
[
'callback'
]
);
foreach
(
$this
->
internal_
events
as
$internal_event
)
{
add_action
(
$internal_
event
[
'action'
],
$internal_event
[
'callback'
]
);
}
}
...
...
@@ -53,7 +53,7 @@ class Internal_Events extends Singleton {
* Populate internal events, allowing for additions
*/
private
function
prepare_internal_events
()
{
$internal_
job
s
=
array
(
$internal_
event
s
=
array
(
array
(
'schedule'
=>
'a8c_cron_control_minute'
,
'action'
=>
'a8c_cron_control_force_publish_missed_schedules'
,
...
...
@@ -78,7 +78,7 @@ class Internal_Events extends Singleton {
// Allow additional internal events to be specified, ensuring the above cannot be overwritten.
if
(
defined
(
'CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS'
)
&&
is_array
(
\
CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS
)
)
{
$internal_actions
=
wp_list_pluck
(
$internal_
job
s
,
'action'
);
$internal_actions
=
wp_list_pluck
(
$internal_
event
s
,
'action'
);
foreach
(
\
CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS
as
$additional
)
{
if
(
in_array
(
$additional
[
'action'
],
$internal_actions
,
true
)
)
{
...
...
@@ -89,18 +89,18 @@ class Internal_Events extends Singleton {
continue
;
}
$internal_
job
s
[]
=
$additional
;
$internal_
event
s
[]
=
$additional
;
}
}
$this
->
internal_
jobs
=
$internal_job
s
;
$this
->
internal_
events
=
$internal_event
s
;
}
/**
* Allow custom internal events to provide their own schedules
*/
private
function
prepare_internal_events_schedules
()
{
$internal_
job
s_schedules
=
array
(
$internal_
event
s_schedules
=
array
(
'a8c_cron_control_minute'
=>
array
(
'interval'
=>
1
*
MINUTE_IN_SECONDS
,
'display'
=>
__
(
'Cron Control internal job - every minute'
,
'automattic-cron-control'
),
...
...
@@ -114,7 +114,7 @@ class Internal_Events extends Singleton {
// Allow additional schedules for custom events, ensuring the above cannot be overwritten.
if
(
defined
(
'CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS_SCHEDULES'
)
&&
is_array
(
\
CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS_SCHEDULES
)
)
{
foreach
(
\
CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS_SCHEDULES
as
$name
=>
$attrs
)
{
if
(
array_key_exists
(
$name
,
$internal_
job
s_schedules
)
)
{
if
(
array_key_exists
(
$name
,
$internal_
event
s_schedules
)
)
{
continue
;
}
...
...
@@ -122,42 +122,42 @@ class Internal_Events extends Singleton {
continue
;
}
$internal_
job
s_schedules
[
$name
]
=
$attrs
;
$internal_
event
s_schedules
[
$name
]
=
$attrs
;
}
}
$this
->
internal_
jobs_schedules
=
$internal_job
s_schedules
;
$this
->
internal_
events_schedules
=
$internal_event
s_schedules
;
}
/**
* Include custom schedules used for internal
job
s
* Include custom schedules used for internal
event
s
*
* @param array $schedules List of registered event intervals.
* @return array
*/
public
function
register_internal_events_schedules
(
$schedules
)
{
return
array_merge
(
$schedules
,
$this
->
internal_
job
s_schedules
);
return
array_merge
(
$schedules
,
$this
->
internal_
event
s_schedules
);
}
/**
* Schedule internal
job
s
* Schedule internal
event
s
*/
public
function
schedule_internal_events
()
{
$when
=
strtotime
(
sprintf
(
'+%d seconds'
,
JOB_QUEUE_WINDOW_IN_SECONDS
)
);
$schedules
=
wp_get_schedules
();
foreach
(
$this
->
internal_
jobs
as
$job
_args
)
{
if
(
!
wp_next_scheduled
(
$
job
_args
[
'action'
]
)
)
{
$interval
=
array_key_exists
(
$
job_args
[
'schedule'
],
$schedules
)
?
$schedules
[
$job
_args
[
'schedule'
]
][
'interval'
]
:
0
;
foreach
(
$this
->
internal_
events
as
$event
_args
)
{
if
(
!
wp_next_scheduled
(
$
event
_args
[
'action'
]
)
)
{
$interval
=
array_key_exists
(
$
event_args
[
'schedule'
],
$schedules
)
?
$schedules
[
$event
_args
[
'schedule'
]
][
'interval'
]
:
0
;
$args
=
array
(
'schedule'
=>
$
job
_args
[
'schedule'
],
'schedule'
=>
$
event
_args
[
'schedule'
],
'args'
=>
array
(),
'interval'
=>
$interval
,
);
schedule_event
(
$when
,
$
job
_args
[
'action'
],
$args
);
schedule_event
(
$when
,
$
event
_args
[
'action'
],
$args
);
}
}
}
...
...
@@ -173,7 +173,7 @@ class Internal_Events extends Singleton {
* @return bool
*/
public
function
is_internal_event
(
$action
)
{
return
in_array
(
$action
,
wp_list_pluck
(
$this
->
internal_
job
s
,
'action'
),
true
);
return
in_array
(
$action
,
wp_list_pluck
(
$this
->
internal_
event
s
,
'action'
),
true
);
}
/**
...
...
@@ -256,32 +256,32 @@ class Internal_Events extends Singleton {
// Confirm internal events are scheduled for when they're expected.
$schedules
=
wp_get_schedules
();
foreach
(
$this
->
internal_
jobs
as
$internal_job
)
{
$timestamp
=
wp_next_scheduled
(
$internal_
job
[
'action'
]
);
foreach
(
$this
->
internal_
events
as
$internal_event
)
{
$timestamp
=
wp_next_scheduled
(
$internal_
event
[
'action'
]
);
// Will reschedule on its own.
if
(
false
===
$timestamp
)
{
continue
;
}
$
job
_details
=
get_event_by_attributes
(
array
(
$
event
_details
=
get_event_by_attributes
(
array
(
'timestamp'
=>
$timestamp
,
'action'
=>
$internal_
job
[
'action'
],
'action'
=>
$internal_
event
[
'action'
],
'instance'
=>
md5
(
maybe_serialize
(
array
()
)
),
)
);
if
(
$
job_details
->
schedule
!==
$internal_job
[
'schedule'
]
)
{
if
(
$
event_details
->
schedule
!==
$internal_event
[
'schedule'
]
)
{
if
(
$timestamp
<=
time
()
)
{
$timestamp
=
time
()
+
(
1
*
\
MINUTE_IN_SECONDS
);
}
$args
=
array
(
'schedule'
=>
$internal_
job
[
'schedule'
],
'args'
=>
$
job
_details
->
args
,
'interval'
=>
$schedules
[
$internal_
job
[
'schedule'
]
][
'interval'
],
'schedule'
=>
$internal_
event
[
'schedule'
],
'args'
=>
$
event
_details
->
args
,
'interval'
=>
$schedules
[
$internal_
event
[
'schedule'
]
][
'interval'
],
);
schedule_event
(
$timestamp
,
$
job_details
->
action
,
$args
,
$job
_details
->
ID
);
schedule_event
(
$timestamp
,
$
event_details
->
action
,
$args
,
$event
_details
->
ID
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment