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 Drupal\Console\Core\Command\Command;
13 use Drupal\Core\Entity\EntityStorageException;
14 use Drupal\Core\Utility\Error;
15 use Drupal\Core\State\StateInterface;
16 use Drupal\Core\Entity\EntityDefinitionUpdateManager;
17 use Drupal\Console\Core\Utils\ChainQueue;
20 * Class EntitiesCommand.
22 * @package Drupal\Console\Command\Update
24 class EntitiesCommand extends Command
32 * @var EntityDefinitionUpdateManager
34 protected $entityDefinitionUpdateManager;
39 protected $chainQueue;
42 * EntitiesCommand constructor.
44 * @param StateInterface $state
45 * @param EntityDefinitionUpdateManager $entityDefinitionUpdateManager
46 * @param ChainQueue $chainQueue
48 public function __construct(
49 StateInterface $state,
50 EntityDefinitionUpdateManager $entityDefinitionUpdateManager,
51 ChainQueue $chainQueue
53 $this->state = $state;
54 $this->entityDefinitionUpdateManager = $entityDefinitionUpdateManager;
55 $this->chainQueue = $chainQueue;
56 parent::__construct();
62 protected function configure()
65 ->setName('update:entities')
66 ->setDescription($this->trans('commands.update.entities.description'))
67 ->setAliases(['upe']);
74 protected function execute(InputInterface $input, OutputInterface $output)
76 //$state = $this->getDrupalService('state');
77 $this->getIo()->info($this->trans('commands.site.maintenance.messages.maintenance-on'));
78 $this->getIo()->info($this->trans('commands.update.entities.messages.start'));
79 $this->state->set('system.maintenance_mode', true);
82 $this->entityDefinitionUpdateManager->applyUpdates();
83 /* @var EntityStorageException $e */
84 } catch (EntityStorageException $e) {
85 /* @var Error $variables */
86 $variables = Error::decodeException($e);
87 $this->getIo()->errorLite($this->trans('commands.update.entities.messages.error'));
88 $this->getIo()->error(strtr('%type: @message in %function (line %line of %file).', $variables));
91 $this->state->set('system.maintenance_mode', false);
92 $this->getIo()->info($this->trans('commands.update.entities.messages.end'));
93 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
94 $this->getIo()->info($this->trans('commands.site.maintenance.messages.maintenance-off'));