1 | <?php |
||
2 | |||
3 | /** |
||
4 | * webtrees: online genealogy |
||
5 | * Copyright (C) 2025 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 | use Throwable; |
||
28 | |||
29 | use function parse_ini_file; |
||
30 | |||
31 | final class Console extends Application |
||
32 | { |
||
33 | private const array COMMANDS = [ |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
34 | Commands\CompilePoFiles::class, |
||
35 | Commands\ConfigIni::class, |
||
36 | Commands\SiteOffline::class, |
||
37 | Commands\SiteOnline::class, |
||
38 | Commands\SiteSetting::class, |
||
39 | //Commands\TreeCreate::class, |
||
40 | Commands\TreeExport::class, |
||
41 | Commands\TreeImport::class, |
||
42 | Commands\TreeList::class, |
||
43 | Commands\TreeSetting::class, |
||
44 | //Commands\UserCreate::class, |
||
45 | Commands\UserList::class, |
||
46 | Commands\UserSetting::class, |
||
47 | Commands\UserTreeSetting::class, |
||
48 | ]; |
||
49 | |||
50 | public function __construct() |
||
51 | { |
||
52 | parent::__construct(name: Webtrees::NAME, version: Webtrees::VERSION); |
||
53 | } |
||
54 | |||
55 | public function loadCommands(): self |
||
56 | { |
||
57 | foreach (self::COMMANDS as $command) { |
||
58 | $this->add(Registry::container()->get($command)); |
||
59 | } |
||
60 | |||
61 | return $this; |
||
62 | } |
||
63 | |||
64 | public function bootstrap(): self |
||
65 | { |
||
66 | I18N::init(code: 'en-US', setup: true); |
||
67 | |||
68 | try { |
||
69 | $config = parse_ini_file(filename: Webtrees::CONFIG_FILE) ?: []; |
||
70 | |||
71 | DB::connect( |
||
72 | driver: $config['dbtype'] ?? DB::MYSQL, |
||
73 | host: $config['dbhost'] ?? '', |
||
74 | port: $config['dbport'] ?? '', |
||
75 | database: $config['dbname'] ?? '', |
||
76 | username: $config['dbuser'] ?? '', |
||
77 | password: $config['dbpass'] ?? '', |
||
78 | prefix: $config['tblpfx'] ?? '', |
||
79 | key: $config['dbkey'] ?? '', |
||
80 | certificate: $config['dbcert'] ?? '', |
||
81 | ca: $config['dbca'] ?? '', |
||
82 | verify_certificate: (bool) ($config['dbverify'] ?? ''), |
||
83 | ); |
||
84 | } catch (Throwable) { |
||
85 | // Ignore errors |
||
86 | } |
||
87 | |||
88 | return $this; |
||
89 | } |
||
90 | } |
||
91 |