Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
simple_sitemap
Commits
612a8c1b
Commit
612a8c1b
authored
Jun 16, 2016
by
Pawel G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only fetch sitemap from database on demand.
parent
b7027db1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
17 deletions
+29
-17
simple_sitemap.module
simple_sitemap.module
+1
-0
src/Simplesitemap.php
src/Simplesitemap.php
+28
-17
No files found.
simple_sitemap.module
View file @
612a8c1b
...
...
@@ -139,3 +139,4 @@ function simple_sitemap_entity_delete(Drupal\Core\Entity\EntityInterface $entity
$sitemap
->
saveConfig
(
'entity_types'
,
$entity_types
);
}
}
src/Simplesitemap.php
View file @
612a8c1b
...
...
@@ -27,8 +27,8 @@ class Simplesitemap {
* The config factory from the container.
*/
function
__construct
(
ConfigFactoryInterface
$config_factory
)
{
$this
->
config
=
$config_factory
->
get
(
'simple_sitemap.settings'
)
;
$this
->
sitemap
=
\
Drupal
::
service
(
'database'
)
->
query
(
"SELECT * FROM
{
simple_sitemap
}
"
)
->
fetchAllAssoc
(
'id
'
);
$this
->
config
_factory
=
$config_factory
;
$this
->
config
=
$this
->
config_factory
->
get
(
'simple_sitemap.settings
'
);
}
/**
...
...
@@ -43,6 +43,12 @@ class Simplesitemap {
return
$this
->
config
->
get
(
$key
);
}
private
function
fetchSitemap
()
{
return
\
Drupal
::
service
(
'database'
)
->
query
(
"SELECT * FROM
{
simple_sitemap
}
"
)
->
fetchAllAssoc
(
'id'
);
}
/**
* Saves a specific sitemap configuration to db.
*
...
...
@@ -52,8 +58,10 @@ class Simplesitemap {
* The configuration to be saved.
*/
public
function
saveConfig
(
$key
,
$value
)
{
\
Drupal
::
service
(
'
config
.
factory
'
)
->
getEditable
(
'simple_sitemap.settings'
)
$this
->
config
_
factory
->
getEditable
(
'simple_sitemap.settings'
)
->
set
(
$key
,
$value
)
->
save
();
// Refresh config object after making changes.
$this
->
config
=
$this
->
config_factory
->
get
(
'simple_sitemap.settings'
);
}
/**
...
...
@@ -202,24 +210,23 @@ class Simplesitemap {
* If a sitemap id is provided, a sitemap chunk is returned.
*/
public
function
getSitemap
(
$sitemap_id
=
NULL
)
{
if
(
is_null
(
$sitemap_id
)
||
!
isset
(
$this
->
sitemap
[
$sitemap_id
]))
{
$sitemap
=
$this
->
fetchSitemap
();
if
(
is_null
(
$sitemap_id
)
||
!
isset
(
$sitemap
[
$sitemap_id
]))
{
// Return sitemap index, if there are multiple sitemap chunks.
if
(
count
(
$
this
->
sitemap
)
>
1
)
{
return
$this
->
getSitemapIndex
();
if
(
count
(
$sitemap
)
>
1
)
{
return
$this
->
getSitemapIndex
(
$sitemap
);
}
// Return sitemap if there is only one chunk.
else
{
if
(
isset
(
$this
->
sitemap
[
1
]))
{
return
$this
->
sitemap
[
1
]
->
sitemap_string
;
else
{
// Return sitemap if there is only one chunk.
if
(
isset
(
$sitemap
[
1
]))
{
return
$sitemap
[
1
]
->
sitemap_string
;
}
return
FALSE
;
}
}
// Return specific sitemap chunk.
else
{
return
$this
->
sitemap
[
$sitemap_id
]
->
sitemap_string
;
else
{
// Return specific sitemap chunk.
return
$sitemap
[
$sitemap_id
]
->
sitemap_string
;
}
}
...
...
@@ -240,12 +247,15 @@ class Simplesitemap {
/**
* Generates and returns the sitemap index as string.
*
* @param array $sitemap
* Sitemap chunks which to generate the index from.
*
* @return string
* The sitemap index.
*/
private
function
getSitemapIndex
()
{
private
function
getSitemapIndex
(
$sitemap
)
{
$generator
=
new
SitemapGenerator
();
return
$generator
->
generateSitemapIndex
(
$
this
->
sitemap
);
return
$generator
->
generateSitemapIndex
(
$sitemap
);
}
/**
...
...
@@ -283,9 +293,10 @@ class Simplesitemap {
* Formatted timestamp of last sitemap generation, otherwise FALSE.
*/
public
function
getGeneratedAgo
()
{
if
(
isset
(
$this
->
sitemap
[
1
]
->
sitemap_created
))
{
$sitemap
=
$this
->
fetchSitemap
();
if
(
isset
(
$sitemap
[
1
]
->
sitemap_created
))
{
return
\
Drupal
::
service
(
'date.formatter'
)
->
formatInterval
(
REQUEST_TIME
-
$
this
->
sitemap
[
1
]
->
sitemap_created
);
->
formatInterval
(
REQUEST_TIME
-
$sitemap
[
1
]
->
sitemap_created
);
}
return
FALSE
;
}
...
...
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