Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Update / EntitiesCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Update\EntitiesCommand.
6  */
7
8 namespace Drupal\Console\Command\Update;
9
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;
18
19 /**
20  * Class EntitiesCommand.
21  *
22  * @package Drupal\Console\Command\Update
23  */
24 class EntitiesCommand extends Command
25 {
26     /**
27      * @var StateInterface
28      */
29     protected $state;
30
31     /**
32      * @var EntityDefinitionUpdateManager
33      */
34     protected $entityDefinitionUpdateManager;
35
36     /**
37      * @var ChainQueue
38      */
39     protected $chainQueue;
40
41     /**
42      * EntitiesCommand constructor.
43      *
44      * @param StateInterface                $state
45      * @param EntityDefinitionUpdateManager $entityDefinitionUpdateManager
46      * @param ChainQueue                    $chainQueue
47      */
48     public function __construct(
49         StateInterface $state,
50         EntityDefinitionUpdateManager $entityDefinitionUpdateManager,
51         ChainQueue $chainQueue
52     ) {
53         $this->state = $state;
54         $this->entityDefinitionUpdateManager = $entityDefinitionUpdateManager;
55         $this->chainQueue = $chainQueue;
56         parent::__construct();
57     }
58
59     /**
60      * {@inheritdoc}
61      */
62     protected function configure()
63     {
64         $this
65             ->setName('update:entities')
66             ->setDescription($this->trans('commands.update.entities.description'))
67             ->setAliases(['upe']);
68         ;
69     }
70
71     /**
72      * {@inheritdoc}
73      */
74     protected function execute(InputInterface $input, OutputInterface $output)
75     {
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);
80
81         try {
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));
89         }
90
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'));
95     }
96 }