3 namespace Friendica\Core\Console;
6 use Friendica\Database\DBA;
7 use Friendica\Database\DBStructure;
10 require_once 'boot.php';
11 require_once 'include/dba.php';
14 * @brief Does database updates from the command line
16 * @author Hypolite Petovan <mrpetovan@gmail.com>
18 class DatabaseStructure extends \Asika\SimpleConsole\Console
20 protected $helpOptions = ['h', 'help', '?'];
22 protected function getHelp()
25 console dbstructure - Does database updates
27 bin/console dbstructure <command> [-h|--help|-?] [-v]
30 dryrun Show database update schema queries without running them
31 update Update database schema
32 dumpsql Dump database schema
33 toinnodb Convert all tables from MyISAM to InnoDB
36 -h|--help|-? Show help information
37 -v Show more debug information.
42 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 $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();