Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Bulk Actions Cron Offload
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
WP Plugins
Bulk Actions Cron Offload
Commits
70fe999e
Commit
70fe999e
authored
7 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Abstract next_scheduled function
parent
a5dac90b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/class-delete-all.php
+4
-45
4 additions, 45 deletions
includes/class-delete-all.php
includes/class-main.php
+42
-0
42 additions, 0 deletions
includes/class-main.php
with
46 additions
and
45 deletions
includes/class-delete-all.php
+
4
−
45
View file @
70fe999e
...
@@ -43,7 +43,7 @@ class Delete_All {
...
@@ -43,7 +43,7 @@ class Delete_All {
// Special keys are used to trigger this request, and we need to remove them on redirect.
// Special keys are used to trigger this request, and we need to remove them on redirect.
$extra_keys
=
array
(
self
::
ACTION
,
self
::
ACTION
.
'2'
);
$extra_keys
=
array
(
self
::
ACTION
,
self
::
ACTION
.
'2'
);
$action_scheduled
=
self
::
action_next_scheduled
(
$vars
->
post_type
);
$action_scheduled
=
Main
::
get_
action_next_scheduled
(
self
::
ACTION
,
$vars
->
post_type
);
if
(
empty
(
$action_scheduled
)
)
{
if
(
empty
(
$action_scheduled
)
)
{
Main
::
schedule_processing
(
$vars
);
Main
::
schedule_processing
(
$vars
);
...
@@ -126,7 +126,7 @@ class Delete_All {
...
@@ -126,7 +126,7 @@ class Delete_All {
$message
=
__
(
'A request to empty the trash is already pending for this post type.'
,
'bulk-edit-cron-offload'
);
$message
=
__
(
'A request to empty the trash is already pending for this post type.'
,
'bulk-edit-cron-offload'
);
}
}
}
elseif
(
'edit'
===
$screen
->
base
&&
isset
(
$_REQUEST
[
'post_status'
]
)
&&
'trash'
===
$_REQUEST
[
'post_status'
]
)
{
}
elseif
(
'edit'
===
$screen
->
base
&&
isset
(
$_REQUEST
[
'post_status'
]
)
&&
'trash'
===
$_REQUEST
[
'post_status'
]
)
{
if
(
self
::
action_next_scheduled
(
$screen
->
post_type
)
)
{
if
(
Main
::
get_
action_next_scheduled
(
self
::
ACTION
,
$screen
->
post_type
)
)
{
$type
=
'warning'
;
$type
=
'warning'
;
$message
=
__
(
'A pending request to empty the trash will be processed soon.'
,
'bulk-edit-cron-offload'
);
$message
=
__
(
'A pending request to empty the trash will be processed soon.'
,
'bulk-edit-cron-offload'
);
}
}
...
@@ -155,7 +155,7 @@ class Delete_All {
...
@@ -155,7 +155,7 @@ class Delete_All {
return
$where
;
return
$where
;
}
}
if
(
self
::
action_next_scheduled
(
$q
->
get
(
'post_type'
)
)
)
{
if
(
Main
::
get_
action_next_scheduled
(
self
::
ACTION
,
$q
->
get
(
'post_type'
)
)
)
{
$where
.
=
' AND 0=1'
;
$where
.
=
' AND 0=1'
;
}
}
...
@@ -189,7 +189,7 @@ class Delete_All {
...
@@ -189,7 +189,7 @@ class Delete_All {
}
}
// There isn't a pending purge, so one should be permitted.
// There isn't a pending purge, so one should be permitted.
if
(
!
self
::
action_next_scheduled
(
$screen
->
post_type
)
)
{
if
(
!
Main
::
get_
action_next_scheduled
(
self
::
ACTION
,
$screen
->
post_type
)
)
{
return
$caps
;
return
$caps
;
}
}
...
@@ -198,47 +198,6 @@ class Delete_All {
...
@@ -198,47 +198,6 @@ class Delete_All {
return
$caps
;
return
$caps
;
}
}
/**
* Find the next scheduled instance of a given action, regardless of arguments
*
* @param string $post_type Post type hook is scheduled for.
* @return array
*/
private
static
function
action_next_scheduled
(
$post_type
)
{
$events
=
get_option
(
'cron'
);
if
(
!
is_array
(
$events
)
)
{
return
array
();
}
foreach
(
$events
as
$timestamp
=>
$timestamp_events
)
{
// Skip non-event data that Core includes in the option.
if
(
!
is_numeric
(
$timestamp
)
)
{
continue
;
}
foreach
(
$timestamp_events
as
$action
=>
$action_instances
)
{
if
(
Main
::
CRON_EVENT
!==
$action
)
{
continue
;
}
foreach
(
$action_instances
as
$instance
=>
$instance_args
)
{
$vars
=
array_shift
(
$instance_args
[
'args'
]
);
if
(
self
::
ACTION
===
$vars
->
action
&&
$post_type
===
$vars
->
post_type
)
{
return
array
(
'timestamp'
=>
$timestamp
,
'args'
=>
$vars
,
);
}
}
}
}
// No matching event found.
return
array
();
}
}
}
Delete_All
::
register_hooks
();
Delete_All
::
register_hooks
();
This diff is collapsed.
Click to expand it.
includes/class-main.php
+
42
−
0
View file @
70fe999e
...
@@ -254,6 +254,48 @@ class Main {
...
@@ -254,6 +254,48 @@ class Main {
<?php
<?php
}
}
/**
* Find the next scheduled instance of a given action, regardless of arguments
*
* @param string $bulk_action Bulk action to filter by.
* @param string $post_type Post type hook is scheduled for.
* @return array
*/
public
static
function
get_action_next_scheduled
(
$bulk_action
,
$post_type
)
{
$events
=
get_option
(
'cron'
);
if
(
!
is_array
(
$events
)
)
{
return
array
();
}
foreach
(
$events
as
$timestamp
=>
$timestamp_events
)
{
// Skip non-event data that Core includes in the option.
if
(
!
is_numeric
(
$timestamp
)
)
{
continue
;
}
foreach
(
$timestamp_events
as
$action
=>
$action_instances
)
{
if
(
self
::
CRON_EVENT
!==
$action
)
{
continue
;
}
foreach
(
$action_instances
as
$instance
=>
$instance_args
)
{
$vars
=
array_shift
(
$instance_args
[
'args'
]
);
if
(
$bulk_action
===
$vars
->
action
&&
$post_type
===
$vars
->
post_type
)
{
return
array
(
'timestamp'
=>
$timestamp
,
'args'
=>
$vars
,
);
}
}
}
}
// No matching event found.
return
array
();
}
/**
/**
* Gather pending events for given conditions
* Gather pending events for given conditions
*
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment