Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Node / AccessRebuildCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Node\AccessRebuildCommand.
6  */
7
8 namespace Drupal\Console\Command\Node;
9
10 use Symfony\Component\Console\Input\InputOption;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Console\Core\Command\Command;
14 use Drupal\Core\State\StateInterface;
15
16 /**
17  * Class AccessRebuildCommand
18  *
19  * @package Drupal\Console\Command\Node
20  */
21 class AccessRebuildCommand extends Command
22 {
23     /**
24      * @var StateInterface
25      */
26     protected $state;
27
28     /**
29      * AccessRebuildCommand constructor.
30      *
31      * @param StateInterface $state
32      */
33     public function __construct(StateInterface $state)
34     {
35         $this->state = $state;
36         parent::__construct();
37     }
38
39     /**
40      * {@inheritdoc}
41      */
42     protected function configure()
43     {
44         $this
45             ->setName('node:access:rebuild')
46             ->setDescription($this->trans('commands.node.access.rebuild.description'))
47             ->addOption(
48                 'batch',
49                 null,
50                 InputOption::VALUE_NONE,
51                 $this->trans('commands.node.access.rebuild.options.batch')
52             )->setAliases(['nar']);
53     }
54
55     /**
56      * {@inheritdoc}
57      */
58     protected function execute(InputInterface $input, OutputInterface $output)
59     {
60         $this->getIo()->newLine();
61         $this->getIo()->comment(
62             $this->trans('commands.node.access.rebuild.messages.rebuild')
63         );
64
65         $batch = $input->getOption('batch');
66         try {
67             node_access_rebuild($batch);
68         } catch (\Exception $e) {
69             $this->getIo()->error($e->getMessage());
70
71             return 1;
72         }
73
74         $needs_rebuild = $this->state->get('node.node_access_needs_rebuild') ? : false;
75         if ($needs_rebuild) {
76             $this->getIo()->error(
77                 $this->trans('commands.node.access.rebuild.messages.failed')
78             );
79
80             return 1;
81         }
82
83         $this->getIo()->success(
84             $this->trans('commands.node.access.rebuild.messages.completed')
85         );
86         return 0;
87     }
88 }