1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Circles - Bring cloud-users closer together. |
8
|
|
|
* |
9
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
10
|
|
|
* later. See the COPYING file. |
11
|
|
|
* |
12
|
|
|
* @author Maxence Lange <[email protected]> |
13
|
|
|
* @copyright 2021 |
14
|
|
|
* @license GNU AGPL version 3 or any later version |
15
|
|
|
* |
16
|
|
|
* This program is free software: you can redistribute it and/or modify |
17
|
|
|
* it under the terms of the GNU Affero General Public License as |
18
|
|
|
* published by the Free Software Foundation, either version 3 of the |
19
|
|
|
* License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU Affero General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU Affero General Public License |
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
namespace OCA\Circles\Service; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Logger; |
36
|
|
|
use ArtificialOwl\MySmallPhpTools\Traits\TStringTools; |
37
|
|
|
use OCP\Migration\IOutput; |
38
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Class OutputService |
43
|
|
|
* |
44
|
|
|
* @package OCA\Circles\Service |
45
|
|
|
*/ |
46
|
|
|
class OutputService { |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
use TStringTools; |
50
|
|
|
use TNC22Logger; |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** @var IOutput */ |
54
|
|
|
private $migrationOutput; |
55
|
|
|
|
56
|
|
|
/** @var OutputInterface */ |
57
|
|
|
private $occOutput; |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
public function __construct() { |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param OutputInterface $output |
66
|
|
|
*/ |
67
|
|
|
public function setOccOutput(OutputInterface $output): void { |
68
|
|
|
$this->occOutput = $output; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param IOutput $output |
73
|
|
|
*/ |
74
|
|
|
public function setMigrationOutput(IOutput $output): void { |
75
|
|
|
$this->migrationOutput = $output; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $message |
81
|
|
|
* @param bool $advance |
82
|
|
|
*/ |
83
|
|
|
public function output(string $message, bool $advance = false): void { |
84
|
|
|
if (!is_null($this->occOutput)) { |
85
|
|
|
$this->occOutput->writeln((($advance) ? '+' : '-') . ' ' . $message); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (!is_null($this->migrationOutput)) { |
89
|
|
|
if ($advance) { |
90
|
|
|
$this->migrationOutput->advance(1, '(Circles) ' . $message); |
91
|
|
|
} else { |
92
|
|
|
$this->migrationOutput->info('(Circles) ' . $message); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param int $int |
100
|
|
|
*/ |
101
|
|
|
public function startMigrationProgress(int $int): void { |
102
|
|
|
if (is_null($this->migrationOutput)) { |
103
|
|
|
return; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$this->migrationOutput->startProgress($int); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* |
112
|
|
|
*/ |
113
|
|
|
public function finishMigrationProgress(): void { |
114
|
|
|
if (is_null($this->migrationOutput)) { |
115
|
|
|
return; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
$this->migrationOutput->finishProgress(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|