2015-07-30 10:57:16 +02:00
|
|
|
<?php
|
2025-04-27 14:38:18 +02:00
|
|
|
|
2015-07-30 10:57:16 +02:00
|
|
|
/**
|
2024-05-23 09:26:56 +02:00
|
|
|
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2015 ownCloud GmbH
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-07-30 10:57:16 +02:00
|
|
|
*/
|
|
|
|
namespace OC\Migration;
|
|
|
|
|
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
use Symfony\Component\Console\Helper\ProgressBar;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class SimpleOutput
|
|
|
|
*
|
|
|
|
* Just a simple IOutput implementation with writes messages to the log file.
|
|
|
|
* Alternative implementations will write to the console or to the web ui (web update case)
|
|
|
|
*
|
|
|
|
* @package OC\Migration
|
|
|
|
*/
|
|
|
|
class ConsoleOutput implements IOutput {
|
2023-07-02 23:53:30 +03:30
|
|
|
private ?ProgressBar $progressBar = null;
|
2015-07-30 10:57:16 +02:00
|
|
|
|
2023-07-02 23:53:30 +03:30
|
|
|
public function __construct(
|
|
|
|
private OutputInterface $output,
|
|
|
|
) {
|
2015-07-30 10:57:16 +02:00
|
|
|
}
|
|
|
|
|
2023-10-31 12:06:09 +01:00
|
|
|
public function debug(string $message): void {
|
|
|
|
$this->output->writeln($message, OutputInterface::VERBOSITY_VERBOSE);
|
|
|
|
}
|
|
|
|
|
2015-07-30 10:57:16 +02:00
|
|
|
/**
|
|
|
|
* @param string $message
|
|
|
|
*/
|
2023-07-02 23:53:30 +03:30
|
|
|
public function info($message): void {
|
2015-07-30 10:57:16 +02:00
|
|
|
$this->output->writeln("<info>$message</info>");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $message
|
|
|
|
*/
|
2023-07-02 23:53:30 +03:30
|
|
|
public function warning($message): void {
|
2015-07-30 10:57:16 +02:00
|
|
|
$this->output->writeln("<comment>$message</comment>");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $max
|
|
|
|
*/
|
2023-07-02 23:53:30 +03:30
|
|
|
public function startProgress($max = 0): void {
|
2015-07-30 10:57:16 +02:00
|
|
|
if (!is_null($this->progressBar)) {
|
|
|
|
$this->progressBar->finish();
|
|
|
|
}
|
|
|
|
$this->progressBar = new ProgressBar($this->output);
|
|
|
|
$this->progressBar->start($max);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $step
|
|
|
|
* @param string $description
|
|
|
|
*/
|
2023-07-02 23:53:30 +03:30
|
|
|
public function advance($step = 1, $description = ''): void {
|
2023-01-03 16:32:44 +01:00
|
|
|
if (is_null($this->progressBar)) {
|
2015-07-30 10:57:16 +02:00
|
|
|
$this->progressBar = new ProgressBar($this->output);
|
|
|
|
$this->progressBar->start();
|
|
|
|
}
|
|
|
|
$this->progressBar->advance($step);
|
2023-01-03 16:32:44 +01:00
|
|
|
if (!is_null($description)) {
|
|
|
|
$this->output->write(" $description");
|
|
|
|
}
|
2015-07-30 10:57:16 +02:00
|
|
|
}
|
|
|
|
|
2023-07-02 23:53:30 +03:30
|
|
|
public function finishProgress(): void {
|
2015-07-30 10:57:16 +02:00
|
|
|
if (is_null($this->progressBar)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->progressBar->finish();
|
|
|
|
}
|
|
|
|
}
|