1
0

ConsoleOutput.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. if (!is_null($description)) {
  75. $this->output->write(" $description");
  76. }
  77. }
  78. public function finishProgress() {
  79. if (is_null($this->progressBar)) {
  80. return;
  81. }
  82. $this->progressBar->finish();
  83. }
  84. }