/** * 2015-10-10 * @param string $name * @param string $label * @return void */ protected final function attribute($name, $label) { /** @var int $ordering */ static $ordering = 1000; df_eav_setup()->addAttribute('customer', $name, ['type' => 'static', 'label' => "{$this->labelPrefix()} {$label}", 'input' => 'text', 'sort_order' => $ordering, 'position' => $ordering++, 'visible' => false, 'system' => false, 'required' => false]); /** @var int $attributeId */ $attributeId = df_first(df_fetch_col('eav_attribute', 'attribute_id', 'attribute_code', $name)); df_conn()->insert(df_table('customer_form_attribute'), ['form_code' => 'adminhtml_customer', 'attribute_id' => $attributeId]); }
/** * 2015-04-12 * @used-by df_table_delete_not() * @used-by Df_Bundle_Model_Resource_Bundle::deleteAllOptions() * @used-by Df_Tax_Setup_3_0_0::customerClassId() * @used-by Df_Tax_Setup_3_0_0::deleteDemoData() * @used-by Df_Cms_Model_Resource_Hierarchy_Node::deleteNodesByPageId() * @used-by Df_Cms_Model_Resource_Hierarchy_Node::dropNodes() * @used-by Df_Directory_Setup_Processor_InstallRegions::regionsDelete() * @used-by Df_PromoGift_Model_Resource_Indexer::deleteGiftsForProduct() * @used-by Df_PromoGift_Model_Resource_Indexer::deleteGiftsForRule() * @used-by Df_PromoGift_Model_Resource_Indexer::deleteGiftsForWebsite() * @used-by Df_Reward_Setup_1_0_0::_process() * @used-by Df_YandexMarket_Setup_2_42_1::_process() * @param string $table * @param string $columnName * @param int|string|int[]|string[] $values * @param bool $not [optional] * @return void */ function df_table_delete($table, $columnName, $values, $not = false) { /** @var string $condition */ $condition = df_sql_predicate_simple($values, $not); df_conn()->delete(df_table($table), ["{$columnName} {$condition}" => $values]); }
/** * 2016-06-05 * @return string */ private function table() { return df_table('customer_entity'); }
/** * 2016-11-04 * «How to rename a database column?» https://mage2.pro/t/2240 * Unfortunatyly, MySQL does not allow to rename a database column * without repeating the column's definition: http://stackoverflow.com/questions/8553130 * The Magento 2 core classes do not have such method too. * So, we implement such function ourself. * @param string $table * @param string $from The column should exist in the table! * @param string $to * @return void */ function df_db_column_rename($table, $from, $to) { /** * 2016-11-04 * @uses df_table() call is required here, * because @uses \Magento\Framework\DB\Adapter\Pdo\Mysql methods * does not add the custom table prefix to the $name. * The custom table prefix could be set my a Magento 2 administrator * during Magento 2 intallation (see the «table_prefix» key in the app/etc/env.php file). */ $table = df_table($table); /** @var array(string => string|int|null) $definitionRaw */ $definitionRaw = df_db_column_describe($table, $from); /** * 2016-11-04 * @var array(string => string|int|null) $definition * Got an array like: { "name": "test_7781", "type": "text", "length": "255", "options": [], "comment": "Test 7781" } */ $definition = df_conn()->getColumnCreateByDescribe($definitionRaw); /** * 2016-11-04 * The @uses \Magento\Framework\DB\Adapter\Pdo\Mysql::getColumnCreateByDescribe() method * sets the table's name as the table's comment: * https://github.com/magento/magento2/blob/2.1.2/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php#L1600 * We remove this comment, because the table will be renamed. */ unset($definition['comment']); df_conn()->changeColumn($table, $from, $to, $definition); /** * 2016-11-04 * @see \Magento\Framework\DB\Adapter\Pdo\Mysql::resetDdlCache() call is not needed here, * because it has already been called * from @uses \Magento\Framework\DB\Adapter\Pdo\Mysql::changeColumn() * https://github.com/magento/magento2/blob/2.1.2/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php#L1010 */ }