|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. |
|
4
|
|
|
* @author: <mailto:[email protected]> |
|
5
|
|
|
* @github: <https://github.com/hryvinskyi> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Hryvinskyi\InvisibleCaptcha\Command; |
|
11
|
|
|
|
|
12
|
|
|
use Hryvinskyi\InvisibleCaptcha\Model\Area; |
|
13
|
|
|
use Magento\Framework\App\Cache\Manager; |
|
14
|
|
|
use Magento\Framework\Exception\LocalizedException; |
|
15
|
|
|
use Magento\Store\Model\StoreManagerInterface; |
|
16
|
|
|
use Symfony\Component\Console\Command\Command; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class Captcha |
|
24
|
|
|
*/ |
|
25
|
|
|
class Captcha extends Command |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var Manager |
|
29
|
|
|
*/ |
|
30
|
|
|
private $cacheManager; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var StoreManagerInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
private $storeManager; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var Area |
|
39
|
|
|
*/ |
|
40
|
|
|
private $area; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
private $areaConfigList; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* ReCaptcha constructor. |
|
49
|
|
|
* |
|
50
|
|
|
* @param Manager $cacheManager |
|
51
|
|
|
* @param StoreManagerInterface $storeManager |
|
52
|
|
|
* @param Area $area |
|
53
|
|
|
* @param Area\ConfigList $areaConfigList |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct( |
|
56
|
|
|
Manager $cacheManager, |
|
57
|
|
|
StoreManagerInterface $storeManager, |
|
58
|
|
|
Area $area, |
|
59
|
|
|
Area\ConfigList $areaConfigList |
|
60
|
|
|
) { |
|
61
|
|
|
$this->cacheManager = $cacheManager; |
|
62
|
|
|
$this->storeManager = $storeManager; |
|
63
|
|
|
$this->area = $area; |
|
64
|
|
|
$this->areaConfigList = $areaConfigList; |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
parent::__construct(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @inheritdoc |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function configure() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->setName('hryvinskyi:invisible-captcha:disable') |
|
75
|
|
|
->setDescription('Disable invisible captcha') |
|
76
|
|
|
->addArgument( |
|
77
|
|
|
'area', |
|
78
|
|
|
InputArgument::OPTIONAL, |
|
79
|
|
|
'Area (' . implode('/', $this->area->getAllowedList()) . ')', |
|
80
|
|
|
Area::GLOBAL |
|
81
|
|
|
) |
|
82
|
|
|
->addOption( |
|
83
|
|
|
'website_id', |
|
84
|
|
|
'website_id', |
|
85
|
|
|
InputOption::VALUE_OPTIONAL, |
|
86
|
|
|
'Website ID', |
|
87
|
|
|
null |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
parent::configure(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* {@inheritdoc} |
|
95
|
|
|
* @SuppressWarnings("PHPMD.UnusedFormalParameter") |
|
96
|
|
|
* @throws LocalizedException |
|
97
|
|
|
*/ |
|
98
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
99
|
|
|
{ |
|
100
|
|
|
$area = $input->getArgument('area'); |
|
101
|
|
|
$website = $input->getOption('website_id'); |
|
102
|
|
|
|
|
103
|
|
|
if ($website !== null && !isset($this->allWebsites()[$website])) { |
|
104
|
|
|
throw new LocalizedException(__('Website not found')); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
// disable captcha |
|
108
|
|
|
$this->areaConfigList->getConfig($area)->disableCaptcha($area === Area::BACKEND ? null : $website); |
|
109
|
|
|
|
|
110
|
|
|
// flush cache |
|
111
|
|
|
$this->cacheManager->flush(['config']); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Return all websites |
|
116
|
|
|
* |
|
117
|
|
|
* @return array |
|
118
|
|
|
*/ |
|
119
|
|
|
private function allWebsites(): array |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->storeManager->getWebsites(); |
|
122
|
|
|
} |
|
123
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..