| 
 | 1 | +diff --git a/vendor/magento/module-catalog-permissions/Model/Indexer/Product/Action/GetProductsCategories.php b/vendor/magento/module-catalog-permissions/Model/Indexer/Product/Action/GetProductsCategories.php  | 
 | 2 | +new file mode 100644  | 
 | 3 | +index 00000000000..cf6bce34345  | 
 | 4 | +--- /dev/null  | 
 | 5 | ++++ b/vendor/magento/module-catalog-permissions/Model/Indexer/Product/Action/GetProductsCategories.php  | 
 | 6 | +@@ -0,0 +1,84 @@  | 
 | 7 | ++<?php  | 
 | 8 | ++/************************************************************************  | 
 | 9 | ++ *  | 
 | 10 | ++ * ADOBE CONFIDENTIAL  | 
 | 11 | ++ * ___________________  | 
 | 12 | ++ *  | 
 | 13 | ++ * Copyright 2023 Adobe  | 
 | 14 | ++ * All Rights Reserved.  | 
 | 15 | ++ *  | 
 | 16 | ++ * NOTICE: All information contained herein is, and remains  | 
 | 17 | ++ * the property of Adobe and its suppliers, if any. The intellectual  | 
 | 18 | ++ * and technical concepts contained herein are proprietary to Adobe  | 
 | 19 | ++ * and its suppliers and are protected by all applicable intellectual  | 
 | 20 | ++ * property laws, including trade secret and copyright laws.  | 
 | 21 | ++ * Dissemination of this information or reproduction of this material  | 
 | 22 | ++ * is strictly forbidden unless prior written permission is obtained  | 
 | 23 | ++ * from Adobe.  | 
 | 24 | ++ * ************************************************************************  | 
 | 25 | ++ */  | 
 | 26 | ++declare(strict_types=1);  | 
 | 27 | ++  | 
 | 28 | ++namespace Magento\CatalogPermissions\Model\Indexer\Product\Action;  | 
 | 29 | ++  | 
 | 30 | ++use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer as CategoryProductTableMaintainer;  | 
 | 31 | ++use Magento\Framework\App\ResourceConnection;  | 
 | 32 | ++use Magento\Store\Model\StoreManagerInterface;  | 
 | 33 | ++  | 
 | 34 | ++class GetProductsCategories  | 
 | 35 | ++{  | 
 | 36 | ++    /**  | 
 | 37 | ++     * @var ResourceConnection  | 
 | 38 | ++     */  | 
 | 39 | ++    private $resource;  | 
 | 40 | ++  | 
 | 41 | ++    /**  | 
 | 42 | ++     * @var CategoryProductTableMaintainer  | 
 | 43 | ++     */  | 
 | 44 | ++    private $categoryProductTableMaintainer;  | 
 | 45 | ++  | 
 | 46 | ++    /**  | 
 | 47 | ++     * @var StoreManagerInterface  | 
 | 48 | ++     */  | 
 | 49 | ++    private $storeManager;  | 
 | 50 | ++  | 
 | 51 | ++    /**  | 
 | 52 | ++     * @param ResourceConnection $resource  | 
 | 53 | ++     * @param CategoryProductTableMaintainer $categoryProductTableMaintainer  | 
 | 54 | ++     * @param StoreManagerInterface $storeManager  | 
 | 55 | ++     */  | 
 | 56 | ++    public function __construct(  | 
 | 57 | ++        ResourceConnection $resource,  | 
 | 58 | ++        CategoryProductTableMaintainer $categoryProductTableMaintainer,  | 
 | 59 | ++        StoreManagerInterface $storeManager  | 
 | 60 | ++    ) {  | 
 | 61 | ++        $this->resource = $resource;  | 
 | 62 | ++        $this->categoryProductTableMaintainer = $categoryProductTableMaintainer;  | 
 | 63 | ++        $this->storeManager = $storeManager;  | 
 | 64 | ++    }  | 
 | 65 | ++  | 
 | 66 | ++    /**  | 
 | 67 | ++     * Returns list of categories ids for provided products  | 
 | 68 | ++     *  | 
 | 69 | ++     * @param int[] $productList  | 
 | 70 | ++     * @return array  | 
 | 71 | ++     */  | 
 | 72 | ++    public function execute(  | 
 | 73 | ++        array $productList  | 
 | 74 | ++    ): array {  | 
 | 75 | ++        $connection = $this->resource->getConnection();  | 
 | 76 | ++        $categories = [];  | 
 | 77 | ++        foreach ($this->storeManager->getStores() as $store) {  | 
 | 78 | ++            $select = $connection->select()->from(  | 
 | 79 | ++                ['category_product_index' => $this->categoryProductTableMaintainer->getMainTable((int)$store->getId())],  | 
 | 80 | ++                ['category_product_index.category_id']  | 
 | 81 | ++            );  | 
 | 82 | ++            $select->where('category_product_index.product_id IN (?)', $productList, \Zend_Db::INT_TYPE);  | 
 | 83 | ++            $select->distinct(true);  | 
 | 84 | ++  | 
 | 85 | ++            $categories += array_fill_keys($connection->fetchCol($select), true);  | 
 | 86 | ++        }  | 
 | 87 | ++  | 
 | 88 | ++        return array_keys($categories);  | 
 | 89 | ++    }  | 
 | 90 | ++}  | 
 | 91 | +diff --git a/vendor/magento/module-catalog-permissions/Model/Indexer/Product/Action/Rows.php b/vendor/magento/module-catalog-permissions/Model/Indexer/Product/Action/Rows.php  | 
 | 92 | +index a08a297570b..7cf01aad9eb 100644  | 
 | 93 | +--- a/vendor/magento/module-catalog-permissions/Model/Indexer/Product/Action/Rows.php  | 
 | 94 | ++++ b/vendor/magento/module-catalog-permissions/Model/Indexer/Product/Action/Rows.php  | 
 | 95 | +@@ -5,7 +5,24 @@  | 
 | 96 | +  */  | 
 | 97 | + namespace Magento\CatalogPermissions\Model\Indexer\Product\Action;  | 
 | 98 | +   | 
 | 99 | ++use Magento\Catalog\Model\Category;  | 
 | 100 | ++use Magento\Catalog\Model\Config as CatalogConfig;  | 
 | 101 | ++use Magento\Catalog\Model\Product;  | 
 | 102 | ++use Magento\CatalogPermissions\App\ConfigInterface;  | 
 | 103 | + use Magento\CatalogPermissions\Model\Indexer\AbstractAction;  | 
 | 104 | ++use Magento\CatalogPermissions\Model\Indexer\Category\ModeSwitcher;  | 
 | 105 | ++use Magento\CatalogPermissions\Model\Indexer\TableMaintainer;  | 
 | 106 | ++use Magento\Customer\Model\ResourceModel\Group\CollectionFactory as GroupCollectionFactory;  | 
 | 107 | ++use Magento\Framework\App\CacheInterface;  | 
 | 108 | ++use Magento\Framework\App\Config\ScopeConfigInterface;  | 
 | 109 | ++use Magento\Framework\App\ObjectManager;  | 
 | 110 | ++use Magento\Framework\App\ResourceConnection;  | 
 | 111 | ++use Magento\Framework\DB\Query\Generator;  | 
 | 112 | ++use Magento\Framework\EntityManager\MetadataPool;  | 
 | 113 | ++use Magento\Framework\Indexer\CacheContext;  | 
 | 114 | ++use Magento\Store\Model\ResourceModel\Website\CollectionFactory as WebsiteCollectionFactory;  | 
 | 115 | ++use Magento\CatalogPermissions\Model\Indexer\Product\IndexFiller as ProductIndexFiller;  | 
 | 116 | ++use Magento\Store\Model\StoreManagerInterface;  | 
 | 117 | +   | 
 | 118 | + /**  | 
 | 119 | +  * @api  | 
 | 120 | +@@ -20,6 +37,76 @@ class Rows extends AbstractAction  | 
 | 121 | +      */  | 
 | 122 | +     protected $entityIds;  | 
 | 123 | +   | 
 | 124 | ++    /**  | 
 | 125 | ++     * @var ScopeConfigInterface  | 
 | 126 | ++     */  | 
 | 127 | ++    private $scopeConfig;  | 
 | 128 | ++  | 
 | 129 | ++    /**  | 
 | 130 | ++     * @var CacheContext  | 
 | 131 | ++     */  | 
 | 132 | ++    private $cacheContext;  | 
 | 133 | ++  | 
 | 134 | ++    /**  | 
 | 135 | ++     * @var GetProductsCategories  | 
 | 136 | ++     */  | 
 | 137 | ++    private $getProductsCategories;  | 
 | 138 | ++  | 
 | 139 | ++    /**  | 
 | 140 | ++     * @param ResourceConnection $resource  | 
 | 141 | ++     * @param WebsiteCollectionFactory $websiteCollectionFactory  | 
 | 142 | ++     * @param GroupCollectionFactory $groupCollectionFactory  | 
 | 143 | ++     * @param ConfigInterface $config  | 
 | 144 | ++     * @param StoreManagerInterface $storeManager  | 
 | 145 | ++     * @param CatalogConfig $catalogConfig  | 
 | 146 | ++     * @param CacheInterface $coreCache  | 
 | 147 | ++     * @param MetadataPool $metadataPool  | 
 | 148 | ++     * @param Generator|null $batchQueryGenerator  | 
 | 149 | ++     * @param ProductSelectDataProvider|null $productSelectDataProvider  | 
 | 150 | ++     * @param ProductIndexFiller|null $productIndexFiller  | 
 | 151 | ++     * @param TableMaintainer|null $tableMaintainer  | 
 | 152 | ++     * @param ScopeConfigInterface|null $scopeConfig  | 
 | 153 | ++     * @param CacheContext|null $cacheContext  | 
 | 154 | ++     * @param GetProductsCategories|null $getProductsCategories  | 
 | 155 | ++     * @throws \Exception  | 
 | 156 | ++     * @SuppressWarnings(PHPMD.ExcessiveParameterList)  | 
 | 157 | ++     */  | 
 | 158 | ++    public function __construct(  | 
 | 159 | ++        ResourceConnection $resource,  | 
 | 160 | ++        WebsiteCollectionFactory $websiteCollectionFactory,  | 
 | 161 | ++        GroupCollectionFactory $groupCollectionFactory,  | 
 | 162 | ++        ConfigInterface $config,  | 
 | 163 | ++        StoreManagerInterface $storeManager,  | 
 | 164 | ++        CatalogConfig $catalogConfig,  | 
 | 165 | ++        CacheInterface $coreCache,  | 
 | 166 | ++        \Magento\Framework\EntityManager\MetadataPool $metadataPool,  | 
 | 167 | ++        Generator $batchQueryGenerator = null,  | 
 | 168 | ++        ProductSelectDataProvider $productSelectDataProvider = null,  | 
 | 169 | ++        ProductIndexFiller $productIndexFiller = null,  | 
 | 170 | ++        ?CacheContext $cacheContext = null,  | 
 | 171 | ++        ?GetProductsCategories $getProductsCategories = null  | 
 | 172 | ++    ) {  | 
 | 173 | ++        parent::__construct(  | 
 | 174 | ++            $resource,  | 
 | 175 | ++            $websiteCollectionFactory,  | 
 | 176 | ++            $groupCollectionFactory,  | 
 | 177 | ++            $config,  | 
 | 178 | ++            $storeManager,  | 
 | 179 | ++            $catalogConfig,  | 
 | 180 | ++            $coreCache,  | 
 | 181 | ++            $metadataPool,  | 
 | 182 | ++            $batchQueryGenerator,  | 
 | 183 | ++            $productSelectDataProvider,  | 
 | 184 | ++            $productIndexFiller  | 
 | 185 | ++        );  | 
 | 186 | ++        $this->scopeConfig = $scopeConfig  | 
 | 187 | ++            ??ObjectManager::getInstance()->get(ScopeConfigInterface::class);  | 
 | 188 | ++        $this->cacheContext = $cacheContext  | 
 | 189 | ++            ?? ObjectManager::getInstance()->get(CacheContext::class);  | 
 | 190 | ++        $this->getProductsCategories = $getProductsCategories  | 
 | 191 | ++            ?? ObjectManager::getInstance()->get(GetProductsCategories::class);  | 
 | 192 | ++    }  | 
 | 193 | ++  | 
 | 194 | +     /**  | 
 | 195 | +      * Refresh entities index  | 
 | 196 | +      *  | 
 | 197 | +@@ -36,6 +123,14 @@ class Rows extends AbstractAction  | 
 | 198 | +             $this->removeObsoleteIndexData();  | 
 | 199 | +   | 
 | 200 | +             $this->reindex();  | 
 | 201 | ++            $this->cacheContext->registerEntities(  | 
 | 202 | ++                Product::CACHE_TAG,  | 
 | 203 | ++                $entityIds  | 
 | 204 | ++            );  | 
 | 205 | ++            $this->cacheContext->registerEntities(  | 
 | 206 | ++                Category::CACHE_TAG,  | 
 | 207 | ++                $this->getProductsCategories->execute($entityIds)  | 
 | 208 | ++            );  | 
 | 209 | +         }  | 
 | 210 | +     }  | 
 | 211 | +   | 
0 commit comments