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