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

Use constants

parent e97347fe
......@@ -5,6 +5,8 @@
* Drush (< 9) integration.
*/
use Drupal\simple_sitemap\Queue\QueueWorker;
/**
* Implements hook_drush_command().
*/
......@@ -32,7 +34,7 @@ function simple_sitemap_drush_command() {
* Regenerate the XML sitemaps according to the module settings.
*/
function drush_simple_sitemap_generate() {
\Drupal::service('simple_sitemap.generator')->generateSitemap('drush');
\Drupal::service('simple_sitemap.generator')->generateSitemap(QueueWorker::GENERATE_TYPE_DRUSH);
}
/**
......
......@@ -8,6 +8,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\simple_sitemap\Queue\QueueWorker;
use Drupal\system\MenuInterface;
use Drupal\language\ConfigurableLanguageInterface;
......@@ -159,7 +160,7 @@ function simple_sitemap_cron() {
$state->set('simple_sitemap.last_cron_generate', $request_time);
}
$generator->generateSitemap('cron');
$generator->generateSitemap(QueueWorker::GENERATE_TYPE_CRON);
}
}
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\simple_sitemap\Commands;
use Drupal\simple_sitemap\Queue\QueueWorker;
use Drupal\simple_sitemap\Simplesitemap;
use Drush\Commands\DrushCommands;
......@@ -37,7 +38,7 @@ class SimplesitemapCommands extends DrushCommands {
* @aliases ssg, simple-sitemap-generate
*/
public function generate() {
$this->generator->generateSitemap('drush');
$this->generator->generateSitemap(QueueWorker::GENERATE_TYPE_DRUSH);
}
/**
......
......@@ -20,7 +20,7 @@ trait BatchTrait {
* @param array|null $variants
* @return bool
*/
public function batchGenerateSitemap($from = 'form', $variants = NULL) {
public function batchGenerateSitemap($from = self::GENERATE_TYPE_FORM, $variants = NULL) {
$this->batch = [
'title' => $this->t('Generating XML sitemaps'),
'init_message' => $this->t('Initializing...'),
......@@ -32,12 +32,12 @@ trait BatchTrait {
switch ($from) {
case 'form':
case self::GENERATE_TYPE_FORM:
// Start batch process.
batch_set($this->batch);
return TRUE;
case 'drush':
case self::GENERATE_TYPE_DRUSH:
// Start drush batch process.
batch_set($this->batch);
......
......@@ -16,6 +16,11 @@ class QueueWorker {
const REBUILD_QUEUE_CHUNK_ITEM_SIZE = 5000;
const GENERATE_TYPE_FORM = 'form';
const GENERATE_TYPE_DRUSH = 'drush';
const GENERATE_TYPE_CRON = 'cron';
const GENERATE_TYPE_BACKEND = 'backend';
/**
* @var \Drupal\simple_sitemap\SimplesitemapSettings
*/
......@@ -199,7 +204,7 @@ class QueueWorker {
* @return $this
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
public function generateSitemap($from = 'form') {
public function generateSitemap($from = self::GENERATE_TYPE_FORM) {
$this->generatorSettings = [
'base_url' => $this->settings->getSetting('base_url', ''),
......
......@@ -319,15 +319,15 @@ class Simplesitemap {
*
* @todo Implement lock functionality.
*/
public function generateSitemap($from = 'form') {
public function generateSitemap($from = QueueWorker::GENERATE_TYPE_FORM) {
switch($from) {
case 'form':
case 'drush':
case QueueWorker::GENERATE_TYPE_FORM:
case QueueWorker::GENERATE_TYPE_DRUSH;
$this->queueWorker->batchGenerateSitemap($from);
break;
case 'cron':
case 'backend':
case QueueWorker::GENERATE_TYPE_CRON:
case QueueWorker::GENERATE_TYPE_BACKEND:
$this->queueWorker->generateSitemap($from);
break;
}
......
This diff is collapsed.
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