Commit 7ad3960b authored by gbyte.co's avatar gbyte.co

Clean up

parent 0854540b
......@@ -109,7 +109,7 @@ function hook_simple_sitemap_index_attributes_alter(array &$index_attributes, $s
}
/**
* Alter properties of and remove generator plugins.
* Alter properties of and remove URL generator plugins.
*
* @param array $url_generators
*/
......@@ -120,7 +120,7 @@ function hook_simple_sitemap_url_generators_alter(array &$url_generators) {
}
/**
* Alter properties of and remove generator plugins.
* Alter properties of and remove sitemap generator plugins.
*
* @param array $sitemap_generators
*/
......
......@@ -30,7 +30,7 @@ function simple_sitemap_requirements($phase) {
case 'runtime':
$generator = \Drupal::service('simple_sitemap.generator');
$generated_ago = $generator->getGeneratedAgo(SitemapGeneratorBase::DEFAULT_SITEMAP_VARIANT); //todo
$generated_ago = $generator->getGeneratedAgo(\Drupal\simple_sitemap\Simplesitemap::DEFAULT_SITEMAP_VARIANT); //todo
$cron_generation = $generator->getSetting('cron_generate');
if (!$generated_ago) {
......
......@@ -66,7 +66,7 @@ class SimplesitemapController extends ControllerBase {
* @return object
* Returns an XML response.
*/
public function getSitemap($variant = SitemapGeneratorBase::DEFAULT_SITEMAP_VARIANT, $delta = NULL) {
public function getSitemap($variant = Simplesitemap::DEFAULT_SITEMAP_VARIANT, $delta = NULL) {
$output = $this->generator->getSitemap($variant, $delta);
if (!$output) {
$this->cacheKillSwitch->trigger();
......
......@@ -3,6 +3,7 @@
namespace Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator;
use Drupal\simple_sitemap\Plugin\simple_sitemap\SimplesitemapPluginBase;
use Drupal\simple_sitemap\Simplesitemap;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Extension\ModuleHandler;
......@@ -18,10 +19,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
const FIRST_CHUNK_DELTA = 1;
const INDEX_DELTA = 0;
// todo Move this to Simplesitemap class?
const DEFAULT_SITEMAP_VARIANT = 'default';
const DEFAULT_SITEMAP_TYPE = 'default_hreflang';
const GENERATED_BY = 'Generated by the Simple XML sitemap Drupal module: https://drupal.org/project/simple_sitemap.';
const XML_VERSION = '1.0';
const ENCODING = 'UTF-8';
......@@ -96,7 +93,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
$this->languageManager = $language_manager;
$this->time = $time;
$this->writer = $sitemap_writer;
$this->sitemapVariant = self::DEFAULT_SITEMAP_VARIANT;
$this->sitemapVariant = Simplesitemap::DEFAULT_SITEMAP_VARIANT;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
......
......@@ -20,6 +20,9 @@ use Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\UrlGeneratorManager
*/
class Simplesitemap {
const DEFAULT_SITEMAP_TYPE = 'default_hreflang';
const DEFAULT_SITEMAP_VARIANT = 'default';
/**
* @var \Drupal\simple_sitemap\EntityHelper
*/
......@@ -183,8 +186,8 @@ class Simplesitemap {
* links setting. If a sitemap ID is provided, a sitemap chunk is returned.
* Returns false if the sitemap is not retrievable from the database.
*/
public function getSitemap($variant = SitemapGeneratorBase::DEFAULT_SITEMAP_VARIANT, $delta = NULL) {
$chunk_info = $this->fetchSitemapChunkInfo($variant);
public function getSitemap($variant = self::DEFAULT_SITEMAP_VARIANT, $delta = NULL) {
$chunk_info = $this->fetchSitemapVariantInfo($variant);
if (empty($delta) || !isset($chunk_info[$delta])) {
......@@ -208,14 +211,15 @@ class Simplesitemap {
}
/**
* Fetches all sitemap chunk timestamps keyed by chunk ID.
* Fetches info about all sitemap variants and their chunks.
*
* @param string|null $variant
*
* @return array
* An array containing chunk creation timestamps keyed by chunk ID.
* An array containing all sitemap chunk IDs, deltas and creation timestamps
* keyed by their variant ID.
*/
protected function fetchSitemapChunkInfo($variant = NULL) {
protected function fetchSitemapVariantInfo($variant = NULL) {
$query = $this->db->select('simple_sitemap', 's')
->fields('s', ['id', 'delta', 'sitemap_created', 'type']);
......@@ -279,10 +283,9 @@ class Simplesitemap {
* @param $name
*
* @todo document
* @todo translate label, description
*/
public function removeSitemapTypeDefinition($name) {
if ($name !== SitemapGeneratorBase::DEFAULT_SITEMAP_TYPE) {
if ($name !== self::DEFAULT_SITEMAP_TYPE) {
$this->configFactory->getEditable("simple_sitemap.types.$name")->delete();
}
else {
......@@ -310,11 +313,11 @@ class Simplesitemap {
*/
public function addSitemapVariant($name, $definition) {
if (empty($definition['label'])) {
$definition['type'] = $name;
$definition['label'] = $name;
}
if (empty($definition['type'])) {
$definition['type'] = SitemapGeneratorBase::DEFAULT_SITEMAP_TYPE;
$definition['type'] = self::DEFAULT_SITEMAP_TYPE;
}
$variants = array_merge($this->getSitemapVariants(), [$name => ['label' => $definition['label'], 'type' => $definition['type']]]);
......@@ -332,9 +335,11 @@ class Simplesitemap {
*/
public function removeSitemapVariant($name) {
$variants = $this->getSitemapVariants();
unset($variants[$name]);
$this->configFactory->getEditable('simple_sitemap.variants')
->set('variants', $variants)->save();
if (isset($variants[$name])) {
unset($variants[$name]);
$this->configFactory->getEditable('simple_sitemap.variants')
->set('variants', $variants)->save();
}
return $this;
}
......@@ -450,7 +455,7 @@ class Simplesitemap {
* Formatted timestamp of last sitemap generation, otherwise FALSE.
*/
public function getGeneratedAgo($variant = NULL) {
$chunks = $this->fetchSitemapChunkInfo($variant);
$chunks = $this->fetchSitemapVariantInfo($variant);
if ($variant !== NULL) {
return isset($chunks[DefaultSitemapGenerator::FIRST_CHUNK_DELTA]->sitemap_created)
? $this->dateFormatter
......@@ -550,7 +555,7 @@ class Simplesitemap {
->getEditable("simple_sitemap.bundle_settings.$entity_type_id.$bundle_name");
foreach ($settings as $setting_key => $setting) {
if ($setting_key === 'index') {
$setting = intval($setting);
$setting = (int) $setting;
}
$bundle_settings->set($setting_key, $setting);
}
......
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