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
3
Merge Requests
3
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
439cbcaa
Commit
439cbcaa
authored
Sep 26, 2016
by
Pawel G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2798863
by guile2912: Error if custom link is not an entity
parent
2cd4f16c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
6 deletions
+86
-6
src/Batch/BatchUrlGenerator.php
src/Batch/BatchUrlGenerator.php
+86
-6
No files found.
src/Batch/BatchUrlGenerator.php
View file @
439cbcaa
...
...
@@ -310,12 +310,7 @@ class BatchUrlGenerator {
continue
;
}
// Load entity object if this is an entity route.
$route_parameters
=
$url_object
->
getRouteParameters
();
$entity
=
!
empty
(
$route_parameters
)
?
$this
->
entityTypeManager
->
getStorage
(
key
(
$route_parameters
))
->
load
(
$route_parameters
[
key
(
$route_parameters
)])
:
NULL
;
$entity
=
$this
->
getEntityFromUrlObject
(
$url_object
);
$path_data
=
[
'path'
=>
$path
,
...
...
@@ -365,6 +360,91 @@ class BatchUrlGenerator {
}
}
/**
* @return bool
*/
protected
function
needsInitialization
()
{
return
empty
(
$this
->
context
[
'sandbox'
]);
}
/**
* @param $max
*/
protected
function
initializeBatch
(
$max
)
{
$this
->
context
[
'results'
][
'generate'
]
=
!
empty
(
$this
->
context
[
'results'
][
'generate'
])
?
$this
->
context
[
'results'
][
'generate'
]
:
[];
if
(
$this
->
isBatch
())
{
$this
->
context
[
'sandbox'
][
'progress'
]
=
0
;
$this
->
context
[
'sandbox'
][
'current_id'
]
=
0
;
$this
->
context
[
'sandbox'
][
'max'
]
=
$max
;
$this
->
context
[
'results'
][
'processed_paths'
]
=
!
empty
(
$this
->
context
[
'results'
][
'processed_paths'
])
?
$this
->
context
[
'results'
][
'processed_paths'
]
:
[];
}
}
/**
* @param $id
*/
protected
function
setCurrentId
(
$id
)
{
if
(
$this
->
isBatch
())
{
$this
->
context
[
'sandbox'
][
'progress'
]
++
;
$this
->
context
[
'sandbox'
][
'current_id'
]
=
$id
;
}
}
/**
*
*/
protected
function
processSegment
()
{
if
(
$this
->
isBatch
())
{
$this
->
setProgressInfo
();
}
if
(
!
empty
(
$this
->
batchInfo
[
'max_links'
])
&&
count
(
$this
->
context
[
'results'
][
'generate'
])
>=
$this
->
batchInfo
[
'max_links'
])
{
$chunks
=
array_chunk
(
$this
->
context
[
'results'
][
'generate'
],
$this
->
batchInfo
[
'max_links'
]);
foreach
(
$chunks
as
$i
=>
$chunk_links
)
{
if
(
count
(
$chunk_links
)
==
$this
->
batchInfo
[
'max_links'
])
{
$remove_sitemap
=
empty
(
$this
->
context
[
'results'
][
'chunk_count'
]);
$this
->
sitemapGenerator
->
generateSitemap
(
$chunk_links
,
$remove_sitemap
);
$this
->
context
[
'results'
][
'chunk_count'
]
=
!
isset
(
$this
->
context
[
'results'
][
'chunk_count'
])
?
1
:
$this
->
context
[
'results'
][
'chunk_count'
]
+
1
;
$this
->
context
[
'results'
][
'generate'
]
=
array_slice
(
$this
->
context
[
'results'
][
'generate'
],
count
(
$chunk_links
));
}
}
}
}
/**
*
*/
protected
function
setProgressInfo
()
{
if
(
$this
->
context
[
'sandbox'
][
'progress'
]
!=
$this
->
context
[
'sandbox'
][
'max'
])
{
// Providing progress info to the batch API.
$this
->
context
[
'finished'
]
=
$this
->
context
[
'sandbox'
][
'progress'
]
/
$this
->
context
[
'sandbox'
][
'max'
];
// Adding processing message after finishing every batch segment.
end
(
$this
->
context
[
'results'
][
'generate'
]);
$last_key
=
key
(
$this
->
context
[
'results'
][
'generate'
]);
if
(
!
empty
(
$this
->
context
[
'results'
][
'generate'
][
$last_key
][
'path'
]))
{
$this
->
context
[
'message'
]
=
$this
->
t
(
self
::
PROCESSING_PATH_MESSAGE
,
[
'@current'
=>
$this
->
context
[
'sandbox'
][
'progress'
],
'@max'
=>
$this
->
context
[
'sandbox'
][
'max'
],
'@path'
=>
HTML
::
escape
(
$this
->
context
[
'results'
][
'generate'
][
$last_key
][
'path'
]),
]);
}
}
}
/**
* @param $url_object
* @return object|null
*/
private
function
getEntityFromUrlObject
(
$url_object
)
{
$route_parameters
=
$url_object
->
getRouteParameters
();
return
!
empty
(
$route_parameters
)
&&
$this
->
entityTypeManager
->
getDefinition
(
$entity_type_id
=
key
(
$route_parameters
),
FALSE
)
?
$this
->
entityTypeManager
->
getStorage
(
$entity_type_id
)
->
load
(
$route_parameters
[
$entity_type_id
])
:
NULL
;
}
/**
* Callback function called by the batch API when all operations are finished.
*
...
...
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