Skip to content

Commit 0d380b4

Browse files
Fixed admin config observer for testConnection. r106165
Removed unused code.
1 parent 694679c commit 0d380b4

File tree

2 files changed

+20
-117
lines changed

2 files changed

+20
-117
lines changed

app/code/community/PostcodeNl/Api/Helper/Data.php

Lines changed: 9 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class PostcodeNl_Api_Helper_Data extends Mage_Core_Helper_Abstract
1414
protected $_httpClientError = null;
1515
protected $_debuggingOverride = false;
1616

17+
1718
/**
1819
* Get the html for initializing validation script.
1920
*
@@ -88,7 +89,7 @@ public function isDebugging()
8889
*
8990
* @param bool $toggle
9091
*/
91-
public function setDebuggingOverride($toggle = true)
92+
protected function _setDebuggingOverride($toggle)
9293
{
9394
$this->_debuggingOverride = $toggle;
9495
}
@@ -196,92 +197,6 @@ public function setEnrichType($enrichType)
196197
$this->_enrichType = substr($this->_enrichType, 0, 40);
197198
}
198199

199-
/**
200-
* Split a house number addition from a house number.
201-
* Examples: "123 2", "123 rood", "123a", "123a4", "123-a", "123 II"
202-
* (the official notation is to separate the house number and addition with a single space)
203-
*
204-
* @param string $houseNumber House number input
205-
*
206-
* @return array Split 'houseNumber' and 'houseNumberAddition'
207-
*/
208-
public function splitHouseNumber($houseNumber)
209-
{
210-
$houseNumberAddition = '';
211-
if (preg_match('~^(?<number>[0-9]+)(?:[^0-9a-zA-Z]+(?<addition1>[0-9a-zA-Z ]+)|(?<addition2>[a-zA-Z](?:[0-9a-zA-Z ]*)))?$~', $houseNumber, $match))
212-
{
213-
$houseNumber = $match['number'];
214-
$houseNumberAddition = isset($match['addition2']) ? $match['addition2'] : (isset($match['addition1']) ? $match['addition1'] : null);
215-
}
216-
217-
return array($houseNumber, $houseNumberAddition);
218-
}
219-
220-
/**
221-
* Split a street name, house number and house number addition from a text lines containing a street and house number information.
222-
*
223-
* @param array $streetData Lines of street data
224-
*
225-
* @return array Array containing 'street', 'houseNumber' and 'houseNumberAddition'
226-
*/
227-
public function splitStreetData(array $streetData)
228-
{
229-
$regexpStreet = '[^0-9].*?|.*?[^0-9]';
230-
$regexpHouseNumber = '[0-9]+';
231-
$regexpHouseNumberAddition = '[^\\s]+|[^\\s]\\s+[^\\s]{1,4}';
232-
233-
if (preg_match('~^(?<street>'. $regexpStreet .')\s+(?<houseNumber>'. $regexpHouseNumber .')([^0-9a-zA-Z]*(?<houseNumberAddition>'. $regexpHouseNumberAddition .'))?\s*$~', $streetData[0], $match))
234-
{
235-
// Found housenumber contained in first street line
236-
return array(
237-
'street' => $match['street'],
238-
'houseNumber' => $match['houseNumber'],
239-
'houseNumberAddition' => isset($match['houseNumberAddition']) ? $match['houseNumberAddition'] : null,
240-
);
241-
}
242-
else if (isset($streetData[1]))
243-
{
244-
// Find housenumber contained in second street line
245-
246-
$houseNumberData = $this->splitHouseNumber($streetData[1]);
247-
248-
return array(
249-
'street' => $streetData[0],
250-
'houseNumber' => $houseNumberData[0],
251-
'houseNumberAddition' => $houseNumberData[1],
252-
);
253-
}
254-
else
255-
{
256-
return array(
257-
'street' => $streetData[0],
258-
'houseNumber' => null,
259-
'houseNumberAddition' => null,
260-
);
261-
}
262-
}
263-
264-
protected function _addAccessIpAddress($access, $inputIp)
265-
{
266-
if ($inputIp === '' || $inputIp === null || $inputIp === false)
267-
return $access;
268-
269-
// input might be multiple IPs (from X-Forwarded-For, for example)
270-
if (strpos($inputIp, ',') !== false)
271-
{
272-
$inputIp = array_map('trim', explode(',', $inputIp));
273-
274-
foreach ($inputIp as $ip)
275-
$access = $this->_addAccessIpAddress($access, $ip);
276-
}
277-
else if (filter_var($inputIp, FILTER_VALIDATE_IP) && $inputIp !== $access['ipAddress'] && !in_array($inputIp, $access['additionalIpAddresses']))
278-
{
279-
$access['additionalIpAddresses'][] = $inputIp;
280-
}
281-
282-
return $access;
283-
}
284-
285200
protected function _getDebugInfo($url, $jsonData)
286201
{
287202
return array(
@@ -312,9 +227,9 @@ public function testConnection()
312227
$info = array();
313228

314229
// Do a test address lookup
315-
$this->setDebuggingOverride(true);
230+
$this->_setDebuggingOverride(true);
316231
$addressData = $this->lookupAddress('2012ES', '30', '');
317-
$this->setDebuggingOverride(false);
232+
$this->_setDebuggingOverride(false);
318233

319234
if (!isset($addressData['debugInfo']) && isset($addressData['message']))
320235
{
@@ -439,11 +354,8 @@ protected function _getMagentoVersion()
439354
// Detect professional
440355
return 'MagentoProfessional/'. Mage::getVersion();
441356
}
442-
else
443-
{
444-
// Rest
445-
return 'Magento/'. Mage::getVersion();
446-
}
357+
358+
return 'Magento/'. Mage::getVersion();
447359
}
448360

449361
protected function _getModuleInfo($moduleName)
@@ -468,8 +380,8 @@ protected function _getMagentoLookupUrl($inAdmin = false)
468380
{
469381
if ($inAdmin)
470382
return Mage::helper('adminhtml')->getUrl('*/pcnl/lookup', array('_secure' => true));
471-
else
472-
return Mage::getUrl('postcodenl_api/json', array('_secure' => true));
383+
384+
return Mage::getUrl('postcodenl_api/json', array('_secure' => true));
473385
}
474386

475387
protected function _curlHasSsl()
@@ -507,32 +419,12 @@ protected function _callApiUrlGet($url)
507419
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
508420
curl_setopt($ch, CURLOPT_USERPWD, $this->_getKey() .':'. $this->_getSecret());
509421
curl_setopt($ch, CURLOPT_USERAGENT, $this->_getUserAgent());
510-
$this->_httpResponseRaw = curl_exec($ch);
511-
$this->_httpResponseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
512-
$this->_httpResponseCodeClass = (int)floor($this->_httpResponseCode / 100) * 100;
513-
$this->_httpClientError = curl_errno($ch) ? sprintf('cURL error %s: %s', curl_errno($ch), curl_error($ch)) : null;
514-
515-
curl_close($ch);
516-
517-
return json_decode($this->_httpResponseRaw, true);
518-
}
519422

520-
protected function _callApiUrlPostJson($url, array $data)
521-
{
522-
$ch = curl_init();
523-
curl_setopt($ch, CURLOPT_URL, $url);
524-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
525-
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::API_TIMEOUT);
526-
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
527-
curl_setopt($ch, CURLOPT_USERPWD, $this->_getKey() .':'. $this->_getSecret());
528-
curl_setopt($ch, CURLOPT_USERAGENT, $this->_getUserAgent());
529-
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
530-
curl_setopt($ch, CURLOPT_POST, true);
531-
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
532423
$this->_httpResponseRaw = curl_exec($ch);
533424
$this->_httpResponseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
534425
$this->_httpResponseCodeClass = (int)floor($this->_httpResponseCode / 100) * 100;
535426
$this->_httpClientError = curl_errno($ch) ? sprintf('cURL error %s: %s', curl_errno($ch), curl_error($ch)) : null;
427+
536428
curl_close($ch);
537429

538430
return json_decode($this->_httpResponseRaw, true);

app/code/community/PostcodeNl/Api/etc/config.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@
7979
</postcodenl_api>
8080
</modules>
8181
</translate>
82+
<events>
83+
<admin_system_config_changed_section_postcodenl_api>
84+
<observers>
85+
<postcodenl_admin_change>
86+
<type>singleton</type>
87+
<class>PostcodeNl_Api_Model_Observer</class>
88+
<method>adminConfigurationChanged</method>
89+
</postcodenl_admin_change>
90+
</observers>
91+
</admin_system_config_changed_section_postcodenl_api>
92+
</events>
8293
</adminhtml>
8394
<default>
8495
<postcodenl_api>

0 commit comments

Comments
 (0)