class SitemapSubmitter in Simple XML sitemap 4.x
Same name and namespace in other branches
- 8.3 modules/simple_sitemap_engines/src/Plugin/QueueWorker/SitemapSubmitter.php \Drupal\simple_sitemap_engines\Plugin\QueueWorker\SitemapSubmitter
Process a queue of search engines to submit sitemaps.
Plugin annotation
@QueueWorker(
id = "simple_sitemap_engine_submit",
title = @Translation("Sitemap search engine submission"),
cron = {"time" = 30}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
- class \Drupal\simple_sitemap_engines\Plugin\QueueWorker\SitemapSubmitter implements ContainerFactoryPluginInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
Expanded class hierarchy of SitemapSubmitter
See also
File
- modules/
simple_sitemap_engines/ src/ Plugin/ QueueWorker/ SitemapSubmitter.php, line 28
Namespace
Drupal\simple_sitemap_engines\Plugin\QueueWorkerView source
class SitemapSubmitter extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* The HTTP Client service.
*
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* The sitemap generator service.
*
* @var \Drupal\simple_sitemap\Manager\Generator
*/
protected $generator;
/**
* The Drupal logger service.
*
* @var \Drupal\simple_sitemap\Logger
*/
protected $logger;
/**
* The Drupal state service.
*
* @var \Drupal\workflows\StateInterface
*/
protected $state;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* SitemapSubmitter constructor.
*
* @param array $configuration
* The config.
* @param string $plugin_id
* The plugin id.
* @param array $plugin_definition
* The plugin definition.
* @param \GuzzleHttp\ClientInterface $http_client
* The client used to submit to engines.
* @param \Drupal\simple_sitemap\Manager\Generator $generator
* The generator service.
* @param \Drupal\simple_sitemap\Logger $logger
* Standard logger.
* @param \Drupal\Core\State\StateInterface $state
* Drupal state service for last submitted.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, ClientInterface $http_client, Generator $generator, Logger $logger, StateInterface $state, TimeInterface $time) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->httpClient = $http_client;
$this->generator = $generator;
$this->logger = $logger;
$this->state = $state;
$this->time = $time;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('http_client'), $container
->get('simple_sitemap.generator'), $container
->get('simple_sitemap.logger'), $container
->get('state'), $container
->get('datetime.time'));
}
/**
* {@inheritdoc}
*/
public function processItem($engine_id) {
if ($engine = SimpleSitemapEngine::load($engine_id)) {
// Submit all variants that are enabled for this search engine.
foreach (SimpleSitemap::loadMultiple($engine->sitemap_variants) as $sitemap_id => $sitemap) {
if ($sitemap
->status()) {
$submit_url = str_replace('[sitemap]', $sitemap
->toUrl()
->toString(), $engine->url);
try {
$this->httpClient
->request('GET', $submit_url);
// Log if submission was successful.
$this->logger
->m('Sitemap @variant submitted to @url', [
'@variant' => $sitemap_id,
'@url' => $submit_url,
])
->log();
// Record last submission time. This is purely informational; the
// variable that determines when the next submission should be run is
// stored in the global state.
$this->state
->set("simple_sitemap_engines.simple_sitemap_engine.{$engine_id}.last_submitted", $this->time
->getRequestTime());
} catch (RequestException $e) {
// Catch and log exceptions so this submission gets removed from the
// queue whether or not it succeeded.
// If the error was caused by network failure, it's fine to just wait
// until next time the submission is queued to try again.
// If the error was caused by a malformed URL, keeping the submission
// in the queue to retry is pointless since it will always fail.
watchdog_exception('simple_sitemap', $e);
}
}
}
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
SitemapSubmitter:: |
protected | property | The sitemap generator service. | |
SitemapSubmitter:: |
protected | property | The HTTP Client service. | |
SitemapSubmitter:: |
protected | property | The Drupal logger service. | |
SitemapSubmitter:: |
protected | property | The Drupal state service. | |
SitemapSubmitter:: |
protected | property | The time service. | |
SitemapSubmitter:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
SitemapSubmitter:: |
public | function |
Works on a single queue item. Overrides QueueWorkerInterface:: |
|
SitemapSubmitter:: |
public | function |
SitemapSubmitter constructor. Overrides PluginBase:: |