Yaffs site version 1.1
[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 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;
20
21 /**
22  * Class EntitiesCommand.
23  *
24  * @package Drupal\Console\Command\Update
25  */
26 class EntitiesCommand extends Command
27 {
28     use CommandTrait;
29
30     /**
31      * @var StateInterface
32      */
33     protected $state;
34
35     /**
36      * @var EntityDefinitionUpdateManager
37      */
38     protected $entityDefinitionUpdateManager;
39
40     /**
41      * @var ChainQueue
42      */
43     protected $chainQueue;
44
45     /**
46      * EntitiesCommand constructor.
47      *
48      * @param StateInterface                $state
49      * @param EntityDefinitionUpdateManager $entityDefinitionUpdateManager
50      * @param ChainQueue                    $chainQueue
51      */
52     public function __construct(
53         StateInterface $state,
54         EntityDefinitionUpdateManager $entityDefinitionUpdateManager,
55         ChainQueue $chainQueue
56     ) {
57         $this->state = $state;
58         $this->entityDefinitionUpdateManager = $entityDefinitionUpdateManager;
59         $this->chainQueue = $chainQueue;
60         parent::__construct();
61     }
62
63     /**
64      * {@inheritdoc}
65      */
66     protected function configure()
67     {
68         $this
69             ->setName('update:entities')
70             ->setDescription($this->trans('commands.update.entities.description'));
71     }
72
73     /**
74      * {@inheritdoc}
75      */
76     protected function execute(InputInterface $input, OutputInterface $output)
77     {
78         $io = new DrupalStyle($input, $output);
79
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);
84
85         try {
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);
93         }
94
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'));
99     }
100 }