Elgg  Version 4.3
UpgradeCommand.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
7 use function React\Promise\all;
11 
15 class UpgradeCommand extends BaseCommand {
16 
20  protected function configure() {
21  $this->setName('upgrade')
22  ->setDescription(elgg_echo('cli:upgrade:description'))
23  ->addOption('force', 'f', InputOption::VALUE_NONE,
24  elgg_echo('cli:upgrade:option:force')
25  )
26  ->addArgument('async', InputOption::VALUE_OPTIONAL,
27  elgg_echo('cli:upgrade:argument:async')
28  );
29  }
30 
34  protected function execute(InputInterface $input, OutputInterface $output) {
35  $this->input = $input;
36  $this->output = $output;
37 
38  $async = (bool) $this->argument('async');
39  $force = $this->option('force');
40 
41  $return = 0;
42 
43  // run Phinx (database) migrations
44  ElggApplication::migrate();
45 
46  $app = ElggApplication::getInstance();
47  $initial_app = clone $app;
48 
49  $boot = new BootHandler($app);
50  $boot->bootServices();
51  $boot->bootPlugins();
52 
53  // check if upgrade is locked
54  $is_locked = _elgg_services()->mutex->isLocked('upgrade');
55  if ($is_locked && !$force) {
56  $this->error(elgg_echo('upgrade:locked'));
57 
58  return 1;
59  } elseif ($is_locked && $force) {
60  _elgg_services()->mutex->unlock('upgrade');
61 
62  $this->notice(elgg_echo('upgrade:unlock:success'));
63  }
64 
65  // run system upgrades
66  $upgrades = _elgg_services()->upgrades->getPendingUpgrades(false);
67  $job = _elgg_services()->upgrades->run($upgrades);
68 
69  $job->done(
70  function () {
71  $this->notice(elgg_echo('cli:upgrade:system:upgraded'));
72  },
73  function ($errors) use (&$return) {
74  $this->error(elgg_echo('cli:upgrade:system:failed'));
75 
76  if (!is_array($errors)) {
77  $errors = [$errors];
78  }
79 
80  foreach ($errors as $error) {
81  $this->error($error);
82  }
83  $return = 1;
84  }
85  );
86 
87  _elgg_services()->plugins->generateEntities();
88 
89  if ($return !== 0 || !$async) {
90  return $return;
91  }
92 
93  // We want to reboot the application, because some of the services (e.g. dic) can bootstrap themselves again
94  $app = $initial_app;
95  ElggApplication::setInstance($initial_app);
96  $app->start();
97 
98  // run async upgrades
99  $upgrades = _elgg_services()->upgrades->getPendingUpgrades($async);
100  $job = _elgg_services()->upgrades->run($upgrades);
101 
102  $job->done(
103  function () {
104  $this->notice(elgg_echo('cli:upgrade:async:upgraded'));
105  },
106  function ($errors) use (&$return) {
107  $this->error(elgg_echo('cli:upgrade:aysnc:failed'));
108 
109  if (!is_array($errors)) {
110  $errors = [$errors];
111  }
112 
113  foreach ($errors as $error) {
114  $this->error($error);
115  }
116  $return = 1;
117  }
118  );
119 
120  return $return;
121  }
122 }
if(empty($plugins)) $errors
Adds interaction to a console command.
Definition: BaseCommand.php:18
error($message)
Print an error.
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
notice($message)
Print a notce.
$upgrades
Lists pending upgrades.
Definition: upgrades.php:11
$error
Bad request error.
Definition: 400.php:6
execute(InputInterface $input, OutputInterface $output)
{}
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
elgg-cli upgrade [async]
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
argument($name)
Returns argument value.
Handles application boot sequence.
Definition: BootHandler.php:12
option($name)
Returns option value.