Elgg  Version 3.0
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  ->addArgument('async', InputOption::VALUE_OPTIONAL,
23  'Execute pending asynchronous upgrades'
24  )
25  ->setDescription('Run system upgrade');
26  }
27 
31  protected function execute(InputInterface $input, OutputInterface $output) {
32  $this->input = $input;
33  $this->output = $output;
34 
35  $async = (bool) $this->argument('async');
36 
37  $return = 0;
38 
39  ElggApplication::migrate();
40 
41  $app = ElggApplication::getInstance();
42  $initial_app = clone $app;
43 
44  $boot = new BootHandler($app);
45  $boot->bootServices();
46 
47  $upgrades = _elgg_services()->upgrades->getPendingUpgrades(false);
48  $job = _elgg_services()->upgrades->run($upgrades);
49 
50  $job->done(
51  function () {
52  $this->notice('System has been upgraded');
53  },
54  function ($errors) use (&$return) {
55  $this->error('System upgrade has failed');
56 
57  if (!is_array($errors)) {
58  $errors = [$errors];
59  }
60 
61  foreach ($errors as $error) {
62  $this->error($error);
63  }
64  $return = 1;
65  }
66  );
67 
68  // We want to reboot the application, because some of the services (e.g. dic) can bootstrap themselves again
69  $app = $initial_app;
70  ElggApplication::setInstance($initial_app);
71  $app->start();
72 
73  $upgrades = _elgg_services()->upgrades->getPendingUpgrades($async);
74  $job = _elgg_services()->upgrades->run($upgrades);
75 
76  $job->done(
77  function () {
78  $this->notice('Plugins have been upgraded');
79  },
80  function ($errors) use (&$return) {
81  $this->error('Plugin upgrade has failed');
82 
83  if (!is_array($errors)) {
84  $errors = [$errors];
85  }
86 
87  foreach ($errors as $error) {
88  $this->error($error);
89  }
90  $return = 1;
91  }
92  );
93 
94  return $return;
95  }
96 }
$errors
Definition: pending.php:46
Adds interaction to a console command.
Definition: BaseCommand.php:17
error($message)
Print an error.
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)
{}
elgg-cli upgrade [async]
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
argument($name)
Returns argument value.
Handles application boot sequence.
Definition: BootHandler.php:13