3 namespace Friendica\Core\Console;
6 use Friendica\Core\Update;
7 use Friendica\Database\DBA;
8 use Friendica\Database\DBStructure;
11 require_once 'boot.php';
12 require_once 'include/dba.php';
15 * @brief Performs database updates from the command line
17 * @author Hypolite Petovan <hypolite@mrpetovan.com>
19 class DatabaseStructure extends \Asika\SimpleConsole\Console
21 protected $helpOptions = ['h', 'help', '?'];
23 protected function getHelp()
26 console dbstructure - Performs database updates
28 bin/console dbstructure <command> [-h|--help|-?] |-f|--force] [-v]
31 dryrun Show database update schema queries without running them
32 update Update database schema
33 dumpsql Dump database schema
34 toinnodb Convert all tables from MyISAM to InnoDB
37 -h|--help|-? Show help information
38 -v Show more debug information.
39 -f|--force Force the command in case of "update" (Ignore failed updates/running updates)
44 protected function doExecute()
46 if ($this->getOption('v')) {
47 $this->out('Class: ' . __CLASS__);
48 $this->out('Arguments: ' . var_export($this->args, true));
49 $this->out('Options: ' . var_export($this->options, true));
52 if (count($this->args) == 0) {
53 $this->out($this->getHelp());
57 if (count($this->args) > 1) {
58 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
61 if (!DBA::connected()) {
62 throw new RuntimeException('Unable to connect to database');
67 switch ($this->getArgument(0)) {
69 $output = DBStructure::update(true, false);
72 $force = $this->getOption(['f', 'force'], false);
73 $output = Update::run($force, true, false);
77 DBStructure::printStructure();
78 $output = ob_get_clean();
82 DBStructure::convertToInnoDB();
83 $output = ob_get_clean();