Commit f06aaddd authored by gbyte.co's avatar gbyte.co

Replace deprecated REQUEST_TIME with getRequestTime() of datetime.time service

parent fe9c81e1
......@@ -152,8 +152,9 @@ function simple_sitemap_cron() {
$generator = \Drupal::service('simple_sitemap.generator');
if ($generator->getSetting('cron_generate')) {
$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);
$requestTime = \Drupal::service('datetime.time')->getRequestTime();
if ($interval === 0 || ((\Drupal::state()->get('simple_sitemap.last_cron_generate', 0) + $interval) <= $requestTime)) {
\Drupal::state()->set('simple_sitemap.last_cron_generate', $requestTime);
$generator->generateSitemap('backend');
}
}
......
......@@ -10,6 +10,7 @@ services:
- '@entity_type.manager'
- '@path.validator'
- '@date.formatter'
- '@datetime.time'
simple_sitemap.sitemap_generator:
class: Drupal\simple_sitemap\SitemapGenerator
......@@ -20,6 +21,7 @@ services:
- '@database'
- '@module_handler'
- '@language_manager'
- '@datetime.time'
simple_sitemap.entity_helper:
class: Drupal\simple_sitemap\EntityHelper
......
......@@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Path\PathValidator;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\Component\Datetime\Time;
/**
* Class Simplesitemap
......@@ -49,6 +50,11 @@ class Simplesitemap {
*/
protected $dateFormatter;
/**
* @var \Drupal\Component\Datetime\Time
*/
protected $time;
/**
* @var array
*/
......@@ -73,6 +79,7 @@ class Simplesitemap {
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* @param \Drupal\Core\Path\PathValidator $pathValidator
* @param \Drupal\Core\Datetime\DateFormatter $dateFormatter
* @param \Drupal\Component\Datetime\Time $time
*/
public function __construct(
SitemapGenerator $sitemapGenerator,
......@@ -81,7 +88,8 @@ class Simplesitemap {
Connection $database,
EntityTypeManagerInterface $entityTypeManager,
PathValidator $pathValidator,
DateFormatter $dateFormatter
DateFormatter $dateFormatter,
Time $time
) {
$this->sitemapGenerator = $sitemapGenerator;
$this->entityHelper = $entityHelper;
......@@ -90,6 +98,7 @@ class Simplesitemap {
$this->entityTypeManager = $entityTypeManager;
$this->pathValidator = $pathValidator;
$this->dateFormatter = $dateFormatter;
$this->time = $time;
}
/**
......@@ -229,7 +238,7 @@ class Simplesitemap {
$chunks = $this->fetchSitemapChunkInfo();
if (isset($chunks[SitemapGenerator::FIRST_CHUNK_INDEX]->sitemap_created)) {
return $this->dateFormatter
->formatInterval(REQUEST_TIME - $chunks[SitemapGenerator::FIRST_CHUNK_INDEX]
->formatInterval($this->time->getRequestTime() - $chunks[SitemapGenerator::FIRST_CHUNK_INDEX]
->sitemap_created);
}
return FALSE;
......
......@@ -7,6 +7,7 @@ use Drupal\simple_sitemap\Batch\Batch;
use Drupal\Core\Database\Connection;
use Drupal\Core\Extension\ModuleHandler;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Component\Datetime\Time;
/**
* Class SitemapGenerator
......@@ -62,6 +63,11 @@ class SitemapGenerator {
*/
protected $generator;
/**
* @var \Drupal\Component\Datetime\Time
*/
protected $time;
/**
* @var array
*/
......@@ -85,19 +91,22 @@ class SitemapGenerator {
* @param \Drupal\Core\Database\Connection $database
* @param \Drupal\Core\Extension\ModuleHandler $module_handler
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* @param \Drupal\Component\Datetime\Time $time
*/
public function __construct(
Batch $batch,
EntityHelper $entityHelper,
Connection $database,
ModuleHandler $module_handler,
LanguageManagerInterface $language_manager
LanguageManagerInterface $language_manager,
Time $time
) {
$this->batch = $batch;
$this->entityHelper = $entityHelper;
$this->db = $database;
$this->moduleHandler = $module_handler;
$this->languageManager = $language_manager;
$this->time = $time;
$this->setIsHreflangSitemap();
}
......@@ -226,7 +235,7 @@ class SitemapGenerator {
: $this->db->query('SELECT MAX(id) FROM {simple_sitemap}')
->fetchField() + 1,
'sitemap_string' => $this->generateSitemapChunk($links),
'sitemap_created' => REQUEST_TIME,
'sitemap_created' => $this->time->getRequestTime(),
];
if ($remove_sitemap) {
$this->db->truncate('simple_sitemap')->execute();
......
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