Commit 54765021 authored by gbyte.co's avatar gbyte.co Committed by gbyte.co

Issue #3001038 by wells, gbyte.co: Division by zero warnings when there are no queue items

parent 0e322424
......@@ -54,18 +54,25 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
];
$queue_worker = $this->generator->getQueueWorker();
$indexed_count = $queue_worker->getProcessedElementCount();
$total_count = $queue_worker->getInitialElementCount();
$index_progress = [
'#theme' => 'progress_bar',
'#percent' => round(100 * $indexed_count / $total_count),
'#message' => t('@indexed out of @total items have been indexed.', ['@indexed' => $indexed_count, '@total' => $total_count]),
];
$form['simple_sitemap_settings']['progress'] = [
'#markup' => render($index_progress),
'#prefix' => '<div class="simple-sitemap-progress clearfix">',
'#suffix' => '</div>',
];
if (!empty($total_count)) {
$indexed_count = $queue_worker->getProcessedElementCount();
$percent = round(100 * $indexed_count / $total_count);
// With all results processed, there still may be some stashed results to be indexed.
$percent = $percent === 100 && $queue_worker->generationInProgress() ? 99 : $percent;
$index_progress = [
'#theme' => 'progress_bar',
'#percent' => $percent,
'#message' => t('@indexed out of @total items have been processed.', ['@indexed' => $indexed_count, '@total' => $total_count]),
];
$form['simple_sitemap_settings']['progress'] = [
'#markup' => render($index_progress),
'#prefix' => '<div class="simple-sitemap-progress clearfix">',
'#suffix' => '</div>',
];
}
$form['simple_sitemap_settings']['settings'] = [
'#type' => 'fieldset',
......
......@@ -69,7 +69,7 @@ trait BatchTrait {
$processed_element_count = $queue_worker->getProcessedElementCount();
$original_element_count = $queue_worker->getInitialElementCount();
$context['message'] = t('@indexed out of @total total items have been indexed.', [
$context['message'] = t('@indexed out of @total total items have been processed.', [
'@indexed' => $processed_element_count, '@total' => $original_element_count]);
$context['finished'] = $processed_element_count / $original_element_count;
}
......
......@@ -321,9 +321,7 @@ class QueueWorker {
public function getInitialElementCount() {
if (NULL === $this->elementsTotal) {
$this->elementsTotal = !empty($original = $this->state->get('simple_sitemap.queue_items_initial_amount'))
? (int) $original
: 0;
$this->elementsTotal = (int) $this->state->get('simple_sitemap.queue_items_initial_amount', 0);
}
return $this->elementsTotal;
......@@ -339,16 +337,15 @@ class QueueWorker {
public function getStashedResultCount() {
return ($this->state->has('simple_sitemap.queue_stashed_results')
&& !empty($results = $this->state->get('simple_sitemap.queue_stashed_results')['results']))
? count($results)
: 0;
? count($this->state->get('simple_sitemap.queue_stashed_results')['results'])
: 0);
}
public function getProcessedElementCount() {
$original = $this->getInitialElementCount();
$initial = $this->getInitialElementCount();
$remaining = $this->getQueuedElementCount();
return $remaining <= $original ? ($original - $remaining) : 0;
return $initial > $remaining ? ($initial - $remaining) : 0;
}
public function generationInProgress() {
......
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