1 | <?php |
||
12 | abstract class AbstractMagentoStoreConfigCommand extends AbstractMagentoCommand |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | const SCOPE_STORE_VIEW = 'store'; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | const SCOPE_WEBSITE = 'website'; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | const SCOPE_GLOBAL = 'global'; |
||
28 | |||
29 | /** |
||
30 | * Store view or global by additional option |
||
31 | */ |
||
32 | const SCOPE_STORE_VIEW_GLOBAL = 'store_view_global'; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $commandName = ''; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $commandDescription = ''; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $configPath = ''; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $toggleComment = ''; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $falseName = 'disabled'; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | */ |
||
62 | protected $trueName = 'enabled'; |
||
63 | |||
64 | /** |
||
65 | * Add admin store to interactive prompt |
||
66 | * |
||
67 | * @var bool |
||
68 | */ |
||
69 | protected $withAdminStore = false; |
||
70 | |||
71 | /** |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $scope = self::SCOPE_STORE_VIEW; |
||
75 | |||
76 | protected function configure() |
||
93 | |||
94 | /** |
||
95 | * @param InputInterface $input |
||
96 | * @param OutputInterface $output |
||
97 | * |
||
98 | * @return int|void |
||
99 | */ |
||
100 | protected function execute(InputInterface $input, OutputInterface $output) |
||
147 | |||
148 | /** |
||
149 | * Determine if a developer restriction is in place, and if we're enabling something that will use it |
||
150 | * then notify and ask if it needs to be changed from its current value. |
||
151 | * |
||
152 | * @param \Mage_Core_Model_Store $store |
||
153 | * @param bool $enabled |
||
154 | * @return void |
||
155 | */ |
||
156 | protected function detectAskAndSetDeveloperIp(\Mage_Core_Model_Store $store, $enabled) |
||
157 | { |
||
158 | if (!$enabled) { |
||
159 | // No need to notify about developer IP restrictions if we're disabling template hints etc |
||
160 | return; |
||
161 | } |
||
162 | |||
163 | /** @var OutputInterface $output */ |
||
164 | $output = $this->getHelper('io')->getOutput(); |
||
165 | |||
166 | if (!$devRestriction = $store->getConfig('dev/restrict/allow_ips')) { |
||
167 | return; |
||
168 | } |
||
169 | |||
170 | $this->askAndSetDeveloperIp($output, $store, $devRestriction); |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Ask if the developer IP should be changed, and change it if required |
||
175 | * |
||
176 | * @param OutputInterface $output |
||
177 | * @param \Mage_Core_Model_Store $store |
||
178 | * @param string|null $devRestriction |
||
179 | * @return void |
||
180 | */ |
||
181 | protected function askAndSetDeveloperIp(OutputInterface $output, \Mage_Core_Model_Store $store, $devRestriction) |
||
182 | { |
||
183 | $output->writeln( |
||
184 | sprintf( |
||
185 | '<comment><info>Please note:</info> developer IP restriction is enabled for <info>%s</info>.', |
||
186 | $devRestriction |
||
187 | ) |
||
188 | ); |
||
189 | |||
190 | /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ |
||
191 | $dialog = $this->getHelperSet()->get('dialog'); |
||
192 | $newDeveloperIp = $dialog->ask( |
||
193 | $output, |
||
194 | '<question>Change developer IP? Enter a new IP to change or leave blank</question>: ' |
||
195 | ); |
||
196 | |||
197 | if (empty($newDeveloperIp)) { |
||
198 | return; |
||
199 | } |
||
200 | |||
201 | $this->setDeveloperIp($store, $newDeveloperIp); |
||
202 | $output->writeln(sprintf('<comment><info>New developer IP restriction set to %s', $newDeveloperIp)); |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * Set the restricted IP for developer access |
||
207 | * |
||
208 | * @param \Mage_Core_Model_Store $store |
||
209 | * @param string $newDeveloperIp |
||
210 | */ |
||
211 | protected function setDeveloperIp(\Mage_Core_Model_Store $store, $newDeveloperIp) |
||
212 | { |
||
213 | \Mage::getModel('core/config') |
||
214 | ->saveConfig('dev/restrict/allow_ips', $newDeveloperIp, 'stores', $store->getId()); |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * @param InputInterface $input |
||
219 | * @param OutputInterface $output |
||
220 | * |
||
221 | * @return mixed |
||
222 | */ |
||
223 | protected function _initStore($input, $output) |
||
227 | |||
228 | /** |
||
229 | * @param \Mage_Core_Model_Store $store |
||
230 | * @param bool $disabled |
||
231 | */ |
||
232 | protected function _beforeSave(\Mage_Core_Model_Store $store, $disabled) |
||
235 | |||
236 | /** |
||
237 | * @param \Mage_Core_Model_Store $store |
||
238 | * @param bool $disabled |
||
239 | */ |
||
240 | protected function _afterSave(\Mage_Core_Model_Store $store, $disabled) |
||
243 | } |
||
244 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: