|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Catalog\Setup; |
| 7 | + |
| 8 | +use Magento\Framework\Setup\UpgradeDataInterface; |
| 9 | +use Magento\Framework\Setup\ModuleContextInterface; |
| 10 | +use Magento\Framework\Setup\ModuleDataSetupInterface; |
| 11 | +use Magento\Catalog\Model\Category; |
| 12 | + |
| 13 | +/** |
| 14 | + * @codeCoverageIgnore |
| 15 | + */ |
| 16 | +class UpgradeData implements UpgradeDataInterface |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var Category |
| 20 | + */ |
| 21 | + protected $category; |
| 22 | + |
| 23 | + /** |
| 24 | + * @param Category $category |
| 25 | + */ |
| 26 | + public function __construct(Category $category) |
| 27 | + { |
| 28 | + $this->category = $category; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * {@inheritdoc} |
| 33 | + */ |
| 34 | + public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) |
| 35 | + { |
| 36 | + if (version_compare($context->getVersion(), '2.0.0.2') < 0) { |
| 37 | + $newBackendModel = 'Magento\Catalog\Model\Attribute\Backend\Startdate'; |
| 38 | + $connection = $setup->getConnection(); |
| 39 | + $connection->startSetup(); |
| 40 | + $connection->update( |
| 41 | + $setup->getTable('eav_attribute'), |
| 42 | + ['backend_model' => $newBackendModel], |
| 43 | + ['backend_model = ?' => 'Magento\Catalog\Model\Product\Attribute\Backend\Startdate'] |
| 44 | + ); |
| 45 | + /** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attribute */ |
| 46 | + foreach($this->category->getAttributes() as $attribute) { |
| 47 | + if ($attribute->getAttributeCode() == 'custom_design_from') { |
| 48 | + $attribute->setBackendModel($newBackendModel); |
| 49 | + $attribute->save(); |
| 50 | + break; |
| 51 | + } |
| 52 | + } |
| 53 | + $connection->endSetup(); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments