-<?php\r
-\r
-namespace Friendica\Core\Console;\r
-\r
-use Friendica\Core;\r
-use Friendica\Database\DBStructure;\r
-\r
-require_once 'boot.php';\r
-require_once 'include/dba.php';\r
-\r
-/**\r
- * @brief Does database updates from the command line\r
- *\r
- * @author Hypolite Petovan <mrpetovan@gmail.com>\r
- */\r
-class DatabaseStructure extends \Asika\SimpleConsole\Console\r
-{\r
- protected $helpOptions = ['h', 'help', '?'];\r
-\r
- protected function getHelp()\r
- {\r
- $help = <<<HELP\r
-console dbstructure - Does database updates\r
-Usage\r
- bin/console dbstructure <command> [-h|--help|-?] [-v]\r
-\r
-Commands\r
- dryrun Show database update schema queries without running them\r
- update Update database schema\r
- dumpsql Dump database schema\r
- toinnodb Convert all tables from MyISAM to InnoDB\r
-\r
-Options\r
- -h|--help|-? Show help information\r
- -v Show more debug information.\r
-HELP;\r
- return $help;\r
- }\r
-\r
- protected function doExecute()\r
- {\r
- if ($this->getOption('v')) {\r
- $this->out('Class: ' . __CLASS__);\r
- $this->out('Arguments: ' . var_export($this->args, true));\r
- $this->out('Options: ' . var_export($this->options, true));\r
- }\r
-\r
- if (count($this->args) == 0) {\r
- $this->out($this->getHelp());\r
- return 0;\r
- }\r
-\r
- if (count($this->args) > 1) {\r
- throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');\r
- }\r
-\r
- require_once '.htconfig.php';\r
- $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);\r
- unset($db_host, $db_user, $db_pass, $db_data);\r
-\r
- if (!$result) {\r
- throw new \RuntimeException('Unable to connect to database');\r
- }\r
-\r
- Core\Config::load();\r
-\r
- switch ($this->getArgument(0)) {\r
- case "dryrun":\r
- $output = DBStructure::update(true, false);\r
- break;\r
- case "update":\r
- $output = DBStructure::update(true, true);\r
-\r
- $build = Core\Config::get('system', 'build');\r
- if (empty($build)) {\r
- Core\Config::set('system', 'build', DB_UPDATE_VERSION);\r
- $build = DB_UPDATE_VERSION;\r
- }\r
-\r
- $stored = intval($build);\r
- $current = intval(DB_UPDATE_VERSION);\r
-\r
- // run any left update_nnnn functions in update.php\r
- for ($x = $stored; $x < $current; $x ++) {\r
- $r = run_update_function($x);\r
- if (!$r) {\r
- break;\r
- }\r
- }\r
-\r
- Core\Config::set('system', 'build', DB_UPDATE_VERSION);\r
- break;\r
- case "dumpsql":\r
- ob_start();\r
- DBStructure::printStructure();\r
- $output = ob_get_clean();\r
- break;\r
- case "toinnodb":\r
- ob_start();\r
- DBStructure::convertToInnoDB();\r
- $output = ob_get_clean();\r
- break;\r
- }\r
-\r
- $this->out($output);\r
-\r
- return 0;\r
- }\r
-\r
-}\r
+<?php
+
+namespace Friendica\Core\Console;
+
+use Friendica\Core;
+use Friendica\Core\Update;
+use Friendica\Database\DBA;
+use Friendica\Database\DBStructure;
+use RuntimeException;
+
+/**
+ * @brief Performs database updates from the command line
+ *
+ * @author Hypolite Petovan <hypolite@mrpetovan.com>
+ */
+class DatabaseStructure extends \Asika\SimpleConsole\Console
+{
+ protected $helpOptions = ['h', 'help', '?'];
+
+ protected function getHelp()
+ {
+ $help = <<<HELP
+console dbstructure - Performs database updates
+Usage
+ bin/console dbstructure <command> [-h|--help|-?] |-f|--force] [-v]
+
+Commands
+ dryrun Show database update schema queries without running them
+ update Update database schema
+ dumpsql Dump database schema
+ toinnodb Convert all tables from MyISAM to InnoDB
+
+Options
+ -h|--help|-? Show help information
+ -v Show more debug information.
+ -f|--force Force the command in case of "update" (Ignore failed updates/running updates)
+HELP;
+ return $help;
+ }
+
+ protected function doExecute()
+ {
+ if ($this->getOption('v')) {
+ $this->out('Class: ' . __CLASS__);
+ $this->out('Arguments: ' . var_export($this->args, true));
+ $this->out('Options: ' . var_export($this->options, true));
+ }
+
+ if (count($this->args) == 0) {
+ $this->out($this->getHelp());
+ return 0;
+ }
+
+ if (count($this->args) > 1) {
+ throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+ }
+
+ if (!DBA::connected()) {
+ throw new RuntimeException('Unable to connect to database');
+ }
+
+ Core\Config::load();
+
+ switch ($this->getArgument(0)) {
+ case "dryrun":
+ $output = DBStructure::update(true, false);
+ break;
+ case "update":
+ $force = $this->getOption(['f', 'force'], false);
+ $output = Update::run($force, true, false);
+ break;
+ case "dumpsql":
+ ob_start();
+ DBStructure::printStructure();
+ $output = ob_get_clean();
+ break;
+ case "toinnodb":
+ ob_start();
+ DBStructure::convertToInnoDB();
+ $output = ob_get_clean();
+ break;
+ }
+
+ $this->out($output);
+
+ return 0;
+ }
+
+}