|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Mageplaza |
| 4 | + * |
| 5 | + * NOTICE OF LICENSE |
| 6 | + * |
| 7 | + * This source file is subject to the Mageplaza.com license that is |
| 8 | + * available through the world-wide-web at this URL: |
| 9 | + * https://mageplaza.com/LICENSE.txt |
| 10 | + * |
| 11 | + * DISCLAIMER |
| 12 | + * |
| 13 | + * Do not edit or add to this file if you wish to upgrade this extension to newer |
| 14 | + * version in the future. |
| 15 | + * |
| 16 | + * @category Mageplaza |
| 17 | + * @package Mageplaza_Seo |
| 18 | + * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) |
| 19 | + * @license http://mageplaza.com/LICENSE.txt |
| 20 | + */ |
| 21 | + |
| 22 | +declare(strict_types=1); |
| 23 | + |
| 24 | +namespace Mageplaza\Seo\Setup\Patch\Data; |
| 25 | + |
| 26 | +use Magento\Catalog\Model\Category; |
| 27 | +use Magento\Catalog\Model\Product; |
| 28 | +use Magento\Eav\Setup\EavSetupFactory; |
| 29 | +use Magento\Framework\Setup\ModuleDataSetupInterface; |
| 30 | +use Magento\Framework\Setup\Patch\DataPatchInterface; |
| 31 | + |
| 32 | +/** |
| 33 | + * Patch is mechanism, that allows to do atomic upgrade data changes |
| 34 | + * Class RemoveAttribute |
| 35 | + * @package Mageplaza\Seo\Setup\Patch\Data |
| 36 | + */ |
| 37 | +class RemoveAttribute implements DataPatchInterface |
| 38 | +{ |
| 39 | + /** |
| 40 | + * @var ModuleDataSetupInterface $moduleDataSetup |
| 41 | + */ |
| 42 | + private $moduleDataSetup; |
| 43 | + |
| 44 | + /** |
| 45 | + * @var EavSetupFactory |
| 46 | + */ |
| 47 | + private $eavSetupFactory; |
| 48 | + |
| 49 | + /** |
| 50 | + * @param ModuleDataSetupInterface $moduleDataSetup |
| 51 | + * @param EavSetupFactory $eavSetupFactory |
| 52 | + */ |
| 53 | + public function __construct( |
| 54 | + ModuleDataSetupInterface $moduleDataSetup, |
| 55 | + EavSetupFactory $eavSetupFactory |
| 56 | + ) { |
| 57 | + $this->moduleDataSetup = $moduleDataSetup; |
| 58 | + $this->eavSetupFactory = $eavSetupFactory; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Do Upgrade |
| 63 | + * |
| 64 | + * @return void |
| 65 | + */ |
| 66 | + public function apply() |
| 67 | + { |
| 68 | + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); |
| 69 | + $this->removeAttribute($eavSetup, Product::ENTITY, 'mp_meta_robots'); |
| 70 | + $this->removeAttribute($eavSetup, Product::ENTITY, 'mp_seo_og_description'); |
| 71 | + $this->removeAttribute($eavSetup, Category::ENTITY, 'mp_meta_robots'); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @inheritdoc |
| 76 | + */ |
| 77 | + public function getAliases() |
| 78 | + { |
| 79 | + return []; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @inheritdoc |
| 84 | + */ |
| 85 | + public static function getDependencies() |
| 86 | + { |
| 87 | + return []; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * @return string |
| 92 | + */ |
| 93 | + public static function getVersion() |
| 94 | + { |
| 95 | + return '2.0.1'; |
| 96 | + } |
| 97 | + |
| 98 | + |
| 99 | + /** |
| 100 | + * Remove attribute |
| 101 | + * |
| 102 | + * @param $eavSetup |
| 103 | + * @param $model |
| 104 | + * @param $id |
| 105 | + */ |
| 106 | + private function removeAttribute($eavSetup, $model, $id) |
| 107 | + { |
| 108 | + if ($eavSetup->getAttributeId($model, $id)) { |
| 109 | + $eavSetup->removeAttribute($model, $id); |
| 110 | + } |
| 111 | + } |
| 112 | +} |
0 commit comments