This repository was archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathDriverUnlockCommand.php
More file actions
112 lines (95 loc) · 3.11 KB
/
Copy pathDriverUnlockCommand.php
File metadata and controls
112 lines (95 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace Lexik\Bundle\MaintenanceBundle\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
/**
* Create an unlock action
*
* @package LexikMaintenanceBundle
* @author Gilles Gauthier <g.gauthier@lexik.fr>
*/
class DriverUnlockCommand extends Command
{
/**
* return object of Queue
*
* @return object
* @package LexikMaintenanceBundleBundle
*/
public function setContainer($container){
$this->container = $container;
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('lexik:maintenance:unlock')
->setDescription('Unlock access to the site while maintenance...')
->setHelp(<<<EOT
You can execute the unlock without a warning message which you need to interact with:
<info>%command.full_name% --no-interaction</info>
EOT
);
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$this->confirmUnlock($input, $output)) {
return;
}
$driver = $this->container->get('lexik_maintenance.driver.factory')->getDriver();
$unlockMessage = $driver->getMessageUnlock($driver->unlock());
$output->writeln('<info>'.$unlockMessage.'</info>');
return 0;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return bool
*/
protected function confirmUnlock(InputInterface $input, OutputInterface $output)
{
$formatter = $this->getHelperSet()->get('formatter');
if ($input->getOption('no-interaction', false)) {
$confirmation = true;
} else {
// confirm
$output->writeln(array(
'',
$formatter->formatBlock('You are about to unlock your server.', 'bg=green;fg=white', true),
'',
));
$confirmation = $this->askConfirmation(
'WARNING! Are you sure you wish to continue? (y/n) ',
$input,
$output
);
}
if (!$confirmation) {
$output->writeln('<error>Action cancelled!</error>');
}
return $confirmation;
}
/**
* This method ensure that we stay compatible with symfony console 2.3 by using the deprecated dialog helper
* but use the ConfirmationQuestion when available.
*
* @param $question
* @param InputInterface $input
* @param OutputInterface $output
* @return mixed
*/
protected function askConfirmation($question, InputInterface $input, OutputInterface $output) {
if (!$this->getHelperSet()->has('question')) {
return $this->getHelper('dialog')
->askConfirmation($output, '<question>' . $question . '</question>', 'y');
}
return $this->getHelper('question')
->ask($input, $output, new \Symfony\Component\Console\Question\ConfirmationQuestion($question));
}
}