2018-03-24 14:39:13 -04:00
|
|
|
<?php
|
|
|
|
|
2019-05-02 17:17:35 -04:00
|
|
|
namespace Friendica\Console;
|
2018-03-24 14:39:13 -04:00
|
|
|
|
|
|
|
use Friendica\Core;
|
2018-10-05 18:53:13 -04:00
|
|
|
use Friendica\Core\Update;
|
2018-07-20 08:19:26 -04:00
|
|
|
use Friendica\Database\DBA;
|
2018-03-24 14:39:13 -04:00
|
|
|
use Friendica\Database\DBStructure;
|
2018-07-19 22:15:21 -04:00
|
|
|
use RuntimeException;
|
2018-03-24 14:39:13 -04:00
|
|
|
|
|
|
|
/**
|
2018-08-29 09:06:56 -04:00
|
|
|
* @brief Performs database updates from the command line
|
2018-03-24 14:39:13 -04:00
|
|
|
*
|
2018-09-15 19:28:38 -04:00
|
|
|
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
2018-03-24 14:39:13 -04:00
|
|
|
*/
|
|
|
|
class DatabaseStructure extends \Asika\SimpleConsole\Console
|
|
|
|
{
|
|
|
|
protected $helpOptions = ['h', 'help', '?'];
|
|
|
|
|
|
|
|
protected function getHelp()
|
|
|
|
{
|
|
|
|
$help = <<<HELP
|
2018-08-29 09:06:56 -04:00
|
|
|
console dbstructure - Performs database updates
|
2018-03-24 14:39:13 -04:00
|
|
|
Usage
|
2018-10-29 05:16:07 -04:00
|
|
|
bin/console dbstructure <command> [-h|--help|-?] |-f|--force] [-v]
|
2018-03-24 14:39:13 -04:00
|
|
|
|
|
|
|
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
|
2019-02-24 06:24:09 -05:00
|
|
|
-h|--help|-? Show help information
|
|
|
|
-v Show more debug information.
|
|
|
|
-f|--force Force the update command (Even if the database structure matches)
|
|
|
|
-o|--override Override running or stalling updates
|
2018-03-24 14:39:13 -04:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2018-07-20 08:19:26 -04:00
|
|
|
if (!DBA::connected()) {
|
2018-07-19 22:15:21 -04:00
|
|
|
throw new RuntimeException('Unable to connect to database');
|
2018-03-24 14:39:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Core\Config::load();
|
|
|
|
|
2019-02-03 16:46:50 -05:00
|
|
|
$a = get_app();
|
|
|
|
|
2018-03-24 14:39:13 -04:00
|
|
|
switch ($this->getArgument(0)) {
|
|
|
|
case "dryrun":
|
2019-02-03 16:46:50 -05:00
|
|
|
$output = DBStructure::update($a->getBasePath(), true, false);
|
2018-03-24 14:39:13 -04:00
|
|
|
break;
|
|
|
|
case "update":
|
2019-02-24 06:24:09 -05:00
|
|
|
$force = $this->getOption(['f', 'force'], false);
|
|
|
|
$override = $this->getOption(['o', 'override'], false);
|
|
|
|
$output = Update::run($a->getBasePath(), $force, $override,true, false);
|
2018-03-24 14:39:13 -04:00
|
|
|
break;
|
|
|
|
case "dumpsql":
|
|
|
|
ob_start();
|
2019-02-03 16:46:50 -05:00
|
|
|
DBStructure::printStructure($a->getBasePath());
|
2018-03-24 14:39:13 -04:00
|
|
|
$output = ob_get_clean();
|
|
|
|
break;
|
|
|
|
case "toinnodb":
|
|
|
|
ob_start();
|
|
|
|
DBStructure::convertToInnoDB();
|
|
|
|
$output = ob_get_clean();
|
|
|
|
break;
|
2019-01-07 12:51:48 -05:00
|
|
|
default:
|
|
|
|
$output = 'Unknown command: ' . $this->getArgument(0);
|
2018-03-24 14:39:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->out($output);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|