Ejemplo n.º 1
0
 /**
  * @param string $entityType
  * @param object $entity
  * @return object
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entity)
 {
     if ($entity->getId()) {
         $stores = $this->resourceBlock->lookupStoreIds((int) $entity->getId());
         $entity->setData('store_id', $stores);
         $entity->setData('stores', $stores);
     }
     return $entity;
 }
Ejemplo n.º 2
0
 /**
  * @param string $entityType
  * @param object $entity
  * @param array $arguments
  * @return object
  * @throws \Exception
  */
 public function execute($entityType, $entity, $arguments = [])
 {
     $entityMetadata = $this->metadataPool->getMetadata($entityType);
     $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;
 }