Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpgradePasswordHashAndAddress.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Customer\Setup\CustomerSetupFactory;
15 
21 {
25  private $moduleDataSetup;
26 
30  private $customerSetupFactory;
31 
37  public function __construct(
38  ModuleDataSetupInterface $moduleDataSetup,
39  CustomerSetupFactory $customerSetupFactory
40  ) {
41  $this->moduleDataSetup = $moduleDataSetup;
42  $this->customerSetupFactory = $customerSetupFactory;
43  }
44 
48  public function apply()
49  {
50  $this->upgradeHash();
51  $entityAttributes = [
52  'customer_address' => [
53  'fax' => [
54  'is_visible' => false,
55  'is_system' => false,
56  ],
57  ],
58  ];
59  $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
60  $customerSetup->upgradeAttributes($entityAttributes);
61  }
62 
66  private function upgradeHash()
67  {
68  $customerEntityTable = $this->moduleDataSetup->getTable('customer_entity');
69 
70  $select = $this->moduleDataSetup->getConnection()->select()->from(
71  $customerEntityTable,
72  ['entity_id', 'password_hash']
73  );
74 
75  $customers = $this->moduleDataSetup->getConnection()->fetchAll($select);
76  foreach ($customers as $customer) {
77  if ($customer['password_hash'] === null) {
78  continue;
79  }
80  list($hash, $salt) = explode(Encryptor::DELIMITER, $customer['password_hash']);
81 
82  $newHash = $customer['password_hash'];
83  if (strlen($hash) === 32) {
84  $newHash = implode(Encryptor::DELIMITER, [$hash, $salt, Encryptor::HASH_VERSION_MD5]);
85  } elseif (strlen($hash) === 64) {
86  $newHash = implode(Encryptor::DELIMITER, [$hash, $salt, Encryptor::HASH_VERSION_SHA256]);
87  }
88 
89  $bind = ['password_hash' => $newHash];
90  $where = ['entity_id = ?' => (int)$customer['entity_id']];
91  $this->moduleDataSetup->getConnection()->update($customerEntityTable, $bind, $where);
92  }
93  }
94 
98  public static function getDependencies()
99  {
100  return [
101  AddCustomerUpdatedAtAttribute::class,
102  ];
103  }
104 
108  public static function getVersion()
109  {
110  return '2.0.5';
111  }
112 
116  public function getAliases()
117  {
118  return [];
119  }
120 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$customer
Definition: customers.php:11
__construct(ModuleDataSetupInterface $moduleDataSetup, CustomerSetupFactory $customerSetupFactory)