3 namespace Friendica\Core\Console;
6 use Friendica\Database\DBStructure;
8 require_once 'boot.php';
9 require_once 'include/dba.php';
12 * @brief Does database updates from the command line
14 * @author Hypolite Petovan <mrpetovan@gmail.com>
16 class DatabaseStructure extends \Asika\SimpleConsole\Console
18 protected $helpOptions = ['h', 'help', '?'];
20 protected function getHelp()
23 console dbstructure - Does database updates
25 bin/console dbstructure <command> [-h|--help|-?] [-v]
28 dryrun Show database update schema queries without running them
29 update Update database schema
30 dumpsql Dump database schema
31 toinnodb Convert all tables from MyISAM to InnoDB
34 -h|--help|-? Show help information
35 -v Show more debug information.
40 protected function doExecute()
42 if ($this->getOption('v')) {
43 $this->out('Class: ' . __CLASS__);
44 $this->out('Arguments: ' . var_export($this->args, true));
45 $this->out('Options: ' . var_export($this->options, true));
48 if (count($this->args) == 0) {
49 $this->out($this->getHelp());
53 if (count($this->args) > 1) {
54 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
57 require_once '.htconfig.php';
58 $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);
59 unset($db_host, $db_user, $db_pass, $db_data);
62 throw new \RuntimeException('Unable to connect to database');
67 switch ($this->getArgument(0)) {
69 $output = DBStructure::update(true, false);
72 $output = DBStructure::update(true, true);
74 $build = Core\Config::get('system', 'build');
76 Core\Config::set('system', 'build', DB_UPDATE_VERSION);
77 $build = DB_UPDATE_VERSION;
80 $stored = intval($build);
81 $current = intval(DB_UPDATE_VERSION);
83 // run any left update_nnnn functions in update.php
84 for ($x = $stored; $x < $current; $x ++) {
85 $r = run_update_function($x);
91 Core\Config::set('system', 'build', DB_UPDATE_VERSION);
95 DBStructure::printStructure();
96 $output = ob_get_clean();
100 DBStructure::convertToInnoDB();
101 $output = ob_get_clean();