/** * Retrieve Attribute Data By Id or Code * * @param int|string $entityTypeId * @param int|string $id * @param string $field * @return mixed */ public function getAttribute($entityTypeId, $id, $field = null) { $additionalTable = $this->getEntityType($entityTypeId, 'additional_attribute_table'); $entityTypeId = $this->getEntityTypeId($entityTypeId); $idField = is_numeric($id) ? 'attribute_id' : 'attribute_code'; if (!$additionalTable) { return $this->setup->getTableRow('eav_attribute', $idField, $id, $field, 'entity_type_id', $entityTypeId); } $mainTable = $this->setup->getTable('eav_attribute'); $setupCache = $this->setup->getSetupCache(); if (!$setupCache->has($mainTable, $entityTypeId, $id)) { $additionalTable = $this->setup->getTable($additionalTable); $bind = ['id' => $id, 'entity_type_id' => $entityTypeId]; $select = $this->setup->getConnection()->select()->from(['main' => $mainTable])->join(['additional' => $additionalTable], 'main.attribute_id = additional.attribute_id')->where("main.{$idField} = :id")->where('main.entity_type_id = :entity_type_id'); $row = $this->setup->getConnection()->fetchRow($select, $bind); if (!$row) { $setupCache->setRow($mainTable, $entityTypeId, $id, []); } else { $setupCache->setRow($mainTable, $entityTypeId, $row['attribute_id'], $row); $setupCache->setRow($mainTable, $entityTypeId, $row['attribute_code'], $row); } } $row = $setupCache->get($mainTable, $entityTypeId, $id); if ($field !== null) { return isset($row[$field]) ? $row[$field] : false; } return $row; }
/** * @covers \Magento\Setup\Module\DataSetup::updateTableRow * @expectedException \Zend_Db_Statement_Exception */ public function testUpdateTableRowNameConversion() { $original = $this->_model->getTableRow('setup_module', 'module', 'core_setup', 'schema_version'); $this->_model->updateTableRow('setup/module', 'module', 'core_setup', 'schema_version', $original); }