Skip to content

Commit da1f610

Browse files
committed
MAGETWO-66328: Remove usages of serialize/unserialize in CustomerSampleData
- Convert install code to JSON serializer and change csv data to JSON array - Fix minor docblock issues - Fix bug in di.xml that breaks installation
1 parent f82a1f5 commit da1f610

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

app/code/Magento/CustomerSampleData/Model/Customer.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66
namespace Magento\CustomerSampleData\Model;
77

8-
use Magento\Framework\Setup\SampleData\Context as SampleDataContext;
98
use Magento\Customer\Api\Data\RegionInterface;
9+
use Magento\Framework\Serialize\Serializer\Json;
10+
use Magento\Framework\Setup\SampleData\Context as SampleDataContext;
1011

1112
/**
12-
* Class Customer
1313
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1414
*/
1515
class Customer
@@ -50,12 +50,12 @@ class Customer
5050
protected $accountManagement;
5151

5252
/**
53-
* @var array $customerDataProfile
53+
* @var array
5454
*/
5555
protected $customerDataProfile;
5656

5757
/**
58-
* @var array $customerDataAddress
58+
* @var array
5959
*/
6060
protected $customerDataAddress;
6161

@@ -69,9 +69,16 @@ class Customer
6969
*/
7070
protected $dataObjectHelper;
7171

72-
72+
/**
73+
* @var \Magento\Framework\App\State
74+
*/
7375
protected $appState;
7476

77+
/**
78+
* @var Json
79+
*/
80+
private $serializer;
81+
7582
/**
7683
* @param SampleDataContext $sampleDataContext
7784
* @param \Magento\Directory\Model\CountryFactory $countryFactory
@@ -82,6 +89,7 @@ class Customer
8289
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
8390
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
8491
* @param \Magento\Framework\App\State $appState
92+
* @param Json $serializer
8593
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8694
*/
8795
public function __construct(
@@ -93,7 +101,8 @@ public function __construct(
93101
\Magento\Customer\Api\AccountManagementInterface $accountManagement,
94102
\Magento\Store\Model\StoreManagerInterface $storeManager,
95103
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
96-
\Magento\Framework\App\State $appState
104+
\Magento\Framework\App\State $appState,
105+
Json $serializer = null
97106
) {
98107
$this->fixtureManager = $sampleDataContext->getFixtureManager();
99108
$this->csvReader = $sampleDataContext->getCsvReader();
@@ -105,10 +114,13 @@ public function __construct(
105114
$this->storeManager = $storeManager;
106115
$this->dataObjectHelper = $dataObjectHelper;
107116
$this->appState = $appState;
117+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Json::class);
108118
}
109119

110120
/**
111-
* {@inheritdoc}
121+
* Loop through list of fixture files and install sample data
122+
*
123+
* @param string[] $fixtures
112124
*/
113125
public function install($fixtures)
114126
{
@@ -237,7 +249,7 @@ protected function convertRowData($row, $data)
237249
foreach ($row as $field => $value) {
238250
if (isset($data[$field])) {
239251
if ($field == 'street') {
240-
$data[$field] = unserialize($value);
252+
$data[$field] = $this->serializer->unserialize($value);
241253
continue;
242254
}
243255
if ($field == 'password') {

app/code/Magento/CustomerSampleData/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9-
<type name="\Magento\Framework\Mail\TransportInterface">
9+
<type name="Magento\Framework\Mail\TransportInterface">
1010
<plugin name="customer-sample-data-disable-registration-email-send" type="Magento\CustomerSampleData\Magento\Framework\Mail\Transport\MailPlugin"/>
1111
</type>
1212
</config>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
firstname,lastname,email,password,dob,gender,street,city,region,country_id,postcode,telephone
2-
Veronica,Costello,"[email protected]","[email protected]","1973-12-15",2,"a:2:{i:0;s:24:""6146 Honey Bluff Parkway"";i:1;s:0:"""";}",Calder,Michigan,US,"49628-7978","(555) 229-3326"
2+
Veronica,Costello,"[email protected]","[email protected]","1973-12-15",2,"[""6146 Honey Bluff Parkway"",""""]",Calder,Michigan,US,"49628-7978","(555) 229-3326"

0 commit comments

Comments
 (0)