5 * Contains \Drupal\Console\Command\Update\EntitiesCommand.
8 namespace Drupal\Console\Command\Update;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Console\Core\Command\Shared\CommandTrait;
14 use Drupal\Core\Entity\EntityStorageException;
15 use Drupal\Core\Utility\Error;
16 use Drupal\Console\Core\Style\DrupalStyle;
17 use Drupal\Core\State\StateInterface;
18 use Drupal\Core\Entity\EntityDefinitionUpdateManager;
19 use Drupal\Console\Core\Utils\ChainQueue;
22 * Class EntitiesCommand.
24 * @package Drupal\Console\Command\Update
26 class EntitiesCommand extends Command
36 * @var EntityDefinitionUpdateManager
38 protected $entityDefinitionUpdateManager;
43 protected $chainQueue;
46 * EntitiesCommand constructor.
48 * @param StateInterface $state
49 * @param EntityDefinitionUpdateManager $entityDefinitionUpdateManager
50 * @param ChainQueue $chainQueue
52 public function __construct(
53 StateInterface $state,
54 EntityDefinitionUpdateManager $entityDefinitionUpdateManager,
55 ChainQueue $chainQueue
57 $this->state = $state;
58 $this->entityDefinitionUpdateManager = $entityDefinitionUpdateManager;
59 $this->chainQueue = $chainQueue;
60 parent::__construct();
66 protected function configure()
69 ->setName('update:entities')
70 ->setDescription($this->trans('commands.update.entities.description'));
76 protected function execute(InputInterface $input, OutputInterface $output)
78 $io = new DrupalStyle($input, $output);
80 //$state = $this->getDrupalService('state');
81 $io->info($this->trans('commands.site.maintenance.messages.maintenance-on'));
82 $io->info($this->trans('commands.update.entities.messages.start'));
83 $this->state->set('system.maintenance_mode', true);
86 $this->entityDefinitionUpdateManager->applyUpdates();
87 /* @var EntityStorageException $e */
88 } catch (EntityStorageException $e) {
89 /* @var Error $variables */
90 $variables = Error::decodeException($e);
91 $io->info($this->trans('commands.update.entities.messages.error'));
92 $io->info($variables);
95 $this->state->set('system.maintenance_mode', false);
96 $io->info($this->trans('commands.update.entities.messages.end'));
97 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
98 $io->info($this->trans('commands.site.maintenance.messages.maintenance-off'));