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.

109 lines
2.3KB

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