UpgradeData.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Payment\Setup;
  17. use Magento\Eav\Setup\EavSetupFactory;
  18. use Magento\Framework\Exception\LocalizedException;
  19. use Magento\Framework\Setup\ModuleContextInterface;
  20. use Magento\Framework\Setup\ModuleDataSetupInterface;
  21. use Magento\Framework\Setup\UpgradeDataInterface;
  22. class UpgradeData implements UpgradeDataInterface
  23. {
  24. /**
  25. * @var EavSetupFactory
  26. */
  27. private $eavSetupFactory;
  28. /**
  29. * @param EavSetupFactory $eavSetupFactory
  30. */
  31. public function __construct(EavSetupFactory $eavSetupFactory)
  32. {
  33. $this->eavSetupFactory = $eavSetupFactory;
  34. }
  35. public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
  36. {
  37. if (version_compare($context->getVersion(), '1.5.0', '<')) {
  38. $this->upgradeAddressStreetMultiline($setup);
  39. }
  40. }
  41. /**
  42. * @throws LocalizedException
  43. * @return void
  44. */
  45. private function upgradeAddressStreetMultiline(ModuleDataSetupInterface $setup)
  46. {
  47. $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
  48. $row = $eavSetup->getAttribute('customer_address', 'street', 'multiline_count');
  49. if ($row === false || ! is_numeric($row)) {
  50. throw new LocalizedException(__('Could not find the "multiline_count" config of the "street" ' .
  51. 'Customer address attribute.'));
  52. }
  53. if ($row < 3) {
  54. $eavSetup->updateAttribute('customer_address', 'street', 'multiline_count', 3);
  55. }
  56. }
  57. }