Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
X
xmlsitemap
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
xmlsitemap
Commits
6a579bd2
Commit
6a579bd2
authored
May 25, 2014
by
andrei.dincu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2249723
by andrei.dincu: xmlsitemap-regenerate drush command 90% works
parent
d05275ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
40 deletions
+20
-40
xmlsitemap.generate.inc
xmlsitemap.generate.inc
+13
-18
xmlsitemap.module
xmlsitemap.module
+7
-22
No files found.
xmlsitemap.generate.inc
View file @
6a579bd2
...
...
@@ -6,7 +6,6 @@
*
* @ingroup xmlsitemap
*/
use
Drupal\Core\Language\LanguageInterface
;
use
Drupal\xmlsitemap\XmlSitemapInterface
;
use
Drupal\xmlsitemap\Entity\XmlSitemap
;
...
...
@@ -56,9 +55,8 @@ function _xmlsitemap_regenerate_before() {
if
(
\
Drupal
::
config
(
'xmlsitemap.settings'
)
->
get
(
'developer_mode'
))
{
watchdog
(
'xmlsitemap'
,
'Starting XML sitemap generation. Memory usage: @memory-peak.'
,
array
(
'@memory-peak'
=>
format_size
(
memory_get_peak_usage
(
TRUE
)),
),
WATCHDOG_DEBUG
'@memory-peak'
=>
format_size
(
memory_get_peak_usage
(
TRUE
)),
),
WATCHDOG_DEBUG
);
}
}
...
...
@@ -140,7 +138,7 @@ function xmlsitemap_generate_page(XmlSitemapInterface $sitemap, $page) {
return
$writer
->
getSitemapElementCount
();
}
function
xmlsitemap_generate_chunk
(
stdClass
$sitemap
,
XMLSitemapWriter
$writer
,
$chunk
)
{
function
xmlsitemap_generate_chunk
(
XmlSitemapInterface
$sitemap
,
XMLSitemapWriter
$writer
,
$chunk
)
{
$lastmod_format
=
\
Drupal
::
config
(
'xmlsitemap.settings'
)
->
get
(
'lastmod_format'
);
$url_options
=
$sitemap
->
uri
[
'options'
];
...
...
@@ -256,7 +254,7 @@ function xmlsitemap_regenerate_batch(array $smids = array()) {
$smids
[]
=
$sitemap
->
id
();
}
}
$t
=
't'
;
$batch
=
array
(
'operations'
=>
array
(),
...
...
@@ -289,7 +287,8 @@ function xmlsitemap_regenerate_batch(array $smids = array()) {
*/
function
xmlsitemap_regenerate_batch_generate
(
$smid
,
array
&
$context
)
{
if
(
!
isset
(
$context
[
'sandbox'
][
'sitemap'
]))
{
$sitemap
=
\
Drupal
::
entityManager
()
->
getStorage
(
'xmlsitemap'
)
->
load
(
$smid
);
//$sitemap = \Drupal::entityManager()->getStorage('xmlsitemap')->load($smid);
$sitemap
=
xmlsitemap_sitemap_load
(
$smid
);
$context
[
'sandbox'
][
'sitemap'
]
=
$sitemap
;
$context
[
'sandbox'
][
'sitemap'
]
->
setChunks
(
1
);
$context
[
'sandbox'
][
'sitemap'
]
->
setLinks
(
0
);
...
...
@@ -299,7 +298,6 @@ function xmlsitemap_regenerate_batch_generate($smid, array &$context) {
xmlsitemap_check_directory
(
$context
[
'sandbox'
][
'sitemap'
]);
xmlsitemap_clear_directory
(
$context
[
'sandbox'
][
'sitemap'
]);
}
$sitemap
=
&
$context
[
'sandbox'
][
'sitemap'
];
$links
=
xmlsitemap_generate_page
(
$sitemap
,
$sitemap
->
getChunks
());
//$context['message'] = t('Now generating %sitemap-url.', array('%sitemap-url' => url('sitemap.xml', $sitemap->uri['options'] + array('query' => array('page' => $sitemap->getChunks())))));
...
...
@@ -333,9 +331,9 @@ function xmlsitemap_regenerate_batch_generate($smid, array &$context) {
*/
function
xmlsitemap_regenerate_batch_generate_index
(
$smid
,
array
&
$context
)
{
$sitemap
=
xmlsitemap_sitemap_load
(
$smid
);
if
(
$sitemap
->
getChunks
()
>
1
)
{
if
(
$sitemap
!=
NULL
&&
$sitemap
->
getChunks
()
>
1
)
{
xmlsitemap_generate_index
(
$sitemap
);
//
$context['message'] = t('Now generating sitemap index %sitemap-url.', array('%sitemap-url' => url('sitemap.xml', $sitemap->uri['options'])));
$context
[
'message'
]
=
t
(
'Now generating sitemap index %sitemap-url.'
,
array
(
'%sitemap-url'
=>
url
(
'sitemap.xml'
,
$sitemap
->
uri
[
'options'
])));
}
}
...
...
@@ -347,13 +345,10 @@ function xmlsitemap_regenerate_batch_finished($success, $results, $operations, $
\
Drupal
::
config
(
'xmlsitemap.settings'
)
->
set
(
'generated_last'
,
REQUEST_TIME
);
drupal_set_message
(
t
(
'The sitemaps were regenerated.'
));
// Show a watchdog message that the sitemap was regenerated.
watchdog
(
'xmlsitemap'
,
'Finished XML sitemap generation in @elapsed. Memory usage: @memory-peak.'
,
array
(
'@elapsed'
=>
$elapsed
,
'@memory-peak'
=>
format_size
(
memory_get_peak_usage
(
TRUE
)),
),
WATCHDOG_NOTICE
watchdog
(
'xmlsitemap'
,
'Finished XML sitemap generation in @elapsed. Memory usage: @memory-peak.'
,
array
(
'@elapsed'
=>
$elapsed
,
'@memory-peak'
=>
format_size
(
memory_get_peak_usage
(
TRUE
)),
),
WATCHDOG_NOTICE
);
}
else
{
...
...
@@ -399,7 +394,7 @@ function xmlsitemap_rebuild_batch(array $entities, $save_custom = FALSE) {
*/
function
xmlsitemap_batch_variable_set
(
array
$variables
)
{
foreach
(
$variables
as
$variable
=>
$value
)
{
\
Drupal
::
config
(
'xmlsitemap.settings'
)
->
set
(
$variable
,
$value
);
\
Drupal
::
config
(
'xmlsitemap.settings'
)
->
set
(
$variable
,
$value
);
}
}
...
...
xmlsitemap.module
View file @
6a579bd2
...
...
@@ -371,7 +371,6 @@ function xmlsitemap_sitemap_load_multiple($smids = array(), array $conditions =
}
$sitemaps = $query->execute()->fetchAllAssoc('smid');
*/
$sitemaps
=
array
();
foreach
(
$sitemaps
as
$sitemap
)
{
$sitemaps
[
$sitemap
->
id
()]
->
setContext
(
unserialize
(
$sitemap
->
getContext
()));
$sitemaps
[
$sitemap
->
id
()]
->
uri
=
xmlsitemap_sitemap_uri
(
$sitemap
);
...
...
@@ -408,14 +407,15 @@ function xmlsitemap_sitemap_load_by_context(array $context = NULL) {
* @todo Save the sitemap's URL as a column?
*/
function
xmlsitemap_sitemap_save
(
XmlSitemapInterface
$sitemap
)
{
if
(
!
isset
(
$sitemap
->
getContext
()))
{
$context
=
$sitemap
->
getContext
();
if
(
!
isset
(
$context
)
||
!
$context
)
{
$sitemap
->
setContext
(
array
());
}
// Make sure context is sorted before saving the hash.
//$sitemap->is_new = empty($sitemap->getId());
//$sitemap->old_smid = $sitemap->is_new ? NULL : $sitemap->smid;
$sitemap
->
setOriginalId
(
$sitemap
->
isNew
()
?
NULL
:
$sitemap
->
getId
());
$sitemap
->
setOriginalId
(
$sitemap
->
isNew
()
?
NULL
:
$sitemap
->
getId
());
//$sitemap->smid = xmlsitemap_sitemap_get_context_hash($sitemap->context);
$sitemap
->
setId
(
xmlsitemap_sitemap_get_context_hash
(
$sitemap
->
getContext
()));
// If the context was changed, we need to perform additional actions.
...
...
@@ -426,25 +426,10 @@ function xmlsitemap_sitemap_save(XmlSitemapInterface $sitemap) {
$new_dir
=
xmlsitemap_get_directory
(
$sitemap
);
xmlsitemap_directory_move
(
$old_dir
,
$new_dir
);
// Change the smid field so drupal_write_record() does not fail.
/*db_update('xmlsitemap_sitemap')
->fields(array('smid' => $sitemap->smid))
->condition('smid', $sitemap->old_smid)
->execute();
*/
// Mark the sitemaps as needing regeneration.
\
Drupal
::
config
(
'xmlsitemap.settings'
)
->
set
(
'regenerate_needed'
,
TRUE
);
}
$sitemap
->
save
();
/*
if ($sitemap->is_new) {
drupal_write_record('xmlsitemap_sitemap', $sitemap);
module_invoke_all('xmlsitemap_sitemap_insert', $sitemap);
}
else {
drupal_write_record('xmlsitemap_sitemap', $sitemap, array('smid'));
module_invoke_all('xmlsitemap_sitemap_update', $sitemap);
}*/
return
$sitemap
;
}
...
...
@@ -499,13 +484,13 @@ function xmlsitemap_sitemap_get_file(stdClass $sitemap, $chunk = 'index') {
* @param $sitemap
* The XML sitemap array.
*/
function
xmlsitemap_sitemap_get_max_filesize
(
stdClass
$sitemap
)
{
function
xmlsitemap_sitemap_get_max_filesize
(
XmlSitemapInterface
$sitemap
)
{
$dir
=
xmlsitemap_get_directory
(
$sitemap
);
$sitemap
->
max_filesize
=
0
;
$sitemap
->
setMaxFileSize
(
0
)
;
foreach
(
file_scan_directory
(
$dir
,
'/\.xml$/'
)
as
$file
)
{
$sitemap
->
max_filesize
=
max
(
$sitemap
->
max_filesize
,
filesize
(
$file
->
uri
));
$sitemap
->
setMaxFileSize
(
max
(
$sitemap
->
getMaxFileSize
(),
filesize
(
$file
->
uri
)
));
}
return
$sitemap
->
max_filesize
;
return
$sitemap
->
getMaxFileSize
()
;
}
function
xmlsitemap_sitemap_get_context_hash
(
array
&
$context
)
{
...
...
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