Yaffs site version 1.1
[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 Symfony\Component\Console\Command\Command;
14 use Drupal\Core\State\StateInterface;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Console\Core\Style\DrupalStyle;
17
18 /**
19  * Class AccessRebuildCommand
20  *
21  * @package Drupal\Console\Command\Node
22  */
23 class AccessRebuildCommand extends Command
24 {
25     use CommandTrait;
26
27     /**
28      * @var StateInterface
29      */
30     protected $state;
31
32     /**
33      * AccessRebuildCommand constructor.
34      *
35      * @param StateInterface $state
36      */
37     public function __construct(StateInterface $state)
38     {
39         $this->state = $state;
40         parent::__construct();
41     }
42
43     /**
44      * {@inheritdoc}
45      */
46     protected function configure()
47     {
48         $this
49             ->setName('node:access:rebuild')
50             ->setDescription($this->trans('commands.node.access.rebuild.description'))
51             ->addOption(
52                 'batch',
53                 null,
54                 InputOption::VALUE_NONE,
55                 $this->trans('commands.node.access.rebuild.options.batch')
56             );
57     }
58
59     /**
60      * {@inheritdoc}
61      */
62     protected function execute(InputInterface $input, OutputInterface $output)
63     {
64         $io = new DrupalStyle($input, $output);
65         $io->newLine();
66         $io->comment(
67             $this->trans('commands.node.access.rebuild.messages.rebuild')
68         );
69
70         $batch = $input->getOption('batch');
71         try {
72             node_access_rebuild($batch);
73         } catch (\Exception $e) {
74             $io->error($e->getMessage());
75
76             return 1;
77         }
78
79         $needs_rebuild = $this->state->get('node.node_access_needs_rebuild') ? : false;
80         if ($needs_rebuild) {
81             $io->error(
82                 $this->trans('commands.node.access.rebuild.messages.failed')
83             );
84
85             return 1;
86         }
87
88         $io->success(
89             $this->trans('commands.node.access.rebuild.messages.completed')
90         );
91         return 0;
92     }
93 }