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

Fix plugin interfaces

parent 9b81940e
...@@ -39,11 +39,11 @@ services: ...@@ -39,11 +39,11 @@ services:
- '@simple_sitemap.manager' - '@simple_sitemap.manager'
- '@state' - '@state'
- '@module_handler' - '@module_handler'
- '@simple_sitemap.element_queue' - '@simple_sitemap.queue'
- '@lock' - '@lock'
simple_sitemap.element_queue: simple_sitemap.queue:
class: Drupal\simple_sitemap\Queue\ElementQueue class: Drupal\simple_sitemap\Queue\SimplesitemapQueue
public: false public: false
arguments: arguments:
- 'simple_sitemap_elements' - 'simple_sitemap_elements'
......
...@@ -8,10 +8,17 @@ namespace Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator; ...@@ -8,10 +8,17 @@ namespace Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator;
*/ */
interface SitemapGeneratorInterface { interface SitemapGeneratorInterface {
public function generate(array $links); function setSitemapVariant($sitemap_variant);
public function generateIndex(); function setSettings(array $settings);
public function remove(); function generate(array $links);
function generateIndex();
function publish();
function remove();
function invalidateCache();
} }
...@@ -8,7 +8,11 @@ namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator; ...@@ -8,7 +8,11 @@ namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
*/ */
interface UrlGeneratorInterface { interface UrlGeneratorInterface {
public function generate($data_sets); function setSettings(array $settings);
public function getDataSets(); function setSitemapVariant($sitemap_variant);
function getDataSets();
function generate($data_set);
} }
...@@ -42,9 +42,9 @@ class QueueWorker { ...@@ -42,9 +42,9 @@ class QueueWorker {
protected $lock; protected $lock;
/** /**
* @var array|\Drupal\simple_sitemap\Queue\ElementQueue * @var \Drupal\simple_sitemap\Queue\SimplesitemapQueue
*/ */
protected $elementQueue = []; protected $queue;
/** /**
* @var string|null * @var string|null
...@@ -87,20 +87,20 @@ class QueueWorker { ...@@ -87,20 +87,20 @@ class QueueWorker {
* @param \Drupal\simple_sitemap\SimplesitemapManager $manager * @param \Drupal\simple_sitemap\SimplesitemapManager $manager
* @param \Drupal\Core\State\State $state * @param \Drupal\Core\State\State $state
* @param \Drupal\Core\Extension\ModuleHandler $module_handler * @param \Drupal\Core\Extension\ModuleHandler $module_handler
* @param \Drupal\simple_sitemap\Queue\ElementQueue $element_queue * @param \Drupal\simple_sitemap\Queue\SimplesitemapQueue $element_queue
* @param \Drupal\Core\Lock\LockBackendInterface $lock * @param \Drupal\Core\Lock\LockBackendInterface $lock
*/ */
public function __construct(SimplesitemapSettings $settings, public function __construct(SimplesitemapSettings $settings,
SimplesitemapManager $manager, SimplesitemapManager $manager,
State $state, State $state,
ModuleHandler $module_handler, ModuleHandler $module_handler,
ElementQueue $element_queue, SimplesitemapQueue $element_queue,
LockBackendInterface $lock) { LockBackendInterface $lock) {
$this->settings = $settings; $this->settings = $settings;
$this->manager = $manager; $this->manager = $manager;
$this->state = $state; $this->state = $state;
$this->moduleHandler = $module_handler; $this->moduleHandler = $module_handler;
$this->elementQueue = $element_queue; $this->queue = $element_queue;
$this->lock = $lock; $this->lock = $lock;
} }
...@@ -110,7 +110,7 @@ class QueueWorker { ...@@ -110,7 +110,7 @@ class QueueWorker {
* @todo Should remove all unpublished variants from db. * @todo Should remove all unpublished variants from db.
*/ */
public function deleteQueue() { public function deleteQueue() {
$this->elementQueue->deleteQueue(); $this->queue->deleteQueue();
$this->variantProcessedNow = NULL; $this->variantProcessedNow = NULL;
$this->generatorProcessedNow = NULL; $this->generatorProcessedNow = NULL;
$this->results = []; $this->results = [];
...@@ -122,8 +122,8 @@ class QueueWorker { ...@@ -122,8 +122,8 @@ class QueueWorker {
return $this; return $this;
} }
public function getElementQueue() { public function getQueue() {
return $this->elementQueue; return $this->queue;
} }
/** /**
...@@ -184,7 +184,7 @@ class QueueWorker { ...@@ -184,7 +184,7 @@ class QueueWorker {
} }
protected function queueElements($elements) { protected function queueElements($elements) {
$this->elementQueue->createItems($elements); $this->queue->createItems($elements);
$this->state->set('simple_sitemap.queue_items_initial_amount', ($this->state->get('simple_sitemap.queue_items_initial_amount') + count($elements))); $this->state->set('simple_sitemap.queue_items_initial_amount', ($this->state->get('simple_sitemap.queue_items_initial_amount') + count($elements)));
} }
...@@ -216,7 +216,7 @@ class QueueWorker { ...@@ -216,7 +216,7 @@ class QueueWorker {
$this->rebuildQueue($variants); $this->rebuildQueue($variants);
} }
while ($element = $this->elementQueue->claimItem()) { while ($element = $this->queue->claimItem()) {
if (!empty($max_execution_time) && Timer::read('simple_sitemap_generator') >= $max_execution_time) { if (!empty($max_execution_time) && Timer::read('simple_sitemap_generator') >= $max_execution_time) {
break; break;
...@@ -244,7 +244,7 @@ class QueueWorker { ...@@ -244,7 +244,7 @@ class QueueWorker {
watchdog_exception('simple_sitemap', $e); watchdog_exception('simple_sitemap', $e);
} }
$this->elementQueue->deleteItem($element); //todo May want to use deleteItems() instead. $this->queue->deleteItem($element); //todo May want to use deleteItems() instead.
$elements_processed++; $elements_processed++;
$this->elementsRemaining--; $this->elementsRemaining--;
} }
...@@ -333,7 +333,7 @@ class QueueWorker { ...@@ -333,7 +333,7 @@ class QueueWorker {
public function getRemainingElementCount($force_recount = FALSE) { public function getRemainingElementCount($force_recount = FALSE) {
if ($force_recount || NULL === $this->elementsRemaining) { if ($force_recount || NULL === $this->elementsRemaining) {
$this->elementsRemaining = $this->elementQueue->numberOfItems(); $this->elementsRemaining = $this->queue->numberOfItems();
} }
return $this->elementsRemaining; return $this->elementsRemaining;
......
...@@ -5,12 +5,10 @@ namespace Drupal\simple_sitemap\Queue; ...@@ -5,12 +5,10 @@ namespace Drupal\simple_sitemap\Queue;
use Drupal\Core\Queue\DatabaseQueue; use Drupal\Core\Queue\DatabaseQueue;
/** /**
* Class ElementQueue * Class SimplesitemapQueue
* @package Drupal\simple_sitemap\Queue * @package Drupal\simple_sitemap\Queue
*
* @todo Need to override claimItem() to what Batch queue uses.
*/ */
class ElementQueue extends DatabaseQueue { class SimplesitemapQueue extends DatabaseQueue {
/** /**
* Overrides \Drupal\Core\Queue\DatabaseQueue::claimItem(). * Overrides \Drupal\Core\Queue\DatabaseQueue::claimItem().
......
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