![]() 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/Block/Relation/Store/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Cms\Model\ResourceModel\Block\Relation\Store; use Magento\Framework\EntityManager\Operation\ExtensionInterface; use Magento\Cms\Api\Data\BlockInterface; use Magento\Cms\Model\ResourceModel\Block; use Magento\Framework\EntityManager\MetadataPool; /** * Class SaveHandler */ class SaveHandler implements ExtensionInterface { /** * @var MetadataPool */ protected $metadataPool; /** * @var Block */ protected $resourceBlock; /** * @param MetadataPool $metadataPool * @param Block $resourceBlock */ public function __construct( MetadataPool $metadataPool, Block $resourceBlock ) { $this->metadataPool = $metadataPool; $this->resourceBlock = $resourceBlock; } /** * @param object $entity * @param array $arguments * @return object * @throws \Exception */ public function execute($entity, $arguments = []) { $entityMetadata = $this->metadataPool->getMetadata(BlockInterface::class); $linkField = $entityMetadata->getLinkField(); $connection = $entityMetadata->getEntityConnection(); $oldStores = $this->resourceBlock->lookupStoreIds((int)$entity->getId()); $newStores = (array)$entity->getStores(); $table = $this->resourceBlock->getTable('cms_block_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; } }