Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
0846b231
Commit
0846b231
authored
Aug 22, 2017
by
catch
Browse files
Issue
#2903183
by amateescu, jkovell, dawehner: Don't run cron after updating cron settings
parent
64ffc1ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/modules/system/src/Form/CronForm.php
View file @
0846b231
...
...
@@ -16,6 +16,7 @@
* Configure cron settings for this site.
*/
class
CronForm
extends
FormBase
{
use
ConfigFormBaseTrait
;
/**
...
...
@@ -104,6 +105,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form
[
'run'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Run cron'
),
'#submit'
=>
[
'::runCron'
],
];
$status
=
'<p>'
.
$this
->
t
(
'Last run: %time ago.'
,
[
'%time'
=>
$this
->
dateFormatter
->
formatTimeDiffSince
(
$this
->
state
->
get
(
'system.cron_last'
))])
.
'</p>'
;
$form
[
'status'
]
=
[
...
...
@@ -145,22 +147,25 @@ public function buildForm(array $form, FormStateInterface $form_state) {
}
/**
*
Runs cron and reloads the page.
*
{@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$this
->
config
(
'system.cron'
)
->
set
(
'logging'
,
$form_state
->
getValue
(
'logging'
))
->
save
();
drupal_set_message
(
t
(
'The configuration options have been saved.'
));
}
// Run cron manually from Cron form.
/**
* Form submission handler for running cron manually.
*/
public
function
runCron
(
array
&
$form
,
FormStateInterface
$form_state
)
{
if
(
$this
->
cron
->
run
())
{
drupal_set_message
(
t
(
'Cron ran successfully.'
));
drupal_set_message
(
$this
->
t
(
'Cron ran successfully.'
));
}
else
{
drupal_set_message
(
t
(
'Cron run failed.'
),
'error'
);
drupal_set_message
(
$this
->
t
(
'Cron run failed.'
),
'error'
);
}
}
}
core/modules/system/src/Tests/System/CronRunTest.php
View file @
0846b231
...
...
@@ -105,9 +105,19 @@ public function testCronUI() {
// the time will start at 1 January 1970.
$this
->
assertNoText
(
'years'
);
$this
->
drupalPostForm
(
NULL
,
[],
t
(
'Save configuration'
));
$this
->
assertText
(
t
(
'The configuration options have been saved.'
));
$cron_last
=
time
()
-
200
;
\
Drupal
::
state
()
->
set
(
'system.cron_last'
,
$cron_last
);
$this
->
drupalPostForm
(
NULL
,
[],
'Save configuration'
);
$this
->
assertText
(
'The configuration options have been saved.'
);
$this
->
assertUrl
(
'admin/config/system/cron'
);
// Check that cron does not run when saving the configuration form.
$this
->
assertEqual
(
$cron_last
,
\
Drupal
::
state
()
->
get
(
'system.cron_last'
),
'Cron does not run when saving the configuration form.'
);
// Check that cron runs when triggered manually.
$this
->
drupalPostForm
(
NULL
,
[],
'Run cron'
);
$this
->
assertTrue
(
$cron_last
<
\
Drupal
::
state
()
->
get
(
'system.cron_last'
),
'Cron runs when triggered manually.'
);
}
/**
...
...
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