|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees: online genealogy |
|
5
|
|
|
* Copyright (C) 2023 webtrees development team |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* You should have received a copy of the GNU General Public License |
|
15
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
declare(strict_types=1); |
|
19
|
|
|
|
|
20
|
|
|
namespace Fisharebest\Webtrees\Cli; |
|
21
|
|
|
|
|
22
|
|
|
use Fisharebest\Webtrees\DB; |
|
23
|
|
|
use Fisharebest\Webtrees\I18N; |
|
24
|
|
|
use Fisharebest\Webtrees\Registry; |
|
25
|
|
|
use Fisharebest\Webtrees\Webtrees; |
|
26
|
|
|
use Symfony\Component\Console\Application; |
|
27
|
|
|
|
|
28
|
|
|
use function parse_ini_file; |
|
29
|
|
|
|
|
30
|
|
|
final class Console extends Application |
|
31
|
|
|
{ |
|
32
|
|
|
private const COMMANDS = [ |
|
33
|
|
|
Commands\CompilePoFiles::class, |
|
34
|
|
|
Commands\TreeCreate::class, |
|
35
|
|
|
Commands\TreeList::class, |
|
36
|
|
|
Commands\UserCreate::class, |
|
37
|
|
|
Commands\UserList::class, |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
public function __construct() |
|
41
|
|
|
{ |
|
42
|
|
|
parent::__construct(Webtrees::NAME, Webtrees::VERSION); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function loadCommands(): self |
|
46
|
|
|
{ |
|
47
|
|
|
foreach (self::COMMANDS as $command) { |
|
48
|
|
|
$this->add(Registry::container()->get($command)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function bootstrap(): self |
|
55
|
|
|
{ |
|
56
|
|
|
I18N::init(code: 'en-US', setup: true); |
|
57
|
|
|
|
|
58
|
|
|
$config = parse_ini_file(filename: Webtrees::CONFIG_FILE); |
|
59
|
|
|
|
|
60
|
|
|
if ($config === false) { |
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
DB::connect( |
|
65
|
|
|
driver: $config['dbtype'] ?? DB::MYSQL, |
|
66
|
|
|
host: $config['dbhost'], |
|
67
|
|
|
port: $config['dbport'], |
|
68
|
|
|
database: $config['dbname'], |
|
69
|
|
|
username: $config['dbuser'], |
|
70
|
|
|
password: $config['dbpass'], |
|
71
|
|
|
prefix: $config['tblpfx'], |
|
72
|
|
|
key: $config['dbkey'] ?? '', |
|
73
|
|
|
certificate: $config['dbcert'] ?? '', |
|
74
|
|
|
ca: $config['dbca'] ?? '', |
|
75
|
|
|
verify_certificate: (bool) ($config['dbverify'] ?? ''), |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
DB::exec('START TRANSACTION'); |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|