Fixes for errors when with the progress closure

This commit is contained in:
Tim Nagel 2015-03-11 21:31:23 +11:00
commit 0009c858a7
3 changed files with 18 additions and 3 deletions

View file

@ -35,12 +35,18 @@ class ProgressClosureBuilder
$progress = null;
return function ($increment, $totalObjects) use (&$progress, $output, $action, $index, $type) {
return function ($increment, $totalObjects, $message = null) use (&$progress, $output, $action, $index, $type) {
if (null === $progress) {
$progress = new ProgressBar($output, $totalObjects);
$progress->start();
}
if (null !== $message) {
$progress->clear();
$output->writeln(sprintf('<info>%s</info> <error>%s</error>', $action, $message));
$progress->display();
}
$progress->setMessage(sprintf('<info>%s</info> <comment>%s/%s</comment>', $action, $index, $type));
$progress->advance($increment);
};
@ -62,11 +68,15 @@ class ProgressClosureBuilder
$lastStep = null;
$current = 0;
return function ($increment, $totalObjects) use ($output, $action, $index, $type, &$lastStep, &$current) {
return function ($increment, $totalObjects, $message = null) use ($output, $action, $index, $type, &$lastStep, &$current) {
if ($current + $increment > $totalObjects) {
$increment = $totalObjects - $current;
}
if (null !== $message) {
$output->writeln(sprintf('<info>%s</info> <error>%s</error>', $action, $message));
}
$currentTime = microtime(true);
$timeDifference = $currentTime - $lastStep;
$objectsPerSecond = $lastStep ? ($increment / $timeDifference) : $increment;