Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
security_review
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
security_review
Merge requests
!12
Issue
#1244238
: Check that cron has been run recently - in the last 72 hours
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#1244238
: Check that cron has been run recently - in the last 72 hours
issue/security_review-1244238:1244238-check-that-cron
into
2.0.x
Overview
0
Commits
1
Pipelines
0
Changes
2
Merged
Stephen Mustgrave
requested to merge
issue/security_review-1244238:1244238-check-that-cron
into
2.0.x
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
2.0.x
2.0.x (base)
and
latest version
latest version
48837118
1 commit,
2 years ago
2 files
+
94
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/Checks/LastCronRun.php
0 → 100644
+
92
−
0
Options
<?php
namespace
Drupal\security_review\Checks
;
use
Drupal\Core\Link
;
use
Drupal\security_review
\Check
;
use
Drupal\security_review
\CheckResult
;
use
Drupal\user\Entity\Role
;
use
Drupal\user\Entity\User
;
/**
* Checks the last time cron has ran.
*/
class
LastCronRun
extends
Check
{
/**
* {@inheritdoc}
*/
public
function
getNamespace
()
{
return
'Security Review'
;
}
/**
* {@inheritdoc}
*/
public
function
getTitle
()
{
return
'Last cron run'
;
}
/**
* {@inheritdoc}
*/
public
function
getMachineTitle
()
{
return
'last_cron_run'
;
}
/**
* {@inheritdoc}
*/
public
function
run
()
{
$result
=
CheckResult
::
SUCCESS
;
$last_run
=
TRUE
;
$cron_last
=
\Drupal
::
state
()
->
get
(
'system.cron_last'
);
if
(
$cron_last
<=
strtotime
(
'-3 day'
))
{
$result
=
CheckResult
::
FAIL
;
$last_run
=
FALSE
;
}
return
$this
->
createResult
(
$result
,
[
'last_run'
=>
$last_run
]);
}
/**
* {@inheritdoc}
*/
public
function
help
()
{
$paragraphs
=
[];
$paragraphs
[]
=
$this
->
t
(
'A properly configured cron job executes, initiates, or manages a variety of tasks.'
);
return
[
'#theme'
=>
'check_help'
,
'#title'
=>
$this
->
t
(
'Cron has ran in last 3 days.'
),
'#paragraphs'
=>
$paragraphs
,
];
}
/**
* {@inheritdoc}
*/
public
function
evaluatePlain
(
CheckResult
$result
)
{
if
(
$result
->
result
()
!=
CheckResult
::
FAIL
)
{
return
''
;
}
return
$this
->
t
(
'Last cron run'
);
}
/**
* {@inheritdoc}
*/
public
function
getMessage
(
$result_const
)
{
switch
(
$result_const
)
{
case
CheckResult
::
SUCCESS
:
return
$this
->
t
(
'Cron has ran within the last 3 days.'
);
case
CheckResult
::
FAIL
:
return
$this
->
t
(
'Cron has not ran within the last 3 days.'
);
default
:
return
$this
->
t
(
'Unexpected result.'
);
}
}
}
Loading