Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateEntityRow.php
Go to the documentation of this file.
1 <?php
8 
11 
16 {
20  protected $metadataPool;
21 
25  public function __construct(
27  ) {
28  $this->metadataPool = $metadataPool;
29  }
30 
36  protected function prepareData(EntityMetadata $metadata, $data)
37  {
38  $output = [];
39  foreach ($metadata->getEntityConnection()->describeTable($metadata->getEntityTable()) as $column) {
40  if ($column['DEFAULT'] == 'CURRENT_TIMESTAMP' || $column['IDENTITY']) {
41  continue;
42  }
43  if (array_key_exists(strtolower($column['COLUMN_NAME']), $data)) {
44  $output[strtolower($column['COLUMN_NAME'])] = $data[strtolower($column['COLUMN_NAME'])];
45  }
46  }
47  return $output;
48  }
49 
56  public function execute($entityType, $data)
57  {
58  $metadata = $this->metadataPool->getMetadata($entityType);
59  $connection = $metadata->getEntityConnection();
60  return $connection->update(
61  $metadata->getEntityTable(),
62  $this->prepareData($metadata, $data),
63  [$metadata->getLinkField() . ' = ?' => $data[$metadata->getLinkField()]]
64  );
65  }
66 }
$connection
Definition: bulk.php:13