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
|
|
|
public function __construct() |
33
|
|
|
{ |
34
|
|
|
parent::__construct(Webtrees::NAME, Webtrees::VERSION); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function loadCommands(): self |
38
|
|
|
{ |
39
|
|
|
$commands = glob(pattern: __DIR__ . '/Commands/*.php') ?: []; |
40
|
|
|
|
41
|
|
|
foreach ($commands as $command) { |
42
|
|
|
$class = __NAMESPACE__ . '\\Commands\\' . basename(path: $command, suffix: '.php'); |
43
|
|
|
|
44
|
|
|
$this->add(Registry::container()->get($class)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function bootstrap(): self |
51
|
|
|
{ |
52
|
|
|
I18N::init(code: 'en-US', setup: true); |
53
|
|
|
|
54
|
|
|
$config = parse_ini_file(filename: Webtrees::CONFIG_FILE); |
55
|
|
|
|
56
|
|
|
if ($config === false) { |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
DB::connect( |
61
|
|
|
driver: $config['dbtype'] ?? DB::MYSQL, |
62
|
|
|
host: $config['dbhost'], |
63
|
|
|
port: $config['dbport'], |
64
|
|
|
database: $config['dbname'], |
65
|
|
|
username: $config['dbuser'], |
66
|
|
|
password: $config['dbpass'], |
67
|
|
|
prefix: $config['tblpfx'], |
68
|
|
|
key: $config['dbkey'] ?? '', |
69
|
|
|
certificate: $config['dbcert'] ?? '', |
70
|
|
|
ca: $config['dbca'] ?? '', |
71
|
|
|
verify_certificate: (bool) ($config['dbverify'] ?? ''), |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
DB::exec('START TRANSACTION'); |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|