Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
simple_sitemap
Commits
fe971ab5
Commit
fe971ab5
authored
Aug 28, 2016
by
Pawel G
Browse files
Batch API now calls static method on every iteration which returns a Drupal service
parent
27657785
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/Batch/Batch.php
View file @
fe971ab5
...
...
@@ -43,10 +43,12 @@ class Batch {
switch
(
$this
->
batchInfo
[
'from'
])
{
case
'form'
:
// Start batch process.
batch_set
(
$this
->
batch
);
break
;
case
'drush'
:
// Start drush batch process.
batch_set
(
$this
->
batch
);
$this
->
batch
=&
batch_get
();
$this
->
batch
[
'progressive'
]
=
FALSE
;
...
...
@@ -55,6 +57,7 @@ class Batch {
break
;
case
'backend'
:
// Start backend batch process.
batch_set
(
$this
->
batch
);
$this
->
batch
=&
batch_get
();
$this
->
batch
[
'progressive'
]
=
FALSE
;
...
...
@@ -62,6 +65,9 @@ class Batch {
break
;
case
'nobatch'
:
// Call each batch operation the way the Drupal batch API would do, but
// within one process (so in fact not using batch API here, just
// mimicking it to avoid code duplication.
$context
=
[];
foreach
(
$this
->
batch
[
'operations'
]
as
$i
=>
$operation
)
{
$operation
[
1
][]
=
&
$context
;
...
...
@@ -92,7 +98,8 @@ class Batch {
* @param array &$context
*/
public
static
function
generateBundleUrls
(
$entity_info
,
$batch_info
,
&
$context
)
{
\
Drupal
::
service
(
'simple_sitemap.batch_url_generator'
)
->
generateBundleUrls
(
$entity_info
,
$batch_info
,
$context
);
BatchUrlGenerator
::
service
()
->
generateBundleUrls
(
$entity_info
,
$batch_info
,
$context
);
}
/**
...
...
@@ -103,7 +110,8 @@ class Batch {
* @param array &$context
*/
public
static
function
generateCustomUrls
(
$custom_paths
,
$batch_info
,
&
$context
)
{
\
Drupal
::
service
(
'simple_sitemap.batch_url_generator'
)
->
generateCustomUrls
(
$custom_paths
,
$batch_info
,
$context
);
BatchUrlGenerator
::
service
()
->
generateCustomUrls
(
$custom_paths
,
$batch_info
,
$context
);
}
/**
...
...
@@ -114,6 +122,7 @@ class Batch {
* @param $operations
*/
public
static
function
finishGeneration
(
$success
,
$results
,
$operations
)
{
\
Drupal
::
service
(
'simple_sitemap.batch_url_generator'
)
->
finishGeneration
(
$success
,
$results
,
$operations
);
BatchUrlGenerator
::
service
()
->
finishGeneration
(
$success
,
$results
,
$operations
);
}
}
src/Batch/BatchUrlGenerator.php
View file @
fe971ab5
...
...
@@ -25,6 +25,15 @@ class BatchUrlGenerator {
protected
$entityQuery
;
protected
$anonUser
;
/**
* BatchUrlGenerator constructor.
*
* @param $sitemap_generator
* @param $language_manager
* @param $entity_type_manager
* @param $path_validator
* @param $entity_query
*/
public
function
__construct
(
$sitemap_generator
,
$language_manager
,
...
...
@@ -40,6 +49,22 @@ class BatchUrlGenerator {
$this
->
anonUser
=
$this
->
entityTypeManager
->
getStorage
(
'user'
)
->
load
(
self
::
ANONYMOUS_USER_ID
);
}
/**
* The Drupal batch API can only call procedural functions or static methods.
* To circumvent exclusively procedural code, on every batch iteration this
* static method is called by the batch API and returns a freshly created
* Drupal service object of this class. All following calls can be made on
* the returned service the OOP way. This is is obviously trading performance
* for cleanness. The service is created within its own class to improve
* testability.
*
* @return object
* Symfony service object of this class
*/
public
static
function
service
()
{
return
\
Drupal
::
service
(
'simple_sitemap.batch_url_generator'
);
}
/**
* @param $batch_info
* @return bool
...
...
src/Simplesitemap.php
View file @
fe971ab5
...
...
@@ -351,8 +351,9 @@ class Simplesitemap {
*
* @return string|false
* If no sitemap id provided, either a sitemap index is returned, or the
* whole sitemap, if the amount of links does not exceed the max links setting.
* If a sitemap id is provided, a sitemap chunk is returned.
* whole sitemap, if the amount of links does not exceed the max links
* setting. If a sitemap id is provided, a sitemap chunk is returned. False
* if sitemap is not retrievable from the database.
*/
public
function
getSitemap
(
$chunk_id
=
NULL
)
{
$chunks
=
$this
->
fetchSitemapChunks
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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