ConsoleOutput.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017, ownCloud GmbH
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Migration;
  23. use OCP\Migration\IOutput;
  24. use Symfony\Component\Console\Helper\ProgressBar;
  25. use Symfony\Component\Console\Output\OutputInterface;
  26. /**
  27. * Class SimpleOutput
  28. *
  29. * Just a simple IOutput implementation with writes messages to the log file.
  30. * Alternative implementations will write to the console or to the web ui (web update case)
  31. *
  32. * @package OC\Migration
  33. */
  34. class ConsoleOutput implements IOutput {
  35. /** @var OutputInterface */
  36. private $output;
  37. /** @var ProgressBar */
  38. private $progressBar;
  39. public function __construct(OutputInterface $output) {
  40. $this->output = $output;
  41. }
  42. /**
  43. * @param string $message
  44. */
  45. public function info($message) {
  46. $this->output->writeln("<info>$message</info>");
  47. }
  48. /**
  49. * @param string $message
  50. */
  51. public function warning($message) {
  52. $this->output->writeln("<comment>$message</comment>");
  53. }
  54. /**
  55. * @param int $max
  56. */
  57. public function startProgress($max = 0) {
  58. if (!is_null($this->progressBar)) {
  59. $this->progressBar->finish();
  60. }
  61. $this->progressBar = new ProgressBar($this->output);
  62. $this->progressBar->start($max);
  63. }
  64. /**
  65. * @param int $step
  66. * @param string $description
  67. */
  68. public function advance($step = 1, $description = '') {
  69. if (!is_null($this->progressBar)) {
  70. $this->progressBar = new ProgressBar($this->output);
  71. $this->progressBar->start();
  72. }
  73. $this->progressBar->advance($step);
  74. }
  75. public function finishProgress() {
  76. if (is_null($this->progressBar)) {
  77. return;
  78. }
  79. $this->progressBar->finish();
  80. }
  81. }