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|-?] [-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.
43 protected function doExecute()
47 if ($this->getOption('v')) {
48 $this->out('Class: ' . __CLASS__);
49 $this->out('Arguments: ' . var_export($this->args, true));
50 $this->out('Options: ' . var_export($this->options, true));
53 if (count($this->args) == 0) {
54 $this->out($this->getHelp());
58 if (count($this->args) > 1) {
59 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
62 if (!DBA::connected()) {
63 throw new RuntimeException('Unable to connect to database');
68 switch ($this->getArgument(0)) {
70 $output = DBStructure::update(true, false);
73 $build = Core\Config::get('system', 'build');
75 Core\Config::set('system', 'build', DB_UPDATE_VERSION);
76 $build = DB_UPDATE_VERSION;
79 $stored = intval($build);
80 $current = intval(DB_UPDATE_VERSION);
82 // run the pre_update_nnnn functions in update.php
83 for ($x = $stored; $x < $current; $x ++) {
84 $r = Update::runUpdateFunction($x, 'pre_update');
90 $output = DBStructure::update(true, true);
92 // run the update_nnnn functions in update.php
93 for ($x = $stored; $x < $current; $x ++) {
94 $r = Update::runUpdateFunction($x, 'update');
100 Core\Config::set('system', 'build', DB_UPDATE_VERSION);
104 DBStructure::printStructure();
105 $output = ob_get_clean();
109 DBStructure::convertToInnoDB();
110 $output = ob_get_clean();