Commit 5b5ba5bc authored by gbyte.co's avatar gbyte.co

Clean up BatchUrlGenerator class

parent fe971ab5
......@@ -120,31 +120,14 @@ class BatchUrlGenerator {
$context['sandbox']['current_id'] = $id;
}
/**
* @param $context
*/
protected function setProgressInfo(&$context) {
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
// Providing progress info to the batch API.
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
// Adding processing message after finishing every batch segment.
end($context['results']['generate']);
$last_key = key($context['results']['generate']);
if (!empty($context['results']['generate'][$last_key]['path'])) {
$context['message'] = t("Processing path @current out of @max: @path", [
'@current' => $context['sandbox']['progress'],
'@max' => $context['sandbox']['max'],
'@path' => HTML::escape($context['results']['generate'][$last_key]['path']),
]);
}
}
}
/**
* @param $context
* @param $batch_info
*/
protected function processSegment(&$context, $batch_info) {
if ($this->isBatch($batch_info)) {
$this->setProgressInfo($context);
}
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) {
......@@ -159,6 +142,26 @@ class BatchUrlGenerator {
}
}
/**
* @param $context
*/
protected function setProgressInfo(&$context) {
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
// Providing progress info to the batch API.
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
// Adding processing message after finishing every batch segment.
end($context['results']['generate']);
$last_key = key($context['results']['generate']);
if (!empty($context['results']['generate'][$last_key]['path'])) {
$context['message'] = t("Processing path @current out of @max: @path", [
'@current' => $context['sandbox']['progress'],
'@max' => $context['sandbox']['max'],
'@path' => HTML::escape($context['results']['generate'][$last_key]['path']),
]);
}
}
}
/**
* Logs and displays an error.
*
......@@ -272,9 +275,6 @@ class BatchUrlGenerator {
}
}
}
if ($this->isBatch($batch_info)) {
$this->setProgressInfo($context);
}
$this->processSegment($context, $batch_info);
}
......@@ -338,9 +338,6 @@ class BatchUrlGenerator {
$context['results']['generate'][] = $path_data + ['langcode' => $langcode, 'url' => $url, 'alternate_urls' => $alternate_urls];
}
}
if ($this->isBatch($batch_info)) {
$this->setProgressInfo($context);
}
$this->processSegment($context, $batch_info);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment