![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/wyomind/msicustomattributes/Setup/Patch/Schema/ |
<?php namespace Wyomind\MsiCustomAttributes\Setup\Patch\Schema; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Ddl\Table; use Magento\Framework\Module\ModuleResource; use Magento\Framework\Setup\Patch\PatchRevertableInterface; use Magento\Framework\Setup\Patch\SchemaPatchInterface; use Magento\Framework\Setup\SchemaSetupInterface; use Wyomind\MsiCustomAttributes\Model\ResourceModel\CustomAttribute; use Wyomind\MsiCustomAttributes\Model\ResourceModel\CustomAttributeDropdownOption; use Wyomind\MsiCustomAttributes\Model\ResourceModel\CustomAttributeDropdownOptionValue; use Wyomind\MsiCustomAttributes\Model\ResourceModel\CustomAttributeValue; class Init implements SchemaPatchInterface, PatchRevertableInterface { public $dbVersion; protected SchemaSetupInterface $schemaSetup; const version = "1.0.0"; /** * @param SchemaSetupInterface $schemaSetup */ public function __construct( SchemaSetupInterface $schemaSetup, ModuleResource $moduleResource ) { $this->schemaSetup = $schemaSetup; $this->dbVersion = $moduleResource->getDbVersion("Wyomind_MsiCustomAttributes"); } public function apply() { if (version_compare($this->dbVersion, self::version) >= 0) { $this->schemaSetup->getConnection()->startSetup(); $installer = $this->schemaSetup; /** * msi_custom_attribute */ $advancedMsiAttributes = $installer->getConnection() ->newTable($installer->getTable(CustomAttribute::MSI_CUSTOM_ATTRIBUTE)) ->addColumn( 'attribute_id', Table::TYPE_INTEGER, 11, ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], 'attribute_id' ) ->addColumn( 'code', Table::TYPE_TEXT, 255, ['identity' => false, 'nullable' => true, 'primary' => false], 'Attribute Code' ) ->addColumn( 'label', Table::TYPE_TEXT, 255, ['identity' => false, 'nullable' => true, 'primary' => false], 'Attribute Label' ) ->addColumn( 'type', Table::TYPE_TEXT, 6, ['identity' => false, 'nullable' => false, "default" => "text", 'primary' => false], 'Attribute Label' ) ->addColumn( 'sort_order', Table::TYPE_INTEGER, 3, ['identity' => false, 'nullable' => false, "default" => 0, 'primary' => false], 'Attribute Sort Order' ) ->addColumn( 'default', Table::TYPE_TEXT, 900, [], 'Default value' ) ->addColumn( 'is_system', Table::TYPE_INTEGER, 1, ['identity' => false, 'nullable' => false, "default" => 0, 'primary' => false], 'Is System Attribute' ) ->addColumn( 'is_required', Table::TYPE_BOOLEAN, 1, ['nullable' => false, 'default' => 0], 'Is default value' ) ->setComment('Advanced Inventory Additionnal Attributes'); $installer->getConnection()->createTable($advancedMsiAttributes); /** * msi_custom_attribute_dropdown_option */ $msiCustomAttributesOption = $installer->getConnection() ->newTable($installer->getTable(CustomAttributeDropdownOption::MSI_CUSTOM_ATTRIBUTE_DROPDOWN_OPTION)) ->addColumn( 'option_id', Table::TYPE_INTEGER, 10, ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], 'Option id' ) ->addColumn( 'attribute_id', Table::TYPE_INTEGER, 10, ['unsigned' => true, 'nullable' => false,], 'Attribute id' ) ->addColumn( 'position', Table::TYPE_INTEGER, 10, ['unsigned' => true, 'nullable' => false, 'default' => 1], 'Sort order' ) ->addColumn( 'is_default', Table::TYPE_INTEGER, 1, ['nullable' => false, 'is_default' => 0], 'Default value' ) ->setComment('MSI Custom attributes Dropdown Options') ->addForeignKey("FK_MSI_CUSTOM_ATTRIBUTE_DROPDOWN_OPTION_ATTRIBUTE_ID", "attribute_id", $installer->getTable(CustomAttribute::MSI_CUSTOM_ATTRIBUTE), "attribute_id", Table::ACTION_CASCADE, Table::ACTION_CASCADE); $installer->getConnection()->createTable($msiCustomAttributesOption); /** * msi_custom_attribute_dropdown_option_value */ $msiCustomAttributesOption = $installer->getConnection() ->newTable($installer->getTable(CustomAttributeDropdownOptionValue::MSI_CUSTOM_ATTRIBUTE_DROPDOWN_OPTION_VALUE)) ->addColumn( 'value_id', Table::TYPE_INTEGER, 10, ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], 'Value id' ) ->addColumn( 'option_id', Table::TYPE_INTEGER, 10, ['unsigned' => true, 'nullable' => false,], 'Option id' ) ->addColumn( 'store_id', Table::TYPE_SMALLINT, 5, ['unsigned' => true, 'nullable' => false], 'Store id' ) ->addColumn( 'value', Table::TYPE_TEXT, 600, ['nullable' => true], 'Value' ) ->setComment('MSI Custom attributes Dropdown Options Values') ->addIndex("UNIQ_OPTION_ID_STORE_ID", ["option_id", "store_id"], ["type" => AdapterInterface::INDEX_TYPE_UNIQUE]) ->addForeignKey("FK_MSI_CUSTOM_ATTRIBUTE_DROPDOWN_OPTION_VALUE_OPTION_ID", "option_id", $installer->getTable(CustomAttributeDropdownOption::MSI_CUSTOM_ATTRIBUTE_DROPDOWN_OPTION), "option_id", Table::ACTION_CASCADE, Table::ACTION_CASCADE) ->addForeignKey("FK_MSI_CUSTOM_ATTRIBUTE_DROPDOWN_OPTION_VALUE_STORE_ID", "store_id", $installer->getTable("store"), "store_id", Table::ACTION_CASCADE, Table::ACTION_CASCADE); $installer->getConnection()->createTable($msiCustomAttributesOption); /** * msi_custom_attribute_value */ $msiCustomAttributes = $installer->getConnection() ->newTable($installer->getTable(CustomAttributeValue::MSI_CUSTOM_ATTRIBUTE_VALUE)) ->addColumn( 'value_id', Table::TYPE_INTEGER, 10, ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], 'Value id' ) ->addColumn( 'source_code', Table::TYPE_TEXT, 255, ['unsigned' => true, 'nullable' => false,], 'Source code' ) ->addColumn( 'sku', Table::TYPE_TEXT, 255, ['nullable' => false], 'Product Sku' ) ->addColumn( 'attribute_id', Table::TYPE_INTEGER, 11, ['unsigned' => true, 'nullable' => false], 'Attribute Id' )->addColumn( 'value', Table::TYPE_TEXT, 999, ['nullable' => true], 'Value of the Attribute' ) ->addIndex("UNIQ_SOURCE_CODE_SKU", ["source_code", "sku", "attribute_id"], ["type" => AdapterInterface::INDEX_TYPE_UNIQUE]) ->setComment('MSI Custom attributes') ->addForeignKey("FK_MSI_CUSTOM_ATTRIBUTE_VALUE_SOURCE_CODE", "source_code", $installer->getTable("inventory_source"), "source_code", Table::ACTION_CASCADE, Table::ACTION_CASCADE) ->addForeignKey("FK_MSI_CUSTOM_ATTRIBUTE_VALUE_ATTRIBUTE_ID", "attribute_id", $installer->getTable(CustomAttribute::MSI_CUSTOM_ATTRIBUTE), "attribute_id", Table::ACTION_CASCADE, Table::ACTION_CASCADE); /* @todo add a cascade constraint on the onUpdate action */ //->addForeignKey("FK_MSI_CUSTOM_ATTRIBUTE_VALUE_SKU", "sku", $installer->getTable("catalog_product_entity"), "sku", \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE, \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE) $installer->getConnection()->createTable($msiCustomAttributes); $this->schemaSetup->getConnection()->endSetup(); } } /** * @inheritdoc */ public function revert() { } /** * @inheritdoc */ public static function getDependencies() { return []; } /** * @inheritdoc */ public function getAliases() { return []; } }