Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
simple_sitemap
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Drupal.org issue queue
Drupal.org issue queue
Security & Compliance
Security & Compliance
Dependency List
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
project
simple_sitemap
Commits
a43ebe5c
Commit
a43ebe5c
authored
May 18, 2016
by
gbyte.co
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Postpone sitemap deletion to shortly before generation of first chunk
parent
f1998727
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
23 deletions
+29
-23
simple_sitemap.module
simple_sitemap.module
+1
-1
src/Batch.php
src/Batch.php
+24
-20
src/Form/SimplesitemapSettingsForm.php
src/Form/SimplesitemapSettingsForm.php
+0
-1
src/Simplesitemap.php
src/Simplesitemap.php
+0
-1
src/SitemapGenerator.php
src/SitemapGenerator.php
+4
-0
No files found.
simple_sitemap.module
View file @
a43ebe5c
...
...
@@ -66,8 +66,8 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
);
// Attach some js magic to forms.
// Only attach fieldset summary js to 'additional settings' vertical tabs.
$form
[
'simple_sitemap'
][
'#attached'
][
'library'
][]
=
'simple_sitemap/form'
;
// Only attach fieldset summary js to 'additional settings' vertical tabs.
if
(
isset
(
$form
[
'additional_settings'
]))
{
$form
[
'simple_sitemap'
][
'#attached'
][
'library'
][]
=
'simple_sitemap/fieldsetSummaries'
;
}
...
...
src/Batch.php
View file @
a43ebe5c
...
...
@@ -74,17 +74,6 @@ class Batch {
$operation
[
1
][]
=
&
$context
;
call_user_func_array
(
$operation
[
0
],
$operation
[
1
]);
}
$links
=
!
empty
(
$context
[
'results'
][
'generate'
])
?
$context
[
'results'
][
'generate'
]
:
array
();
if
(
!
empty
(
$links
))
{
$chunks
=
array_chunk
(
$links
,
$this
->
batchInfo
[
'max_links'
]);
foreach
(
$chunks
as
$i
=>
$chunk_links
)
{
SitemapGenerator
::
generateSitemap
(
$chunk_links
);
}
}
else
{
SitemapGenerator
::
generateSitemap
(
$links
);
}
self
::
finishGeneration
();
break
;
}
}
...
...
@@ -121,7 +110,7 @@ class Batch {
*/
public
static
function
finishBatch
(
$success
,
$results
,
$operations
)
{
if
(
$success
)
{
if
(
!
empty
(
$results
)
||
is_null
(
db_query
(
'SELECT MAX(id) FROM {simple_sitemap}'
)
->
fetchField
()))
{
if
(
!
empty
(
$results
[
'generate'
]
)
||
is_null
(
db_query
(
'SELECT MAX(id) FROM {simple_sitemap}'
)
->
fetchField
()))
{
SitemapGenerator
::
generateSitemap
(
$results
[
'generate'
]);
}
self
::
finishGeneration
();
...
...
@@ -234,8 +223,8 @@ class Batch {
}
if
(
self
::
isBatch
(
$batch_info
))
{
self
::
setProgressInfo
(
$context
);
self
::
processSegment
(
$context
,
$batch_info
);
}
self
::
processSegment
(
$context
,
$batch_info
);
}
/**
...
...
@@ -297,8 +286,8 @@ class Batch {
}
if
(
self
::
isBatch
(
$batch_info
))
{
self
::
setProgressInfo
(
$context
);
self
::
processSegment
(
$context
,
$batch_info
);
}
self
::
processSegment
(
$context
,
$batch_info
);
}
private
static
function
pathProcessed
(
$path
,
&
$context
)
{
//todo: test functionality
...
...
@@ -368,6 +357,7 @@ class Batch {
private
static
function
SetCurrentId
(
$id
,
&
$context
)
{
$context
[
'sandbox'
][
'progress'
]
++
;
$context
[
'sandbox'
][
'current_id'
]
=
$id
;
$context
[
'results'
][
'progress'
]
=
!
isset
(
$context
[
'results'
][
'progress'
])
?
1
:
$context
[
'results'
][
'progress'
]
+
1
;
}
private
static
function
setProgressInfo
(
&
$context
)
{
...
...
@@ -388,6 +378,11 @@ class Batch {
}
private
static
function
processSegment
(
&
$context
,
$batch_info
)
{
if
(
!
self
::
isBatch
(
$batch_info
)
||
$context
[
'results'
][
'progress'
]
==
1
)
{
SitemapGenerator
::
removeSitemap
();
}
if
(
self
::
isBatch
(
$batch_info
))
{
if
(
!
empty
(
$batch_info
[
'max_links'
])
&&
count
(
$context
[
'results'
][
'generate'
])
>=
$batch_info
[
'max_links'
])
{
$chunks
=
array_chunk
(
$context
[
'results'
][
'generate'
],
$batch_info
[
'max_links'
]);
foreach
(
$chunks
as
$i
=>
$chunk_links
)
{
...
...
@@ -398,6 +393,15 @@ class Batch {
}
}
}
else
{
$links
=
!
empty
(
$context
[
'results'
][
'generate'
])
?
$context
[
'results'
][
'generate'
]
:
array
();
$chunks
=
!
empty
(
$links
)
?
array_chunk
(
$links
,
$batch_info
[
'max_links'
])
:
array
(
$links
);
foreach
(
$chunks
as
$i
=>
$chunk_links
)
{
SitemapGenerator
::
generateSitemap
(
$chunk_links
);
}
self
::
finishGeneration
();
}
}
/**
* Logs and displays an error.
...
...
src/Form/SimplesitemapSettingsForm.php
View file @
a43ebe5c
...
...
@@ -128,6 +128,5 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
public
function
generateSitemap
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$sitemap
=
\Drupal
::
service
(
'simple_sitemap.generator'
);
$sitemap
->
generateSitemap
();
// $sitemap->generateSitemap('nobatch');
}
}
src/Simplesitemap.php
View file @
a43ebe5c
...
...
@@ -95,7 +95,6 @@ class Simplesitemap {
* is to be run.
*/
public
function
generateSitemap
(
$from
=
'form'
)
{
db_truncate
(
'simple_sitemap'
)
->
execute
();
$generator
=
new
SitemapGenerator
(
$from
);
$generator
->
setCustomLinks
(
$this
->
getConfig
(
'custom'
));
$generator
->
setEntityTypes
(
$this
->
getConfig
(
'entity_types'
));
...
...
src/SitemapGenerator.php
View file @
a43ebe5c
...
...
@@ -109,6 +109,10 @@ class SitemapGenerator {
db_insert
(
'simple_sitemap'
)
->
fields
(
$values
)
->
execute
();
}
public
static
function
removeSitemap
()
{
db_truncate
(
'simple_sitemap'
)
->
execute
();
}
/**
* Generates and returns the sitemap index for all sitemap chunks.
*
...
...
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