3 namespace Friendica\Console;
5 use Friendica\Core\Config\Cache\ConfigCache;
6 use Friendica\Core\Update;
7 use Friendica\Database\Database;
8 use Friendica\Database\DBStructure;
12 * @brief Performs database updates from the command line
14 * @author Hypolite Petovan <hypolite@mrpetovan.com>
16 class DatabaseStructure extends \Asika\SimpleConsole\Console
18 protected $helpOptions = ['h', 'help', '?'];
29 protected function getHelp()
32 console dbstructure - Performs database updates
34 bin/console dbstructure <command> [-h|--help|-?] |-f|--force] [-v]
37 dryrun Show database update schema queries without running them
38 update Update database schema
39 dumpsql Dump database schema
40 toinnodb Convert all tables from MyISAM to InnoDB
43 -h|--help|-? Show help information
44 -v Show more debug information.
45 -f|--force Force the update command (Even if the database structure matches)
46 -o|--override Override running or stalling updates
51 public function __construct(Database $dba, ConfigCache $configCache, $argv = null)
53 parent::__construct($argv);
56 $this->configCache = $configCache;
59 protected function doExecute()
61 if ($this->getOption('v')) {
62 $this->out('Class: ' . __CLASS__);
63 $this->out('Arguments: ' . var_export($this->args, true));
64 $this->out('Options: ' . var_export($this->options, true));
67 if (count($this->args) == 0) {
68 $this->out($this->getHelp());
72 if (count($this->args) > 1) {
73 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
76 if (!$this->dba->isConnected()) {
77 throw new RuntimeException('Unable to connect to database');
80 $basePath = $this->configCache->get('system', 'basepath');
82 switch ($this->getArgument(0)) {
84 $output = DBStructure::update($basePath, true, false);
87 $force = $this->getOption(['f', 'force'], false);
88 $override = $this->getOption(['o', 'override'], false);
89 $output = Update::run($basePath, $force, $override,true, false);
93 DBStructure::printStructure($basePath);
94 $output = ob_get_clean();
98 DBStructure::convertToInnoDB();
99 $output = ob_get_clean();
102 $output = 'Unknown command: ' . $this->getArgument(0);