Completed
Push — master ( 599977...a7d112 )
by Thomas
10:10
created

ConsoleOutput::finishProgress()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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