Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
S
simple_sitemap
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
3
Merge Requests
3
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
simple_sitemap
Commits
dff86b92
Commit
dff86b92
authored
Apr 08, 2018
by
Pawel G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2959479
: Make sitmemap structure pluggable
parent
ce20a672
Changes
26
Show whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
1104 additions
and
368 deletions
+1104
-368
README.md
README.md
+3
-3
simple_sitemap.drush.inc
simple_sitemap.drush.inc
+2
-2
simple_sitemap.install
simple_sitemap.install
+100
-6
simple_sitemap.module
simple_sitemap.module
+7
-4
simple_sitemap.routing.yml
simple_sitemap.routing.yml
+14
-7
simple_sitemap.services.yml
simple_sitemap.services.yml
+7
-14
src/Annotation/SitemapGenerator.php
src/Annotation/SitemapGenerator.php
+67
-0
src/Annotation/UrlGenerator.php
src/Annotation/UrlGenerator.php
+1
-0
src/Batch.php
src/Batch.php
+36
-19
src/Commands/SimplesitemapCommands.php
src/Commands/SimplesitemapCommands.php
+1
-1
src/Controller/SimplesitemapController.php
src/Controller/SimplesitemapController.php
+13
-8
src/Form/SimplesitemapSettingsForm.php
src/Form/SimplesitemapSettingsForm.php
+5
-5
src/Plugin/simple_sitemap/SitemapGenerator/DefaultSitemapGenerator.php
...mple_sitemap/SitemapGenerator/DefaultSitemapGenerator.php
+167
-0
src/Plugin/simple_sitemap/SitemapGenerator/IndexSitemapGenerator.php
...simple_sitemap/SitemapGenerator/IndexSitemapGenerator.php
+134
-0
src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php
.../simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php
+173
-0
src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorInterface.php
...le_sitemap/SitemapGenerator/SitemapGeneratorInterface.php
+11
-0
src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorManager.php
...mple_sitemap/SitemapGenerator/SitemapGeneratorManager.php
+37
-0
src/Plugin/simple_sitemap/SitemapGenerator/SitemapWriter.php
src/Plugin/simple_sitemap/SitemapGenerator/SitemapWriter.php
+13
-0
src/Plugin/simple_sitemap/UrlGenerator/ArbitraryUrlGenerator.php
...gin/simple_sitemap/UrlGenerator/ArbitraryUrlGenerator.php
+8
-5
src/Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php
...Plugin/simple_sitemap/UrlGenerator/CustomUrlGenerator.php
+11
-6
src/Plugin/simple_sitemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php
...itemap/UrlGenerator/EntityMenuLinkContentUrlGenerator.php
+12
-8
src/Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php
...Plugin/simple_sitemap/UrlGenerator/EntityUrlGenerator.php
+13
-9
src/Plugin/simple_sitemap/UrlGenerator/UrlGeneratorBase.php
src/Plugin/simple_sitemap/UrlGenerator/UrlGeneratorBase.php
+154
-96
src/Plugin/simple_sitemap/UrlGeneratorPluginBase.php
src/Plugin/simple_sitemap/UrlGeneratorPluginBase.php
+0
-94
src/Simplesitemap.php
src/Simplesitemap.php
+110
-76
tests/src/Functional/SimplesitemapTest.php
tests/src/Functional/SimplesitemapTest.php
+5
-5
No files found.
README.md
View file @
dff86b92
...
@@ -66,7 +66,7 @@ basis. Just head over to a bundle instance edit form (e.g. node/1/edit) to
...
@@ -66,7 +66,7 @@ basis. Just head over to a bundle instance edit form (e.g. node/1/edit) to
override its sitemap settings.
override its sitemap settings.
If you wish for the sitemap to reflect the new configuration instantly, check
If you wish for the sitemap to reflect the new configuration instantly, check
'Regenerate sitemap after clicking save'. This setting only appears if a change
'Regenerate sitemap
s
after clicking save'. This setting only appears if a change
in the settings has been detected.
in the settings has been detected.
As the sitemap is accessible to anonymous users, bear in mind that only links
As the sitemap is accessible to anonymous users, bear in mind that only links
...
@@ -77,7 +77,7 @@ To include custom links into the sitemap, visit
...
@@ -77,7 +77,7 @@ To include custom links into the sitemap, visit
/admin/config/search/simplesitemap/custom.
/admin/config/search/simplesitemap/custom.
The settings page can be found under admin/config/search/simplesitemap.
The settings page can be found under admin/config/search/simplesitemap.
Here the module can be configured and the sitemap can be manually regenerated.
Here the module can be configured and the sitemap
s
can be manually regenerated.
USAGE
USAGE
...
@@ -85,7 +85,7 @@ USAGE
...
@@ -85,7 +85,7 @@ USAGE
The sitemap is accessible to the whole world under /sitemap.xml.
The sitemap is accessible to the whole world under /sitemap.xml.
If the cron generation is turned on, the sitemap will be regenerated according
If the cron generation is turned on, the sitemap
s
will be regenerated according
to the 'Sitemap generation interval' setting ranging from 'On every cron run' to
to the 'Sitemap generation interval' setting ranging from 'On every cron run' to
'Once a week'.
'Once a week'.
...
...
simple_sitemap.drush.inc
View file @
dff86b92
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
*/
*/
function
simple_sitemap_drush_command
()
{
function
simple_sitemap_drush_command
()
{
$items
[
'simple_sitemap-generate'
]
=
[
$items
[
'simple_sitemap-generate'
]
=
[
'description'
=>
'Regenerate the XML sitemap according to the module settings.'
,
'description'
=>
'Regenerate the XML sitemap
s
according to the module settings.'
,
'callback'
=>
'drush_simple_sitemap_generate'
,
'callback'
=>
'drush_simple_sitemap_generate'
,
'drupal dependencies'
=>
[
'simple_sitemap'
],
'drupal dependencies'
=>
[
'simple_sitemap'
],
];
];
...
@@ -20,7 +20,7 @@ function simple_sitemap_drush_command() {
...
@@ -20,7 +20,7 @@ function simple_sitemap_drush_command() {
/**
/**
* Callback function for hook_drush_command().
* Callback function for hook_drush_command().
*
*
* Regenerate the XML sitemap.
* Regenerate the XML sitemap
s
.
*/
*/
function
drush_simple_sitemap_generate
()
{
function
drush_simple_sitemap_generate
()
{
\
Drupal
::
service
(
'simple_sitemap.generator'
)
->
generateSitemap
(
'drush'
);
\
Drupal
::
service
(
'simple_sitemap.generator'
)
->
generateSitemap
(
'drush'
);
...
...
simple_sitemap.install
View file @
dff86b92
...
@@ -28,7 +28,7 @@ function simple_sitemap_requirements($phase) {
...
@@ -28,7 +28,7 @@ function simple_sitemap_requirements($phase) {
case
'runtime'
:
case
'runtime'
:
$generator
=
\
Drupal
::
service
(
'simple_sitemap.generator'
);
$generator
=
\
Drupal
::
service
(
'simple_sitemap.generator'
);
$generated_ago
=
$generator
->
getGeneratedAgo
(
);
$generated_ago
=
$generator
->
getGeneratedAgo
(
'default'
);
//todo
$cron_generation
=
$generator
->
getSetting
(
'cron_generate'
);
$cron_generation
=
$generator
->
getSetting
(
'cron_generate'
);
if
(
!
$generated_ago
)
{
if
(
!
$generated_ago
)
{
...
@@ -42,12 +42,11 @@ function simple_sitemap_requirements($phase) {
...
@@ -42,12 +42,11 @@ function simple_sitemap_requirements($phase) {
$severity
=
REQUIREMENT_WARNING
;
$severity
=
REQUIREMENT_WARNING
;
}
}
else
{
else
{
$value
=
t
(
'XML sitemap
is
available'
);
$value
=
t
(
'XML sitemap
s are
available'
);
$description
=
t
(
'The
<a href="@sitemap">XML sitemap</a> was generat
ed @ago ago.'
$description
=
t
(
'The
last generation finish
ed @ago ago.'
.
' '
.
(
$cron_generation
.
' '
.
(
$cron_generation
?
'Run cron, or <a href="@generate">regenerate</a> the sitemap manually.'
?
'Run cron, or <a href="@generate">regenerate</a> the sitemaps manually.'
:
'Generation on cron run is disabled. <a href="@generate">Regenerate</a> the sitemap manually.'
),
[
:
'Generation on cron run is disabled. <a href="@generate">Regenerate</a> the sitemaps manually.'
),
[
'@sitemap'
=>
$GLOBALS
[
'base_url'
]
.
'/sitemap.xml'
,
'@ago'
=>
$generated_ago
,
'@ago'
=>
$generated_ago
,
'@generate'
=>
$GLOBALS
[
'base_url'
]
.
'/admin/config/search/simplesitemap'
'@generate'
=>
$GLOBALS
[
'base_url'
]
.
'/admin/config/search/simplesitemap'
]
]
...
@@ -80,6 +79,20 @@ function simple_sitemap_schema() {
...
@@ -80,6 +79,20 @@ function simple_sitemap_schema() {
'not null'
=>
TRUE
,
'not null'
=>
TRUE
,
'unsigned'
=>
TRUE
,
'unsigned'
=>
TRUE
,
],
],
'type'
=>
[
'description'
=>
'Type of sitemap this chunk belongs to.'
,
'type'
=>
'varchar'
,
'length'
=>
50
,
'not null'
=>
TRUE
,
'default'
=>
''
,
],
'delta'
=>
[
'description'
=>
'Delta of the chunk within the type scope.'
,
'type'
=>
'int'
,
'size'
=>
'small'
,
'not null'
=>
TRUE
,
'unsigned'
=>
TRUE
,
],
'sitemap_string'
=>
[
'sitemap_string'
=>
[
'description'
=>
'XML sitemap chunk string.'
,
'description'
=>
'XML sitemap chunk string.'
,
'type'
=>
'text'
,
'type'
=>
'text'
,
...
@@ -97,6 +110,26 @@ function simple_sitemap_schema() {
...
@@ -97,6 +110,26 @@ function simple_sitemap_schema() {
'primary key'
=>
[
'id'
],
'primary key'
=>
[
'id'
],
];
];
// $schema['simple_sitemap_index'] = [
// 'description' => 'Holds XML sitemaps indexes as strings for quick retrieval.',
// 'fields' => [
// 'id' => [
// 'description' => 'Sitemap index unique identifier.',
// 'type' => 'varchar',
// 'length' => 50,
// 'not null' => TRUE,
// 'default' => '',
// ],
// 'sitemap_string' => [
// 'description' => 'XML sitemap index string.',
// 'type' => 'text',
// 'size' => 'big',
// 'not null' => TRUE,
// ]
// ],
// 'primary key' => ['id'],
// ];
$schema
[
'simple_sitemap_entity_overrides'
]
=
[
$schema
[
'simple_sitemap_entity_overrides'
]
=
[
'description'
=>
'Holds sitemap settings overridden by entities.'
,
'description'
=>
'Holds sitemap settings overridden by entities.'
,
'fields'
=>
[
'fields'
=>
[
...
@@ -398,3 +431,64 @@ function simple_sitemap_update_8209() {
...
@@ -398,3 +431,64 @@ function simple_sitemap_update_8209() {
return
t
(
'You may now want to configure your sitemap entities to include images.'
);
return
t
(
'You may now want to configure your sitemap entities to include images.'
);
}
}
/**
* Adding simple_sitemap_index table and altering the simple_sitemap table.
*/
function
simple_sitemap_update_8210
()
{
$database
=
\
Drupal
::
database
();
// Create simple_sitemap_index table.
// if (!$database->schema()->tableExists('simple_sitemap_index')) {
// $database->schema()->createTable('simple_sitemap_index', [
// 'description' => 'Holds XML sitemaps indexes as strings for quick retrieval.',
// 'fields' => [
// 'id' => [
// 'description' => 'Sitemap index unique identifier.',
// 'type' => 'varchar',
// 'length' => 50,
// 'not null' => TRUE,
// 'default' => '',
// ],
// 'sitemap_string' => [
// 'description' => 'XML sitemap index string.',
// 'type' => 'text',
// 'size' => 'big',
// 'not null' => TRUE,
// ]
// ],
// 'primary key' => ['id'],
// ]);
// }
// Alter simple_sitemap table.
$database
->
truncate
(
'simple_sitemap'
)
->
execute
();
if
(
!
$database
->
schema
()
->
fieldExists
(
'simple_sitemap'
,
'type'
))
{
$database
->
schema
()
->
addField
(
'simple_sitemap'
,
'type'
,
[
'description'
=>
'Type of sitemap this chunk belongs to.'
,
'type'
=>
'varchar'
,
'length'
=>
50
,
'not null'
=>
TRUE
,
'default'
=>
''
,
]
);
}
if
(
!
$database
->
schema
()
->
fieldExists
(
'simple_sitemap'
,
'delta'
))
{
$database
->
schema
()
->
addField
(
'simple_sitemap'
,
'delta'
,
[
'description'
=>
'Delta of the chunk within the type scope.'
,
'type'
=>
'int'
,
'size'
=>
'small'
,
'not null'
=>
TRUE
,
'unsigned'
=>
TRUE
,
]
);
}
}
simple_sitemap.module
View file @
dff86b92
...
@@ -240,9 +240,9 @@ function simple_sitemap_delete_bundle_config($entity_type_id, $bundle) {
...
@@ -240,9 +240,9 @@ function simple_sitemap_delete_bundle_config($entity_type_id, $bundle) {
// Delete bundle settings.
// Delete bundle settings.
\
Drupal
::
service
(
'config.factory'
)
->
getEditable
(
"simple_sitemap.bundle_settings.
$entity_type_id
.
$bundle
"
)
->
delete
();
\
Drupal
::
service
(
'config.factory'
)
->
getEditable
(
"simple_sitemap.bundle_settings.
$entity_type_id
.
$bundle
"
)
->
delete
();
$message
=
'You may want to <a href="@url">regenerate</a> your XML sitemap now.'
;
$message
=
'You may want to <a href="@url">regenerate</a> your XML sitemap
s
now.'
;
if
(
$generator
->
getSetting
(
'cron_generate'
))
{
if
(
$generator
->
getSetting
(
'cron_generate'
))
{
$message
.
=
' Otherwise the sitemap will be regenerated during a future cron run.'
;
$message
.
=
' Otherwise the sitemap
s
will be regenerated during a future cron run.'
;
}
}
drupal_set_message
(
t
(
$message
,
[
'@url'
=>
$GLOBALS
[
'base_url'
]
.
'/admin/config/search/simplesitemap'
]));
drupal_set_message
(
t
(
$message
,
[
'@url'
=>
$GLOBALS
[
'base_url'
]
.
'/admin/config/search/simplesitemap'
]));
}
}
...
@@ -250,10 +250,13 @@ function simple_sitemap_delete_bundle_config($entity_type_id, $bundle) {
...
@@ -250,10 +250,13 @@ function simple_sitemap_delete_bundle_config($entity_type_id, $bundle) {
/**
/**
* Implements hook_robotstxt().
* Implements hook_robotstxt().
*
* @todo Use sitemap base URL setting?
* @todo include non-default sitemaps as well?
*/
*/
function
simple_sitemap_robotstxt
()
{
function
simple_sitemap_robotstxt
()
{
return
[
return
[
'# XML sitemap'
,
'# XML sitemap
s
'
,
'Sitemap: '
.
$GLOBALS
[
'base_url'
]
.
'/sitemap.xml'
,
//todo: Use base URL setting?
'Sitemap: '
.
$GLOBALS
[
'base_url'
]
.
'/sitemap.xml'
,
];
];
}
}
simple_sitemap.routing.yml
View file @
dff86b92
simple_sitemap.sitemap
:
simple_sitemap.sitemap
_default
:
path
:
'
/sitemap.xml'
path
:
'
/sitemap.xml'
defaults
:
defaults
:
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements
:
requirements
:
_access
:
'
TRUE'
_access
:
'
TRUE'
simple_sitemap.sitemap
s
:
simple_sitemap.sitemap
_type
:
path
:
'
/sitemaps'
path
:
'
/sitemaps
/{type}/sitemap.xml
'
defaults
:
defaults
:
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements
:
requirements
:
_access
:
'
TRUE'
_access
:
'
TRUE'
simple_sitemap.
chunk
_fallback
:
simple_sitemap.
sitemap_type
_fallback
:
path
:
'
/sitemaps/{
chunk_id
}'
path
:
'
/sitemaps/{
type
}'
defaults
:
defaults
:
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements
:
requirements
:
_access
:
'
TRUE'
_access
:
'
TRUE'
simple_sitemap.chunk
:
simple_sitemap.sitemap_type_delta
:
path
:
'
/sitemaps/{chunk_id}/sitemap.xml'
path
:
'
/sitemaps/{type}/{delta}/sitemap.xml'
defaults
:
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements
:
_access
:
'
TRUE'
simple_sitemap.sitemap_type_delta_fallback
:
path
:
'
/sitemaps/{type}/{delta}'
defaults
:
defaults
:
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
_controller
:
'
\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements
:
requirements
:
...
...
simple_sitemap.services.yml
View file @
dff86b92
...
@@ -3,7 +3,6 @@ services:
...
@@ -3,7 +3,6 @@ services:
class
:
Drupal\simple_sitemap\Simplesitemap
class
:
Drupal\simple_sitemap\Simplesitemap
public
:
true
public
:
true
arguments
:
arguments
:
-
'
@simple_sitemap.sitemap_generator'
-
'
@simple_sitemap.entity_helper'
-
'
@simple_sitemap.entity_helper'
-
'
@config.factory'
-
'
@config.factory'
-
'
@database'
-
'
@database'
...
@@ -13,21 +12,11 @@ services:
...
@@ -13,21 +12,11 @@ services:
-
'
@datetime.time'
-
'
@datetime.time'
-
'
@simple_sitemap.batch'
-
'
@simple_sitemap.batch'
-
'
@plugin.manager.simple_sitemap.url_generator'
-
'
@plugin.manager.simple_sitemap.url_generator'
-
'
@plugin.manager.simple_sitemap.sitemap_generator'
simple_sitemap.sitemap_generator
:
class
:
Drupal\simple_sitemap\SitemapGenerator
public
:
true
arguments
:
-
'
@simple_sitemap.entity_helper'
-
'
@database'
-
'
@module_handler'
-
'
@language_manager'
-
'
@datetime.time'
-
'
@simple_sitemap.sitemap_writer'
simple_sitemap.sitemap_writer
:
simple_sitemap.sitemap_writer
:
class
:
Drupal\simple_sitemap\SitemapWriter
class
:
Drupal\simple_sitemap\
Plugin\simple_sitemap\SitemapGenerator\
SitemapWriter
public
:
fals
e
public
:
tru
e
simple_sitemap.entity_helper
:
simple_sitemap.entity_helper
:
class
:
Drupal\simple_sitemap\EntityHelper
class
:
Drupal\simple_sitemap\EntityHelper
...
@@ -64,3 +53,7 @@ services:
...
@@ -64,3 +53,7 @@ services:
plugin.manager.simple_sitemap.url_generator
:
plugin.manager.simple_sitemap.url_generator
:
class
:
Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\UrlGeneratorManager
class
:
Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator\UrlGeneratorManager
parent
:
default_plugin_manager
parent
:
default_plugin_manager
plugin.manager.simple_sitemap.sitemap_generator
:
class
:
Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator\SitemapGeneratorManager
parent
:
default_plugin_manager
src/Annotation/SitemapGenerator.php
0 → 100644
View file @
dff86b92
<?php
namespace
Drupal\simple_sitemap\Annotation
;
use
Drupal\Component\Annotation\Plugin
;
/**
* Defines a SitemapGenerator item annotation object.
*
* @package Drupal\simple_sitemap\Annotation
*
* @see \Drupal\simple_sitemap\Plugin\simple_sitemap\SitemapGenerator\SitemapGeneratorManager
* @see plugin_api
*
* @Annotation
*/
class
SitemapGenerator
extends
Plugin
{
/**
* The generator ID.
*
* @var string
*/
public
$id
;
/**
* The human-readable name of the generator.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public
$title
;
/**
* A short description of the generator.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public
$description
;
/**
* An integer to determine the weight of this generator relative to others.
*
* @var int
*/
public
$weight
=
0
;
/**
* Whether the generator is enabled by default.
*
* @var bool
*/
public
$enabled
=
TRUE
;
/**
* Default generator settings.
*
* @var array
*/
public
$settings
=
[
'list'
=>
TRUE
,
'default'
=>
FALSE
,
];
}
src/Annotation/UrlGenerator.php
View file @
dff86b92
...
@@ -61,6 +61,7 @@ class UrlGenerator extends Plugin {
...
@@ -61,6 +61,7 @@ class UrlGenerator extends Plugin {
* @var array
* @var array
*/
*/
public
$settings
=
[
public
$settings
=
[
'default_sitemap_generator'
=>
'default'
,
'instantiate_for_each_data_set'
=>
FALSE
,
'instantiate_for_each_data_set'
=>
FALSE
,
];
];
}
}
src/Batch.php
View file @
dff86b92
...
@@ -26,11 +26,16 @@ class Batch {
...
@@ -26,11 +26,16 @@ class Batch {
*/
*/
protected
$batchSettings
;
protected
$batchSettings
;
/**
* @var array
*/
protected
$batchMeta
;
const
BATCH_TITLE
=
'Generating XML sitemap'
;
const
BATCH_TITLE
=
'Generating XML sitemap'
;
const
BATCH_INIT_MESSAGE
=
'Initializing batch...'
;
const
BATCH_INIT_MESSAGE
=
'Initializing batch...'
;
const
BATCH_ERROR_MESSAGE
=
'An error has occurred. This may result in an incomplete XML sitemap.'
;
const
BATCH_ERROR_MESSAGE
=
'An error has occurred. This may result in an incomplete XML sitemap.'
;
const
BATCH_PROGRESS_MESSAGE
=
'Processing @current out of @total link types.'
;
const
BATCH_PROGRESS_MESSAGE
=
'Processing @current out of @total link types.'
;
const
REGENERATION_FINISHED_MESSAGE
=
'The
<a href="@url" target="_blank">XML sitemap</a> has
been regenerated.'
;
const
REGENERATION_FINISHED_MESSAGE
=
'The
XML sitemaps have
been regenerated.'
;
const
REGENERATION_FINISHED_ERROR_MESSAGE
=
'The sitemap generation finished with an error.'
;
const
REGENERATION_FINISHED_ERROR_MESSAGE
=
'The sitemap generation finished with an error.'
;
/**
/**
...
@@ -54,11 +59,24 @@ class Batch {
...
@@ -54,11 +59,24 @@ class Batch {
$this
->
batchSettings
=
$batch_settings
;
$this
->
batchSettings
=
$batch_settings
;
}
}
/**
* @param array $batch_meta
*/
public
function
setBatchMeta
(
array
$batch_meta
)
{
$this
->
batchMeta
=
$batch_meta
;
}
/**
/**
* Starts the batch process depending on where it was requested from.
* Starts the batch process depending on where it was requested from.
*/
*/
public
function
start
()
{
public
function
start
()
{
switch
(
$this
->
batchSettings
[
'from'
])
{
// Update total operation count for each operation.
foreach
(
$this
->
batch
[
'operations'
]
as
$i
=>
$operation
)
{
$this
->
batch
[
'operations'
][
$i
][
1
][
3
][
'operations_count'
]
=
count
(
$this
->
batch
[
'operations'
]);
}
switch
(
$this
->
batchMeta
[
'from'
])
{
case
'form'
:
case
'form'
:
// Start batch process.
// Start batch process.
...
@@ -98,8 +116,7 @@ class Batch {
...
@@ -98,8 +116,7 @@ class Batch {
$operation
[
1
][]
=
&
$context
;
$operation
[
1
][]
=
&
$context
;
call_user_func_array
(
$operation
[
0
],
$operation
[
1
]);
call_user_func_array
(
$operation
[
0
],
$operation
[
1
]);
}
}
$this
->
finishGeneration
(
TRUE
,
!
empty
(
$context
[
'results'
])
?
$context
[
'results'
]
:
[],
[]);
return
$this
->
finishGeneration
(
TRUE
,
!
empty
(
$context
[
'results'
])
?
$context
[
'results'
]
:
[],
[]);
return
TRUE
;
}
}
return
FALSE
;
return
FALSE
;
}
}
...
@@ -107,29 +124,32 @@ class Batch {
...
@@ -107,29 +124,32 @@ class Batch {
/**
/**
* Adds an operation to the batch.
* Adds an operation to the batch.
*
*
* @param
$plugin_id
* @param
string $url_generator_id$data_sets
* @param array|null $data_sets
* @param array|null $data_sets
*/
*/
public
function
addOperation
(
$plugin_id
,
$data_sets
=
NULL
)
{
public
function
addOperation
(
$url_generator_id
,
$data_sets
=
NULL
)
{
$this
->
batch
[
'operations'
][]
=
[
$operation_no
=
count
(
$this
->
batch
[
'operations'
])
+
1
;
__CLASS__
.
'::generate'
,
[
$plugin_id
,
$data_sets
,
$this
->
batchSettings
],
$this
->
batch
[
'operations'
][
$operation_no
]
=
[
__CLASS__
.
'::generate'
,
[
$url_generator_id
,
$data_sets
,
$this
->
batchSettings
,
$this
->
batchMeta
+
[
'current_operation_no'
=>
$operation_no
]],
];
];
}
}
/**
/**
* Batch callback function which generates URLs.
* Batch callback function which generates URLs.
*
*
* @param
$plugin
_id
* @param
string $url_generator
_id
* @param array|null $data_sets
* @param array|null $data_sets
* @param array $batch_settings
* @param array $batch_settings
* @param array $batch_meta
* @param $context
* @param $context
*
*
* @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8
* @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8
*/
*/
public
static
function
generate
(
$
plugin_id
,
$data_sets
,
array
$batch_settings
,
&
$context
)
{
public
static
function
generate
(
$
url_generator_id
,
$data_sets
,
array
$batch_settings
,
array
$batch_meta
,
&
$context
)
{
\
Drupal
::
service
(
'plugin.manager.simple_sitemap.url_generator'
)
\
Drupal
::
service
(
'plugin.manager.simple_sitemap.url_generator'
)
->
createInstance
(
$
plugin
_id
)
->
createInstance
(
$
url_generator
_id
)
->
setContext
(
$context
)
->
setContext
(
$context
)
->
setBatchMeta
(
$batch_meta
)
->
setBatchSettings
(
$batch_settings
)
->
setBatchSettings
(
$batch_settings
)
->
generate
(
$data_sets
);
->
generate
(
$data_sets
);
}
}
...
@@ -141,19 +161,14 @@ class Batch {
...
@@ -141,19 +161,14 @@ class Batch {
* @param $results
* @param $results
* @param $operations
* @param $operations
*
*
* @return bool
*
* @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8
* @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8
*/
*/
public
static
function
finishGeneration
(
$success
,
$results
,
$operations
)
{
public
static
function
finishGeneration
(
$success
,
$results
,
$operations
)
{
if
(
$success
)
{
if
(
$success
)
{
$remove_sitemap
=
empty
(
$results
[
'chunk_count'
]);
if
(
!
empty
(
$results
[
'generate'
])
||
$remove_sitemap
)
{
\
Drupal
::
service
(
'simple_sitemap.sitemap_generator'
)
->
setSettings
([
'excluded_languages'
=>
\
Drupal
::
service
(
'simple_sitemap.generator'
)
->
getSetting
(
'excluded_languages'
,
[])])
->
generateSitemap
(
!
empty
(
$results
[
'generate'
])
?
$results
[
'generate'
]
:
[],
$remove_sitemap
);
}
Cache
::
invalidateTags
([
'simple_sitemap'
]);
Cache
::
invalidateTags
([
'simple_sitemap'
]);
\
Drupal
::
service
(
'simple_sitemap.logger'
)
->
m
(
self
::
REGENERATION_FINISHED_MESSAGE
,
\
Drupal
::
service
(
'simple_sitemap.logger'
)
->
m
(
self
::
REGENERATION_FINISHED_MESSAGE
)
[
'@url'
=>
$GLOBALS
[
'base_url'
]
.
'/sitemap.xml'
])
// ['@url' => $this->sitemapGenerator->getCustomBaseUrl() . '/sitemap.xml']) //todo: Use actual base URL for message.
// ['@url' => $this->sitemapGenerator->getCustomBaseUrl() . '/sitemap.xml']) //todo: Use actual base URL for message.
->
display
(
'status'
)
->
display
(
'status'
)
->
log
(
'info'
);
->
log
(
'info'
);
...
@@ -163,6 +178,8 @@ class Batch {
...
@@ -163,6 +178,8 @@ class Batch {
->
display
(
'error'
,
'administer sitemap settings'
)
->
display
(
'error'
,
'administer sitemap settings'
)
->
log
(
'error'
);
->
log
(
'error'
);
}
}
return
$success
;
}
}