3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Console;
24 use Friendica\Core\Config\Cache;
25 use Friendica\Core\Update;
26 use Friendica\Database\Database;
27 use Friendica\Database\DBStructure;
31 * Performs database updates from the command line
33 class DatabaseStructure extends \Asika\SimpleConsole\Console
35 protected $helpOptions = ['h', 'help', '?'];
46 protected function getHelp()
49 console dbstructure - Performs database updates
51 bin/console dbstructure <command> [-h|--help|-?] |-f|--force] [-v]
54 dryrun Show database update schema queries without running them
55 update Update database schema
56 dumpsql Dump database schema
57 toinnodb Convert all tables from MyISAM or InnoDB in the Antelope file format to InnoDB in the Barracuda file format
60 -h|--help|-? Show help information
61 -v Show more debug information.
62 -f|--force Force the update command (Even if the database structure matches)
63 -o|--override Override running or stalling updates
68 public function __construct(Database $dba, Cache $configCache, $argv = null)
70 parent::__construct($argv);
73 $this->configCache = $configCache;
76 protected function doExecute()
78 if ($this->getOption('v')) {
79 $this->out('Class: ' . __CLASS__);
80 $this->out('Arguments: ' . var_export($this->args, true));
81 $this->out('Options: ' . var_export($this->options, true));
84 if (count($this->args) == 0) {
85 $this->out($this->getHelp());
89 if (count($this->args) > 1) {
90 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
93 if (!$this->dba->isConnected()) {
94 throw new RuntimeException('Unable to connect to database');
97 $basePath = $this->configCache->get('system', 'basepath');
99 switch ($this->getArgument(0)) {
101 $output = DBStructure::update($basePath, true, false);
104 $force = $this->getOption(['f', 'force'], false);
105 $override = $this->getOption(['o', 'override'], false);
106 $output = Update::run($basePath, $force, $override,true, false);
110 DBStructure::printStructure($basePath);
111 $output = ob_get_clean();
115 DBStructure::convertToInnoDB();
116 $output = ob_get_clean();
119 $output = 'Unknown command: ' . $this->getArgument(0);