UpdateDefaultAttributeValue.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Catalog\Setup\Patch\Data;
  7. use Magento\Catalog\Setup\CategorySetup;
  8. use Magento\Catalog\Setup\CategorySetupFactory;
  9. use Magento\Framework\App\ResourceConnection;
  10. use Magento\Framework\Setup\ModuleDataSetupInterface;
  11. use Magento\Framework\Setup\Patch\DataPatchInterface;
  12. use Magento\Framework\Setup\Patch\PatchVersionInterface;
  13. /**
  14. * Class UpdateDefaultAttributeValue
  15. * @package Magento\Catalog\Setup\Patch
  16. */
  17. class UpdateDefaultAttributeValue implements DataPatchInterface, PatchVersionInterface
  18. {
  19. /**
  20. * @var ModuleDataSetupInterface
  21. */
  22. private $moduleDataSetup;
  23. /**
  24. * @var CategorySetupFactory
  25. */
  26. private $categorySetupFactory;
  27. /**
  28. * PatchInitial constructor.
  29. * @param ModuleDataSetupInterface $moduleDataSetup
  30. * @param CategorySetupFactory $categorySetupFactory
  31. */
  32. public function __construct(
  33. ModuleDataSetupInterface $moduleDataSetup,
  34. CategorySetupFactory $categorySetupFactory
  35. ) {
  36. $this->moduleDataSetup = $moduleDataSetup;
  37. $this->categorySetupFactory = $categorySetupFactory;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function apply()
  43. {
  44. /** @var CategorySetup $categorySetup */
  45. $categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
  46. $categorySetup->updateAttribute(3, 54, 'default_value', 1);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public static function getDependencies()
  52. {
  53. return [
  54. SetNewResourceModelsPaths::class,
  55. ];
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public static function getVersion()
  61. {
  62. return '2.0.3';
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function getAliases()
  68. {
  69. return [];
  70. }
  71. }