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
0
Merge Requests
0
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
65a5da69
Commit
65a5da69
authored
Nov 16, 2018
by
Pawel G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix empty variants not being deleted on generate and clean up
parent
eee77e49
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
44 deletions
+53
-44
src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php
.../simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php
+2
-7
src/Queue/QueueWorker.php
src/Queue/QueueWorker.php
+27
-18
src/Simplesitemap.php
src/Simplesitemap.php
+3
-17
src/SimplesitemapManager.php
src/SimplesitemapManager.php
+21
-2
No files found.
src/Plugin/simple_sitemap/SitemapGenerator/SitemapGeneratorBase.php
View file @
65a5da69
...
@@ -119,7 +119,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
...
@@ -119,7 +119,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
/**
/**
* @return bool
* @return bool
* @todo: Variant cannot be null
*/
*/
protected
function
isDefaultVariant
()
{
protected
function
isDefaultVariant
()
{
return
$this
->
sitemapVariant
===
$this
->
settings
[
'default_variant'
];
return
$this
->
sitemapVariant
===
$this
->
settings
[
'default_variant'
];
...
@@ -128,7 +127,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
...
@@ -128,7 +127,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
/**
/**
* @param array $links
* @param array $links
* @return string
* @return string
* @todo: Variant cannot be null
*/
*/
abstract
protected
function
getXml
(
array
$links
);
abstract
protected
function
getXml
(
array
$links
);
...
@@ -146,7 +144,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
...
@@ -146,7 +144,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
* Returns the sitemap index for all sitemap chunks of this type.
* Returns the sitemap index for all sitemap chunks of this type.
*
*
* @return string
* @return string
* @todo: Variant cannot be null
*/
*/
protected
function
getIndexXml
(
array
$chunk_info
)
{
protected
function
getIndexXml
(
array
$chunk_info
)
{
$this
->
writer
->
openMemory
();
$this
->
writer
->
openMemory
();
...
@@ -183,12 +180,12 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
...
@@ -183,12 +180,12 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
* @return $this
* @return $this
*/
*/
public
function
remove
(
$mode
=
'all'
)
{
public
function
remove
(
$mode
=
'all'
)
{
self
::
remov
eSitemapVariants
(
$this
->
sitemapVariant
,
$mode
);
self
::
purg
eSitemapVariants
(
$this
->
sitemapVariant
,
$mode
);
return
$this
;
return
$this
;
}
}
public
static
function
remov
eSitemapVariants
(
$variants
=
NULL
,
$mode
=
'all'
)
{
public
static
function
purg
eSitemapVariants
(
$variants
=
NULL
,
$mode
=
'all'
)
{
if
(
NULL
===
$variants
||
!
empty
((
array
)
$variants
))
{
if
(
NULL
===
$variants
||
!
empty
((
array
)
$variants
))
{
$delete_query
=
\
Drupal
::
database
()
->
delete
(
'simple_sitemap'
);
$delete_query
=
\
Drupal
::
database
()
->
delete
(
'simple_sitemap'
);
...
@@ -223,7 +220,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
...
@@ -223,7 +220,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
* @param array $links
* @param array $links
* All links with their multilingual versions and settings.
* All links with their multilingual versions and settings.
*
*
* @todo Variant cannot be null
*/
*/
public
function
generate
(
array
$links
)
{
public
function
generate
(
array
$links
)
{
$highest_id
=
$this
->
db
->
query
(
'SELECT MAX(id) FROM {simple_sitemap}'
)
->
fetchField
();
$highest_id
=
$this
->
db
->
query
(
'SELECT MAX(id) FROM {simple_sitemap}'
)
->
fetchField
();
...
@@ -244,7 +240,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
...
@@ -244,7 +240,6 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
/**
/**
* @throws \Exception
* @throws \Exception
* @todo: Variant cannot be null
*/
*/
public
function
generateIndex
()
{
public
function
generateIndex
()
{
if
(
!
empty
(
$chunk_info
=
$this
->
getChunkInfo
())
&&
count
(
$chunk_info
)
>
1
)
{
if
(
!
empty
(
$chunk_info
=
$this
->
getChunkInfo
())
&&
count
(
$chunk_info
)
>
1
)
{
...
...
src/Queue/QueueWorker.php
View file @
65a5da69
...
@@ -115,7 +115,7 @@ class QueueWorker {
...
@@ -115,7 +115,7 @@ class QueueWorker {
*/
*/
public
function
deleteQueue
()
{
public
function
deleteQueue
()
{
$this
->
queue
->
deleteQueue
();
$this
->
queue
->
deleteQueue
();
SitemapGeneratorBase
::
removeSitemapVariants
(
NULL
,
'unpublished'
);
//todo should call the remove() method of every plugin instead?
SitemapGeneratorBase
::
purgeSitemapVariants
(
NULL
,
'unpublished'
);
$this
->
variantProcessedNow
=
NULL
;
$this
->
variantProcessedNow
=
NULL
;
$this
->
generatorProcessedNow
=
NULL
;
$this
->
generatorProcessedNow
=
NULL
;
$this
->
results
=
[];
$this
->
results
=
[];
...
@@ -136,7 +136,7 @@ class QueueWorker {
...
@@ -136,7 +136,7 @@ class QueueWorker {
* @todo Lock functionality
* @todo Lock functionality
*/
*/
public
function
rebuildQueue
(
$variants
=
NULL
)
{
public
function
rebuildQueue
(
$variants
=
NULL
)
{
$data_sets
=
[];
$
all_
data_sets
=
[];
$sitemap_variants
=
$this
->
manager
->
getSitemapVariants
();
$sitemap_variants
=
$this
->
manager
->
getSitemapVariants
();
$this
->
moduleHandler
->
alter
(
'simple_sitemap_variants'
,
$sitemap_variants
);
$this
->
moduleHandler
->
alter
(
'simple_sitemap_variants'
,
$sitemap_variants
);
...
@@ -155,30 +155,38 @@ class QueueWorker {
...
@@ -155,30 +155,38 @@ class QueueWorker {
// Adding generate_sitemap operations for all data sets.
// Adding generate_sitemap operations for all data sets.
foreach
(
$type_definitions
[
$type
][
'urlGenerators'
]
as
$url_generator_id
)
{
foreach
(
$type_definitions
[
$type
][
'urlGenerators'
]
as
$url_generator_id
)
{
foreach
(
$this
->
manager
->
getUrlGenerator
(
$url_generator_id
)
$data_sets
=
$this
->
manager
->
getUrlGenerator
(
$url_generator_id
)
->
setSitemapVariant
(
$variant_name
)
->
setSitemapVariant
(
$variant_name
)
->
getDataSets
()
as
$data_set
)
{
->
getDataSets
();
$data_sets
[]
=
[
if
(
!
empty
(
$data_sets
))
{
'data'
=>
$data_set
,
$sitemap_variants
[
$variant_name
][
'data'
]
=
TRUE
;
'sitemap_variant'
=>
$variant_name
,
foreach
(
$data_sets
as
$data_set
)
{
'url_generator'
=>
$url_generator_id
,
$all_data_sets
[]
=
[
'sitemap_generator'
=>
$type_definitions
[
$type
][
'sitemapGenerator'
],
'data'
=>
$data_set
,
];
'sitemap_variant'
=>
$variant_name
,
'url_generator'
=>
$url_generator_id
,
if
(
count
(
$data_sets
)
===
self
::
REBUILD_QUEUE_CHUNK_ITEM_SIZE
)
{
'sitemap_generator'
=>
$type_definitions
[
$type
][
'sitemapGenerator'
],
$this
->
queueElements
(
$data_sets
);
];
$data_sets
=
[];
if
(
count
(
$all_data_sets
)
===
self
::
REBUILD_QUEUE_CHUNK_ITEM_SIZE
)
{
$this
->
queueElements
(
$all_data_sets
);
$all_data_sets
=
[];
}
}
}
}
}
}
}
}
}
if
(
!
empty
(
$data_sets
))
{
if
(
!
empty
(
$
all_
data_sets
))
{
$this
->
queueElements
(
$data_sets
);
$this
->
queueElements
(
$
all_
data_sets
);
}
}
$this
->
getQueuedElementCount
(
TRUE
);
$this
->
getQueuedElementCount
(
TRUE
);
// todo: May not be clean to remove sitemap variants data when queuing elements.
// Remove all sitemap variant instances where no results have been queued.
$this
->
manager
->
removeSitemap
(
array_keys
(
array_filter
(
$sitemap_variants
,
function
(
$e
)
{
return
empty
(
$e
[
'data'
]);
})));
return
$this
;
return
$this
;
}
}
...
@@ -193,6 +201,7 @@ class QueueWorker {
...
@@ -193,6 +201,7 @@ class QueueWorker {
* @throws \Drupal\Component\Plugin\Exception\PluginException
* @throws \Drupal\Component\Plugin\Exception\PluginException
*
*
* @todo Lock functionality
* @todo Lock functionality
* @todo Does not unpublish sitemaps were variant does not have links anymore.
*/
*/
public
function
generateSitemap
(
$from
=
'form'
)
{
public
function
generateSitemap
(
$from
=
'form'
)
{
...
...
src/Simplesitemap.php
View file @
65a5da69
...
@@ -299,25 +299,9 @@ class Simplesitemap {
...
@@ -299,25 +299,9 @@ class Simplesitemap {
/**
/**
* @return $this
* @return $this
* @throws \Drupal\Component\Plugin\Exception\PluginException
* @throws \Drupal\Component\Plugin\Exception\PluginException
*
* @todo document
*/
*/
public
function
removeSitemap
()
{
public
function
removeSitemap
()
{
$saved_variants
=
$this
->
manager
->
getSitemapVariants
();
$this
->
manager
->
removeSitemap
(
$this
->
getVariants
(
FALSE
));
$this
->
moduleHandler
->
alter
(
'simple_sitemap_variants'
,
$saved_variants
);
$remove_variants
=
NULL
!==
(
$variants
=
$this
->
getVariants
(
FALSE
))
?
array_intersect_key
(
$saved_variants
,
array_flip
((
array
)
$variants
))
:
$saved_variants
;
if
(
!
empty
(
$remove_variants
))
{
$type_definitions
=
$this
->
manager
->
getSitemapTypes
();
$this
->
moduleHandler
->
alter
(
'simple_sitemap_types'
,
$type_definitions
);
foreach
(
$remove_variants
as
$variant_name
=>
$variant_definition
)
{
$this
->
manager
->
getSitemapGenerator
(
$type_definitions
[
$variant_definition
[
'type'
]][
'sitemapGenerator'
])
->
setSitemapVariant
(
$variant_name
)
->
remove
();
}
}
return
$this
;
return
$this
;
}
}
...
@@ -326,6 +310,8 @@ class Simplesitemap {
...
@@ -326,6 +310,8 @@ class Simplesitemap {
* @param string $from
* @param string $from
* @return $this
* @return $this
* @throws \Drupal\Component\Plugin\Exception\PluginException
* @throws \Drupal\Component\Plugin\Exception\PluginException
*
* @todo variants
*/
*/
public
function
generateSitemap
(
$from
=
'form'
)
{
public
function
generateSitemap
(
$from
=
'form'
)
{
switch
(
$from
)
{
switch
(
$from
)
{
...
...
src/SimplesitemapManager.php
View file @
65a5da69
...
@@ -133,7 +133,6 @@ class SimplesitemapManager {
...
@@ -133,7 +133,6 @@ class SimplesitemapManager {
* @param null $sitemap_type
* @param null $sitemap_type
* @return array
* @return array
*
*
* @todo document
* @todo translate label
* @todo translate label
*/
*/
public
function
getSitemapVariants
(
$sitemap_type
=
NULL
,
$attach_type_info
=
TRUE
)
{
public
function
getSitemapVariants
(
$sitemap_type
=
NULL
,
$attach_type_info
=
TRUE
)
{
...
@@ -210,9 +209,29 @@ class SimplesitemapManager {
...
@@ -210,9 +209,29 @@ class SimplesitemapManager {
return
$this
;
return
$this
;
}
}
public
function
removeSitemap
(
$variant_names
=
NULL
)
{
$saved_variants
=
$this
->
getSitemapVariants
();
$remove_variants
=
NULL
!==
$variant_names
&&
!
empty
((
array
)
$variant_names
)
?
array_intersect_key
(
$saved_variants
,
array_flip
((
array
)
$variant_names
))
:
$saved_variants
;
if
(
!
empty
(
$remove_variants
))
{
$type_definitions
=
$this
->
getSitemapTypes
();
foreach
(
$remove_variants
as
$variant_name
=>
$variant_definition
)
{
$this
->
getSitemapGenerator
(
$type_definitions
[
$variant_definition
[
'type'
]][
'sitemapGenerator'
])
->
setSitemapVariant
(
$variant_name
)
->
remove
();
}
}
return
$this
;
}
public
function
removeSitemapVariants
(
$variant_names
=
NULL
)
{
public
function
removeSitemapVariants
(
$variant_names
=
NULL
)
{
if
(
NULL
===
$variant_names
||
!
empty
((
array
)
$variant_names
))
{
if
(
NULL
===
$variant_names
||
!
empty
((
array
)
$variant_names
))
{
SitemapGeneratorBase
::
removeSitemapVariants
(
$variant_names
);
//todo should call the remove() method of every plugin instead?
// Remove sitemap instances.
$this
->
removeSitemap
(
$variant_names
);
if
(
NULL
===
$variant_names
)
{
if
(
NULL
===
$variant_names
)
{
// Remove all variants and their bundle settings.
// Remove all variants and their bundle settings.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment