![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-cms/Model/ResourceModel/Page/Relation/Store/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Cms\Model\ResourceModel\Page\Relation\Store; use Magento\Framework\EntityManager\Operation\ExtensionInterface; use Magento\Cms\Api\Data\PageInterface; use Magento\Cms\Model\ResourceModel\Page; use Magento\Framework\EntityManager\MetadataPool; /** * Class SaveHandler */ class SaveHandler implements ExtensionInterface { /** * @var MetadataPool */ protected $metadataPool; /** * @var Page */ protected $resourcePage; /** * @param MetadataPool $metadataPool * @param Page $resourcePage */ public function __construct( MetadataPool $metadataPool, Page $resourcePage ) { $this->metadataPool = $metadataPool; $this->resourcePage = $resourcePage; } /** * @param object $entity * @param array $arguments * @return object * @throws \Exception */ public function execute($entity, $arguments = []) { $entityMetadata = $this->metadataPool->getMetadata(PageInterface::class); $linkField = $entityMetadata->getLinkField(); $connection = $entityMetadata->getEntityConnection(); $oldStores = $this->resourcePage->lookupStoreIds((int)$entity->getId()); $newStores = (array)$entity->getStores(); if (empty($newStores)) { $newStores = (array)$entity->getStoreId(); } $table = $this->resourcePage->getTable('cms_page_store'); $delete = array_diff($oldStores, $newStores); if ($delete) { $where = [ $linkField . ' = ?' => (int)$entity->getData($linkField), 'store_id IN (?)' => $delete, ]; $connection->delete($table, $where); } $insert = array_diff($newStores, $oldStores); if ($insert) { $data = []; foreach ($insert as $storeId) { $data[] = [ $linkField => (int)$entity->getData($linkField), 'store_id' => (int)$storeId ]; } $connection->insertMultiple($table, $data); } return $entity; } }