Commit 60836c5a authored by FeyP's avatar FeyP Committed by gbyte.co

Issue #2889575 by FeyP: Provide cron regeneration interval setting

parent 507ba278
max_links: 2000
cron_generate: true
cron_generate_interval: 0
remove_duplicates: true
skip_untranslated: false
batch_process_limit: 1500
......
......@@ -7,6 +7,9 @@ simple_sitemap.settings:
cron_generate:
label: 'Cron generate'
type: boolean
cron_generate_interval:
label: 'Cron generate interval'
type: integer
remove_duplicates:
label: 'Remove duplicates'
type: boolean
......
......@@ -150,7 +150,11 @@ function simple_sitemap_cron() {
*/
$generator = \Drupal::service('simple_sitemap.generator');
if ($generator->getSetting('cron_generate')) {
$generator->generateSitemap('backend');
$interval = (int) $generator->getSetting('cron_generate_interval', 0) * 60 * 60;
if ($interval === 0 || ((\Drupal::state()->get('simple_sitemap.last_cron_generate', 0) + $interval) <= REQUEST_TIME)) {
\Drupal::state()->set('simple_sitemap.last_cron_generate', REQUEST_TIME);
$generator->generateSitemap('backend');
}
}
}
......
......@@ -17,6 +17,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
protected $formSettings = [
'max_links',
'cron_generate',
'cron_generate_interval',
'remove_duplicates',
'skip_untranslated',
'batch_process_limit',
......@@ -58,11 +59,37 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$form['simple_sitemap_settings']['settings']['cron_generate'] = [
'#type' => 'checkbox',
'#title' => $this->t('Regenerate the sitemap on every cron run'),
'#title' => $this->t('Regenerate the sitemap during cron runs'),
'#description' => $this->t('Uncheck this if you intend to only regenerate the sitemap manually or via drush.'),
'#default_value' => $this->generator->getSetting('cron_generate', TRUE),
];
$form['simple_sitemap_settings']['settings']['cron_generate_interval'] = [
'#type' => 'select',
'#title' => $this->t('Sitemap generation interval'),
'#description' => $this->t('The sitemap will be generated according to this interval.'),
'#default_value' => $this->generator->getSetting('cron_generate_interval', 0),
'#options' => [
0 => $this->t('On every cron run'),
1 => $this->t('Once an hour'),
3 => $this->t('Once every @hours hours', ['@hours' => 3]),
6 => $this->t('Once every @hours hours', ['@hours' => 6]),
12 => $this->t('Once every @hours hours', ['@hours' => 12]),
24 => $this->t('Once a day'),
48 => $this->t('Once every @days days', ['@days' => 48/24]),
72 => $this->t('Once every @days days', ['@days' => 72/24]),
96 => $this->t('Once every @days days', ['@days' => 96/24]),
120 => $this->t('Once every @days days', ['@days' => 120/24]),
144 => $this->t('Once every @days days', ['@days' => 144/24]),
168 => $this->t('Once a week'),
],
'#states' => [
'visible' => [
':input[name="cron_generate"]' => ['checked' => TRUE],
],
],
];
$form['simple_sitemap_settings']['advanced'] = [
'#type' => 'details',
'#title' => $this->t('Advanced settings'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment