|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magefan (support@magefan.com). All rights reserved. |
| 4 | + * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magefan\HtmlSitemap\Setup\Patch\Data; |
| 10 | + |
| 11 | +use Magento\Cms\Model\ResourceModel\Page\CollectionFactory as PageCollectionFactory; |
| 12 | +use Magento\Framework\Setup\ModuleDataSetupInterface; |
| 13 | +use Magento\Framework\Setup\Patch\DataPatchInterface; |
| 14 | +use Magento\Framework\Setup\Patch\PatchRevertableInterface; |
| 15 | + |
| 16 | +class PageToExclude implements DataPatchInterface, PatchRevertableInterface |
| 17 | +{ |
| 18 | + |
| 19 | + /** |
| 20 | + * @var ModuleDataSetupInterface |
| 21 | + */ |
| 22 | + private $moduleDataSetup; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var PageCollectionFactory |
| 26 | + */ |
| 27 | + private $pageCollectionFactory; |
| 28 | + |
| 29 | + /** |
| 30 | + * @param ModuleDataSetupInterface $moduleDataSetup |
| 31 | + * @param PageCollectionFactory $pageCollectionFactory |
| 32 | + */ |
| 33 | + public function __construct( |
| 34 | + ModuleDataSetupInterface $moduleDataSetup, |
| 35 | + PageCollectionFactory $pageCollectionFactory |
| 36 | + ) |
| 37 | + { |
| 38 | + $this->moduleDataSetup = $moduleDataSetup; |
| 39 | + $this->pageCollectionFactory = $pageCollectionFactory; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @return void |
| 44 | + */ |
| 45 | + public function apply() |
| 46 | + { |
| 47 | + $this->moduleDataSetup->getConnection()->startSetup(); |
| 48 | + |
| 49 | + $pageCollection = $this->pageCollectionFactory->create(); |
| 50 | + |
| 51 | + $pageCollection->addFieldToFilter('identifier', ['in' => ['no-route', 'home', 'enable-cookies']]); |
| 52 | + |
| 53 | + foreach ($pageCollection as $page) { |
| 54 | + $page->setMfExcludeHtmlSitemap(1); |
| 55 | + } |
| 56 | + |
| 57 | + $pageCollection->save(); |
| 58 | + |
| 59 | + $this->moduleDataSetup->getConnection()->endSetup(); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Revert function |
| 64 | + */ |
| 65 | + public function revert() |
| 66 | + { |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * {@inheritdoc} |
| 71 | + */ |
| 72 | + public function getAliases() |
| 73 | + { |
| 74 | + return []; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * {@inheritdoc} |
| 79 | + */ |
| 80 | + public static function getDependencies() |
| 81 | + { |
| 82 | + return []; |
| 83 | + } |
| 84 | +} |
| 85 | + |
0 commit comments