Elgg  Version 4.3
UpgradeBatchCommand.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
8 
13 
17  protected function configure() {
18  $this->setName('upgrade:batch')
19  ->setDescription(elgg_echo('cli:upgrade:batch:description'))
20  ->addOption('force', 'f', InputOption::VALUE_NONE,
21  elgg_echo('cli:upgrade:batch:option:force')
22  )
23  ->addArgument('upgrades', InputArgument::REQUIRED | InputArgument::IS_ARRAY,
24  elgg_echo('cli:upgrade:batch:argument:upgrades')
25  );
26  }
27 
31  protected function command() {
32  $upgrades = (array) $this->argument('upgrades');
33  $force = (bool) $this->option('force');
34 
35  foreach ($upgrades as $upgrade_class) {
36  $upgrade = _elgg_services()->upgradeLocator->getUpgradeByClass($upgrade_class);
37  if (!$upgrade instanceof \ElggUpgrade) {
38  $this->log(LogLevel::WARNING, elgg_echo('cli:upgrade:batch:notfound', [$upgrade_class]));
39  continue;
40  }
41 
42  if (!$force && $upgrade->isCompleted()) {
43  continue;
44  }
45 
46  _elgg_services()->upgrades->executeUpgrade($upgrade, 0);
47  }
48 
49  if (!$this->option('quiet')) {
50  $this->write(elgg_echo('cli:upgrade:batch:finished'));
51  }
52 
53  return 0;
54  }
55 }
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
$upgrades
Lists pending upgrades.
Definition: upgrades.php:11
if(empty($guid)) $upgrade
Definition: upgrade.php:11
Represents an upgrade that runs outside of the upgrade.php script.
Definition: ElggUpgrade.php:26
write($messages, $level=LogLevel::INFO)
Write messages to output buffer.
Definition: BaseCommand.php:93
Abstract command with some utility methods.
Definition: Command.php:12
log($level, $message, array $context=[])
Log a message.
Definition: Loggable.php:58
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
argument($name)
Returns argument value.
option($name)
Returns option value.