Skip to content

Commit

Permalink
Merge pull request #14 from stephane-monnot/fix-uncomplete-progress
Browse files Browse the repository at this point in the history
Fix uncomplete progress when param `every` is greater than 1
  • Loading branch information
imTigger authored Feb 22, 2018
2 parents 80a9025 + 9bf267e commit ec6dc13
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/Trackable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ trait Trackable
/** @var int $statusId */
protected $statusId;
protected $progressNow = 0;
protected $progressMax = 0;

protected function setProgressMax($value)
{
$this->update(['progress_max' => $value]);
$this->progressMax = $value;
}

protected function setProgressNow($value, $every = 1)
{
if ($value % $every == 0) {
if ($value % $every == 0 || $value == $this->progressMax) {
$this->update(['progress_now' => $value]);
}
$this->progressNow = $value;
}

protected function incrementProgress($offset = 1, $every = 1)
{
$value = $this->progressNow + $offset;
Expand Down Expand Up @@ -50,17 +52,17 @@ protected function update(array $data)
return null;
}

protected function prepareStatus(array $data = [])
{
/** @var JobStatus $entityClass */
$entityClass = app()->getAlias(JobStatus::class);
protected function prepareStatus(array $data = [])
{
/** @var JobStatus $entityClass */
$entityClass = app()->getAlias(JobStatus::class);

$data = array_merge(["type" => static::class], $data);
/** @var JobStatus $status */
$status = $entityClass::create($data);
$data = array_merge(["type" => static::class], $data);
/** @var JobStatus $status */
$status = $entityClass::create($data);

$this->statusId = $status->id;
}
$this->statusId = $status->id;
}

public function getJobStatusId()
{
Expand Down

0 comments on commit ec6dc13

Please sign in to comment.