Skip to content

Commit 2406e43

Browse files
author
Victor Rad
committed
MAGETWO-47803: [Github] Error appears while IP convertation magento#33
1 parent 50e4834 commit 2406e43

File tree

4 files changed

+12
-26
lines changed

4 files changed

+12
-26
lines changed

etc/ee-to-ee/1.14.2.0/map.xml.dist

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,9 +1320,7 @@
13201320
</transform>
13211321
<transform>
13221322
<field>enterprise_logging_event.x_forwarded_ip</field>
1323-
<handler class="Migration\Handler\ConvertIp">
1324-
<param name="isIpPacked" value="0"/>
1325-
</handler>
1323+
<handler class="Migration\Handler\ConvertIp"/>
13261324
</transform>
13271325
<transform>
13281326
<field>rating_option_vote.remote_ip_long</field>

etc/ee-to-ee/1.14.2.1/map.xml.dist

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,9 +1320,7 @@
13201320
</transform>
13211321
<transform>
13221322
<field>enterprise_logging_event.x_forwarded_ip</field>
1323-
<handler class="Migration\Handler\ConvertIp">
1324-
<param name="isIpPacked" value="0"/>
1325-
</handler>
1323+
<handler class="Migration\Handler\ConvertIp"/>
13261324
</transform>
13271325
<transform>
13281326
<field>rating_option_vote.remote_ip_long</field>

etc/ee-to-ee/1.14.2.2/map.xml.dist

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,9 +1326,7 @@
13261326
</transform>
13271327
<transform>
13281328
<field>enterprise_logging_event.x_forwarded_ip</field>
1329-
<handler class="Migration\Handler\ConvertIp">
1330-
<param name="isIpPacked" value="0"/>
1331-
</handler>
1329+
<handler class="Migration\Handler\ConvertIp"/>
13321330
</transform>
13331331
<transform>
13341332
<field>rating_option_vote.remote_ip_long</field>

src/Migration/Handler/ConvertIp.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@
1212
*/
1313
class ConvertIp extends AbstractHandler implements HandlerInterface
1414
{
15-
/**
16-
* @var null
17-
*/
18-
protected $isIpPacked = null;
19-
20-
/**
21-
* @param int $isIpPacked
22-
*/
23-
public function __construct($isIpPacked = 1)
24-
{
25-
$this->isIpPacked = $isIpPacked;
26-
}
27-
2815
/**
2916
* {@inheritdoc}
3017
*/
@@ -33,11 +20,16 @@ public function handle(Record $recordToHandle, Record $oppositeRecord)
3320
$this->validate($recordToHandle);
3421

3522
$value = $recordToHandle->getValue($this->field);
36-
if (!$value) {
37-
$recordToHandle->setValue($this->field, 0);
38-
return;
23+
if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)
24+
|| filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)
25+
) {
26+
$newValue = (int) ip2long($value);
27+
} else if (@inet_ntop($value) !== false) {
28+
$newValue = (int) ip2long(inet_ntop($value));
29+
} else {
30+
$newValue = 0;
3931
}
40-
$newValue = $this->isIpPacked ? ip2long(inet_ntop($value)) : ip2long($value);
32+
4133
$recordToHandle->setValue($this->field, $newValue);
4234
}
4335
}

0 commit comments

Comments
 (0)