You are here

public function FeedsState::progress in Feeds 8.2

Safely report progress.

When $total == $progress, the state of the task tracked by this state is regarded to be complete.

Handles the following cases gracefully:

  • $total is 0
  • $progress is larger than $total
  • $progress approximates $total so that $finished rounds to 1.0

Parameters

$total: A natural number that is the total to be worked off.

$progress: A natural number that is the progress made on $total.

File

lib/Drupal/feeds/FeedsState.php, line 60

Class

FeedsState
Status of an import or clearing operation on a source.

Namespace

Drupal\feeds

Code

public function progress($total, $progress) {
  if ($progress > $total) {
    $this->progress = FEEDS_BATCH_COMPLETE;
  }
  elseif ($total) {
    $this->progress = $progress / $total;
    if ($this->progress == FEEDS_BATCH_COMPLETE && $total != $progress) {
      $this->progress = 0.99;
    }
  }
  else {
    $this->progress = FEEDS_BATCH_COMPLETE;
  }
}