Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.0KB

  1. <?php
  2. namespace Friendica\Core\Console;
  3. use Friendica\Core;
  4. use Friendica\Core\Update;
  5. use Friendica\Database\DBA;
  6. use Friendica\Database\DBStructure;
  7. use RuntimeException;
  8. /**
  9. * @brief Performs database updates from the command line
  10. *
  11. * @author Hypolite Petovan <hypolite@mrpetovan.com>
  12. */
  13. class DatabaseStructure extends \Asika\SimpleConsole\Console
  14. {
  15. protected $helpOptions = ['h', 'help', '?'];
  16. protected function getHelp()
  17. {
  18. $help = <<<HELP
  19. console dbstructure - Performs database updates
  20. Usage
  21. bin/console dbstructure <command> [-h|--help|-?] |-f|--force] [-v]
  22. Commands
  23. dryrun Show database update schema queries without running them
  24. update Update database schema
  25. dumpsql Dump database schema
  26. toinnodb Convert all tables from MyISAM to InnoDB
  27. Options
  28. -h|--help|-? Show help information
  29. -v Show more debug information.
  30. -f|--force Force the command in case of "update" (Ignore failed updates/running updates)
  31. HELP;
  32. return $help;
  33. }
  34. protected function doExecute()
  35. {
  36. if ($this->getOption('v')) {
  37. $this->out('Class: ' . __CLASS__);
  38. $this->out('Arguments: ' . var_export($this->args, true));
  39. $this->out('Options: ' . var_export($this->options, true));
  40. }
  41. if (count($this->args) == 0) {
  42. $this->out($this->getHelp());
  43. return 0;
  44. }
  45. if (count($this->args) > 1) {
  46. throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
  47. }
  48. if (!DBA::connected()) {
  49. throw new RuntimeException('Unable to connect to database');
  50. }
  51. Core\Config::load();
  52. switch ($this->getArgument(0)) {
  53. case "dryrun":
  54. $output = DBStructure::update(true, false);
  55. break;
  56. case "update":
  57. $force = $this->getOption(['f', 'force'], false);
  58. $output = Update::run($force, true, false);
  59. break;
  60. case "dumpsql":
  61. ob_start();
  62. DBStructure::printStructure();
  63. $output = ob_get_clean();
  64. break;
  65. case "toinnodb":
  66. ob_start();
  67. DBStructure::convertToInnoDB();
  68. $output = ob_get_clean();
  69. break;
  70. }
  71. $this->out($output);
  72. return 0;
  73. }
  74. }