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.

73 lines
1.7KB

  1. <?php
  2. namespace Friendica\Core\Console;
  3. use Friendica\Core\Config;
  4. use Friendica\Core\L10n;
  5. use Friendica\Core\Update;
  6. /**
  7. * Performs database post updates
  8. *
  9. * License: AGPLv3 or later, same as Friendica
  10. *
  11. * @author Tobias Diekershoff <tobias.diekershoff@gmx.net>
  12. * @author Hypolite Petovan <hypolite@mrpetovan.com>
  13. */
  14. class PostUpdate extends \Asika\SimpleConsole\Console
  15. {
  16. protected $helpOptions = ['h', 'help', '?'];
  17. protected function getHelp()
  18. {
  19. $help = <<<HELP
  20. console postupdate - Performs database post updates
  21. Usage
  22. bin/console postupdate [-h|--help|-?] [--reset <version>]
  23. Options
  24. -h|--help|-? Show help information
  25. --reset <version> Reset the post update version
  26. HELP;
  27. return $help;
  28. }
  29. protected function doExecute()
  30. {
  31. $a = \Friendica\BaseObject::getApp();
  32. if ($this->getOption($this->helpOptions)) {
  33. $this->out($this->getHelp());
  34. return 0;
  35. }
  36. $reset_version = $this->getOption('reset');
  37. if (is_bool($reset_version)) {
  38. $this->out($this->getHelp());
  39. return 0;
  40. } elseif ($reset_version) {
  41. Config::set('system', 'post_update_version', $reset_version);
  42. echo L10n::t('Post update version number has been set to %s.', $reset_version) . "\n";
  43. return 0;
  44. }
  45. if ($a->getMode()->isInstall()) {
  46. throw new \RuntimeException('Database isn\'t ready or populated yet');
  47. }
  48. echo L10n::t('Check for pending update actions.') . "\n";
  49. Update::run($a->getBasePath(), true, true, false);
  50. echo L10n::t('Done.') . "\n";
  51. echo L10n::t('Execute pending post updates.') . "\n";
  52. while (!\Friendica\Database\PostUpdate::update()) {
  53. echo '.';
  54. }
  55. echo "\n" . L10n::t('All pending post updates are done.') . "\n";
  56. return 0;
  57. }
  58. }