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