/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/Model/ResourceModel/Db/CreateEntityRow.php
77 строк
2 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
22 окт 2025, 17:47
22 окт 2025, 17:47
1b769b7
Код
Авторство
О чём код?
<?php /** * Copyright 2015 Adobe * All Rights Reserved. */ namespace Magento\Framework\Model\ResourceModel\Db; use Magento\Framework\EntityManager\EntityMetadata; use Magento\Framework\EntityManager\MetadataPool; /** * Class ReadEntityRow */ class CreateEntityRow { /** * @var MetadataPool */ protected $metadataPool; /** * @param MetadataPool $metadataPool */ public function __construct( MetadataPool $metadataPool ) { $this->metadataPool = $metadataPool; } /** * Prepare data. * * @param EntityMetadata $metadata * @param array $data * @return array */ protected function prepareData(EntityMetadata $metadata, $data) { $output = []; foreach ($metadata->getEntityConnection()->describeTable($metadata->getEntityTable()) as $column) { if ($column['DEFAULT'] == 'CURRENT_TIMESTAMP') { continue; } if (isset($data[strtolower($column['COLUMN_NAME'])])) { $output[strtolower($column['COLUMN_NAME'])] = $data[strtolower($column['COLUMN_NAME'])]; } elseif ($column['DEFAULT'] === null) { $output[strtolower($column['COLUMN_NAME'])] = null; } } if (empty($data[$metadata->getIdentifierField()])) { $output[$metadata->getIdentifierField()] = $metadata->generateIdentifier(); } return $output; } /** * Create entity row. * * @param string $entityType * @param array $data * @return array */ public function execute($entityType, $data) { $metadata = $this->metadataPool->getMetadata($entityType); $linkField = $metadata->getLinkField(); $entityTable = $metadata->getEntityTable(); $connection = $metadata->getEntityConnection(); $connection->insert($entityTable, $this->prepareData($metadata, $data)); $data[$linkField] = $connection->lastInsertId($entityTable); return $data; } }