diff --git a/app/code/Magento/Analytics/Setup/InstallData.php b/app/code/Magento/Analytics/Setup/InstallData.php deleted file mode 100644 index 9832849bacc04..0000000000000 --- a/app/code/Magento/Analytics/Setup/InstallData.php +++ /dev/null @@ -1,52 +0,0 @@ -getConnection()->insertMultiple( - $setup->getTable('core_config_data'), - [ - [ - 'scope' => 'default', - 'scope_id' => 0, - 'path' => 'analytics/subscription/enabled', - 'value' => 1 - ], - [ - 'scope' => 'default', - 'scope_id' => 0, - 'path' => SubscriptionHandler::CRON_STRING_PATH, - 'value' => join(' ', SubscriptionHandler::CRON_EXPR_ARRAY) - ] - ] - ); - - $setup->getConnection()->insert( - $setup->getTable('flag'), - [ - 'flag_code' => SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, - 'state' => 0, - 'flag_data' => 24, - ] - ); - } -} diff --git a/app/code/Magento/Analytics/Setup/Patch/PatchInitial.php b/app/code/Magento/Analytics/Setup/Patch/PrepareInitialConfig.php similarity index 54% rename from app/code/Magento/Analytics/Setup/Patch/PatchInitial.php rename to app/code/Magento/Analytics/Setup/Patch/PrepareInitialConfig.php index b5e30ad8920f5..6bcb455a04322 100644 --- a/app/code/Magento/Analytics/Setup/Patch/PatchInitial.php +++ b/app/code/Magento/Analytics/Setup/Patch/PrepareInitialConfig.php @@ -7,28 +7,38 @@ namespace Magento\Analytics\Setup\Patch; use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler; -use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; - /** - * Patch is mechanism, that allows to do atomic upgrade data changes + * Initial patch. + * + * @package Magento\Analytics\Setup\Patch */ class PatchInitial implements \Magento\Setup\Model\Patch\DataPatchInterface { + /** + * @var ModuleDataSetupInterface + */ + private $moduleDataSetup; + + /** + * PatchInitial constructor. + * @param ModuleDataSetupInterface $moduleDataSetup + */ + public function __construct( + ModuleDataSetupInterface $moduleDataSetup + ) { + $this->moduleDataSetup = $moduleDataSetup; + } /** - * Do Upgrade - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * @return void + * {@inheritdoc} */ - public function apply(ModuleDataSetupInterface $setup) + public function apply() { - $setup->getConnection()->insertMultiple( - $setup->getTable('core_config_data'), + $this->moduleDataSetup->getConnection()->insertMultiple( + $this->moduleDataSetup->getTable('core_config_data'), [ [ 'scope' => 'default', @@ -45,8 +55,8 @@ public function apply(ModuleDataSetupInterface $setup) ] ); - $setup->getConnection()->insert( - $setup->getTable('flag'), + $this->moduleDataSetup->getConnection()->insert( + $this->moduleDataSetup->getTable('flag'), [ 'flag_code' => SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, 'state' => 0, @@ -57,23 +67,26 @@ public function apply(ModuleDataSetupInterface $setup) } /** - * Do Revert - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * @return void + * {@inheritdoc} */ - public function revert(ModuleDataSetupInterface $setup) + public static function getDependencies() { + return []; } /** - * @inheritdoc + * {@inheritdoc} */ - public function isDisabled() + public function getVersion() { - return false; + return '2.0.0'; } - + /** + * {@inheritdoc} + */ + public function getAliases() + { + return []; + } } diff --git a/app/code/Magento/Authorization/Setup/InstallData.php b/app/code/Magento/Authorization/Setup/InstallData.php deleted file mode 100644 index b8b18706722a5..0000000000000 --- a/app/code/Magento/Authorization/Setup/InstallData.php +++ /dev/null @@ -1,101 +0,0 @@ -authFactory = $authFactory; - } - - /** - * {@inheritdoc} - */ - public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) - { - $roleCollection = $this->authFactory->createRoleCollection() - ->addFieldToFilter('parent_id', 0) - ->addFieldToFilter('tree_level', 1) - ->addFieldToFilter('role_type', RoleGroup::ROLE_TYPE) - ->addFieldToFilter('user_id', 0) - ->addFieldToFilter('user_type', UserContextInterface::USER_TYPE_ADMIN) - ->addFieldToFilter('role_name', 'Administrators'); - - if ($roleCollection->count() == 0) { - $admGroupRole = $this->authFactory->createRole()->setData( - [ - 'parent_id' => 0, - 'tree_level' => 1, - 'sort_order' => 1, - 'role_type' => RoleGroup::ROLE_TYPE, - 'user_id' => 0, - 'user_type' => UserContextInterface::USER_TYPE_ADMIN, - 'role_name' => 'Administrators', - ] - )->save(); - } else { - foreach ($roleCollection as $item) { - $admGroupRole = $item; - break; - } - } - - $rulesCollection = $this->authFactory->createRulesCollection() - ->addFieldToFilter('role_id', $admGroupRole->getId()) - ->addFieldToFilter('resource_id', 'all'); - - if ($rulesCollection->count() == 0) { - $this->authFactory->createRules()->setData( - [ - 'role_id' => $admGroupRole->getId(), - 'resource_id' => 'Magento_Backend::all', - 'privileges' => null, - 'permission' => 'allow', - ] - )->save(); - } else { - /** @var \Magento\Authorization\Model\Rules $rule */ - foreach ($rulesCollection as $rule) { - $rule->setData('resource_id', 'Magento_Backend::all')->save(); - } - } - - /** - * Delete rows by condition from authorization_rule - */ - $setup->startSetup(); - - $tableName = $setup->getTable('authorization_rule'); - if ($tableName) { - $setup->getConnection()->delete($tableName, ['resource_id = ?' => 'admin/system/tools/compiler']); - } - - $setup->endSetup(); - } -} diff --git a/app/code/Magento/Authorization/Setup/Patch/InitializeAuthRoles.php b/app/code/Magento/Authorization/Setup/Patch/InitializeAuthRoles.php new file mode 100644 index 0000000000000..ecb406f912a3e --- /dev/null +++ b/app/code/Magento/Authorization/Setup/Patch/InitializeAuthRoles.php @@ -0,0 +1,68 @@ +moduleDataSetup = $moduleDataSetup; + } + + /** + * {@inheritdoc} + */ + public function apply() + { + + + } + + /** + * {@inheritdoc} + */ + public static function getDependencies() + { + return []; + } + + /** + * {@inheritdoc} + */ + public function getVersion() + { + return '2.0.0'; + } + + /** + * {@inheritdoc} + */ + public function getAliases() + { + return []; + } +} diff --git a/app/code/Magento/Authorization/Setup/Patch/PatchInitial.php b/app/code/Magento/Authorization/Setup/Patch/PatchInitial.php deleted file mode 100644 index 4cec6e01344a2..0000000000000 --- a/app/code/Magento/Authorization/Setup/Patch/PatchInitial.php +++ /dev/null @@ -1,139 +0,0 @@ -authFactory = $authFactory; - $this->authFactory = $authFactory; - $this->authFactory = $authFactory; - $this->authFactory = $authFactory; - } - - /** - * Do Upgrade - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * @return void - */ - public function apply(ModuleDataSetupInterface $setup) - { - $roleCollection = $this->authFactory->createRoleCollection() - ->addFieldToFilter('parent_id', 0) - ->addFieldToFilter('tree_level', 1) - ->addFieldToFilter('role_type', RoleGroup::ROLE_TYPE) - ->addFieldToFilter('user_id', 0) - ->addFieldToFilter('user_type', UserContextInterface::USER_TYPE_ADMIN) - ->addFieldToFilter('role_name', 'Administrators'); - - if ($roleCollection->count() == 0) { - $admGroupRole = $this->authFactory->createRole()->setData( - [ - 'parent_id' => 0, - 'tree_level' => 1, - 'sort_order' => 1, - 'role_type' => RoleGroup::ROLE_TYPE, - 'user_id' => 0, - 'user_type' => UserContextInterface::USER_TYPE_ADMIN, - 'role_name' => 'Administrators', - ] - )->save(); - } else { - foreach ($roleCollection as $item) { - $admGroupRole = $item; - break; - } - } - $rulesCollection = $this->authFactory->createRulesCollection() - ->addFieldToFilter('role_id', $admGroupRole->getId()) - ->addFieldToFilter('resource_id', 'all'); - if ($rulesCollection->count() == 0) { - $this->authFactory->createRules()->setData( - [ - 'role_id' => $admGroupRole->getId(), - 'resource_id' => 'Magento_Backend::all', - 'privileges' => null, - 'permission' => 'allow', - ] - )->save(); - } else { - /** @var \Magento\Authorization\Model\Rules $rule */ - foreach ($rulesCollection as $rule) { - $rule->setData('resource_id', 'Magento_Backend::all')->save(); - } - } - /** - * Delete rows by condition from authorization_rule - */ - $setup->startSetup(); - $tableName = $setup->getTable('authorization_rule'); - if ($tableName) { - $setup->getConnection()->delete($tableName, ['resource_id = ?' => 'admin/system/tools/compiler']); - } - $setup->endSetup(); - - } - - /** - * Do Revert - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * @return void - */ - public function revert(ModuleDataSetupInterface $setup) - { - } - - /** - * @inheritdoc - */ - public function isDisabled() - { - return false; - } - - -} diff --git a/app/code/Magento/Braintree/Setup/UpgradeData.php b/app/code/Magento/Braintree/Setup/Patch/ConvertSerializedDataToJson.php similarity index 59% rename from app/code/Magento/Braintree/Setup/UpgradeData.php rename to app/code/Magento/Braintree/Setup/Patch/ConvertSerializedDataToJson.php index a7b39f12273e2..2cb2f37a911a9 100644 --- a/app/code/Magento/Braintree/Setup/UpgradeData.php +++ b/app/code/Magento/Braintree/Setup/Patch/ConvertSerializedDataToJson.php @@ -4,60 +4,63 @@ * See COPYING.txt for license details. */ -namespace Magento\Braintree\Setup; +namespace Magento\Braintree\Setup\Patch; -use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; -use Magento\Framework\Setup\UpgradeDataInterface; +use Magento\Setup\Model\Patch\DataPatchInterface; +use Magento\Setup\Model\Patch\VersionedDataPatch; -class UpgradeData implements UpgradeDataInterface +/** + * + * + * @package Magento\Analytics\Setup\Patch + */ +class ConvertSerializedDataToJson implements DataPatchInterface, VersionedDataPatch { + /** + * @var ModuleDataSetupInterface + */ + private $moduleDataSetup; /** * @var \Magento\Framework\DB\FieldDataConverterFactory */ private $fieldDataConverterFactory; - /** * @var \Magento\Framework\DB\Select\QueryModifierFactory */ private $queryModifierFactory; /** - * UpgradeData constructor. - * + * PatchInitial constructor. + * @param ModuleDataSetupInterface $moduleDataSetup * @param \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory * @param \Magento\Framework\DB\Select\QueryModifierFactory $queryModifierFactory */ public function __construct( + ModuleDataSetupInterface $moduleDataSetup, \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory, \Magento\Framework\DB\Select\QueryModifierFactory $queryModifierFactory ) { + $this->moduleDataSetup = $moduleDataSetup; $this->fieldDataConverterFactory = $fieldDataConverterFactory; $this->queryModifierFactory = $queryModifierFactory; } /** - * Upgrades data for Braintree module - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * @return void + * {@inheritdoc} */ - public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) + public function apply() { - if (version_compare($context->getVersion(), '2.0.1', '<')) { - $this->convertSerializedDataToJson($setup); - } + $this->convertSerializedDataToJson(); } /** * Upgrade data to version 2.0.1, converts row data in the core_config_data table that uses the path * payment/braintree/countrycreditcard from serialized to JSON * - * @param ModuleDataSetupInterface $setup * @return void */ - private function convertSerializedDataToJson(ModuleDataSetupInterface $setup) + private function convertSerializedDataToJson() { $fieldDataConverter = $this->fieldDataConverterFactory->create( \Magento\Framework\DB\DataConverter\SerializedToJson::class @@ -73,11 +76,35 @@ private function convertSerializedDataToJson(ModuleDataSetupInterface $setup) ); $fieldDataConverter->convert( - $setup->getConnection(), - $setup->getTable('core_config_data'), + $this->moduleDataSetup->getConnection(), + $this->moduleDataSetup->getTable('core_config_data'), 'config_id', 'value', $queryModifier ); } + + /** + * {@inheritdoc} + */ + public static function getDependencies() + { + return []; + } + + /** + * {@inheritdoc} + */ + public function getVersion() + { + return '2.0.1'; + } + + /** + * {@inheritdoc} + */ + public function getAliases() + { + return []; + } } diff --git a/app/code/Magento/Braintree/Setup/Patch/Patch201.php b/app/code/Magento/Braintree/Setup/Patch/Patch201.php deleted file mode 100644 index 3caf5f4a2fbfe..0000000000000 --- a/app/code/Magento/Braintree/Setup/Patch/Patch201.php +++ /dev/null @@ -1,97 +0,0 @@ -fieldDataConverterFactory = $fieldDataConverterFactory; - $this->queryModifierFactory = $queryModifierFactory; - } - - /** - * Do Upgrade - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * @return void - */ - public function apply(ModuleDataSetupInterface $setup) - { - $this->convertSerializedDataToJson($setup); - - } - - /** - * Do Revert - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * @return void - */ - public function revert(ModuleDataSetupInterface $setup) - { - } - - /** - * @inheritdoc - */ - public function isDisabled() - { - return false; - } - - - private function convertSerializedDataToJson(ModuleDataSetupInterface $setup - ) - { - $fieldDataConverter = $this->fieldDataConverterFactory->create( - \Magento\Framework\DB\DataConverter\SerializedToJson::class - ); - - $queryModifier = $this->queryModifierFactory->create( - 'in', - [ - 'values' => [ - 'path' => ['payment/braintree/countrycreditcard'] - ] - ] - ); - - $fieldDataConverter->convert( - $setup->getConnection(), - $setup->getTable('core_config_data'), - 'config_id', - 'value', - $queryModifier - ); - - } -} diff --git a/app/code/Magento/Bundle/Setup/InstallData.php b/app/code/Magento/Bundle/Setup/InstallData.php deleted file mode 100644 index 6a3ff08c4d781..0000000000000 --- a/app/code/Magento/Bundle/Setup/InstallData.php +++ /dev/null @@ -1,208 +0,0 @@ -eavSetupFactory = $eavSetupFactory; - } - - /** - * {@inheritdoc} - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) - { - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); - $fieldList = [ - 'price', - 'special_price', - 'special_from_date', - 'special_to_date', - 'minimal_price', - 'cost', - 'tier_price', - 'weight', - ]; - foreach ($fieldList as $field) { - $applyTo = explode( - ',', - $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $field, 'apply_to') - ); - if (!in_array('bundle', $applyTo)) { - $applyTo[] = 'bundle'; - $eavSetup->updateAttribute( - \Magento\Catalog\Model\Product::ENTITY, - $field, - 'apply_to', - implode(',', $applyTo) - ); - } - } - - $applyTo = explode(',', $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'cost', 'apply_to')); - unset($applyTo[array_search('bundle', $applyTo)]); - $eavSetup->updateAttribute(\Magento\Catalog\Model\Product::ENTITY, 'cost', 'apply_to', implode(',', $applyTo)); - - /** - * Add attributes to the eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'price_type', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'bundle' - ] - ); - - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'sku_type', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'visible' => false, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'apply_to' => 'bundle' - ] - ); - - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'weight_type', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'visible' => false, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'bundle' - ] - ); - - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'price_view', - [ - 'group' => 'Advanced Pricing', - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Price View', - 'input' => 'select', - 'class' => '', - 'source' => \Magento\Bundle\Model\Product\Attribute\Source\Price\View::class, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'bundle' - ] - ); - - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'shipment_type', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Shipment', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'visible' => false, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'bundle' - ] - ); - } -} diff --git a/app/code/Magento/Bundle/Setup/Patch/ApplyAttributesUpdate.php b/app/code/Magento/Bundle/Setup/Patch/ApplyAttributesUpdate.php new file mode 100644 index 0000000000000..c127b4cb28f0a --- /dev/null +++ b/app/code/Magento/Bundle/Setup/Patch/ApplyAttributesUpdate.php @@ -0,0 +1,74 @@ +moduleDataSetup = $moduleDataSetup; + } + + /** + * {@inheritdoc} + */ + public function apply() + { + + + } + + /** + * {@inheritdoc} + */ + public static function getDependencies() + { + return []; + } + + /** + * {@inheritdoc} + */ + public function getVersion() + { + return '2.0.0'; + } + + /** + * {@inheritdoc} + */ + public function getAliases() + { + return []; + } +} diff --git a/app/code/Magento/Bundle/Setup/Patch/Patch204.php b/app/code/Magento/Bundle/Setup/Patch/Patch204.php deleted file mode 100644 index 47eaa808b7092..0000000000000 --- a/app/code/Magento/Bundle/Setup/Patch/Patch204.php +++ /dev/null @@ -1,123 +0,0 @@ -startSetup(); - - // Updating data of the 'catalog_product_bundle_option_value' table. - $tableName = $setup->getTable('catalog_product_bundle_option_value'); - - $select = $setup->getConnection()->select() - ->from( - ['values' => $tableName], - ['value_id'] - )->joinLeft( - ['options' => $setup->getTable('catalog_product_bundle_option')], - 'values.option_id = options.option_id', - ['parent_product_id' => 'parent_id'] - ); - $setup->getConnection()->query( - $setup->getConnection()->insertFromSelect( - $select, - $tableName, - ['value_id', 'parent_product_id'], - \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE - ) - ); - // Updating data of the 'catalog_product_bundle_selection_price' table. - $tableName = $setup->getTable('catalog_product_bundle_selection_price'); - $tmpTableName = $setup->getTable('catalog_product_bundle_selection_price_tmp'); - $existingForeignKeys = $setup->getConnection()->getForeignKeys($tableName); - foreach ($existingForeignKeys as $key) { - $setup->getConnection()->dropForeignKey($key['TABLE_NAME'], $key['FK_NAME']); - } - $setup->getConnection()->createTable( - $setup->getConnection()->createTableByDdl($tableName, $tmpTableName) - ); - foreach ($existingForeignKeys as $key) { - $setup->getConnection()->addForeignKey( - $key['FK_NAME'], - $key['TABLE_NAME'], - $key['COLUMN_NAME'], - $key['REF_TABLE_NAME'], - $key['REF_COLUMN_NAME'], - $key['ON_DELETE'] - ); - } - $setup->getConnection()->query( - $setup->getConnection()->insertFromSelect( - $setup->getConnection()->select()->from($tableName), - $tmpTableName - ) - ); - $setup->getConnection()->truncateTable($tableName); - $columnsToSelect = []; - foreach ($setup->getConnection()->describeTable($tmpTableName) as $column) { - $alias = $column['COLUMN_NAME'] == 'parent_product_id' ? 'selections.' : 'prices.'; - $columnsToSelect[] = $alias . $column['COLUMN_NAME']; - } - $select = $setup->getConnection()->select() - ->from( - ['prices' => $tmpTableName], - [] - )->joinLeft( - ['selections' => $setup->getTable('catalog_product_bundle_selection')], - 'prices.selection_id = selections.selection_id', - [] - )->columns($columnsToSelect); - $setup->getConnection()->query( - $setup->getConnection()->insertFromSelect($select, $tableName) - ); - $setup->getConnection()->dropTable($tmpTableName); - - - $setup->endSetup(); - - } - - /** - * Do Revert - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * @return void - */ - public function revert(ModuleDataSetupInterface $setup) - { - } - - /** - * @inheritdoc - */ - public function isDisabled() - { - return false; - } - - -} diff --git a/app/code/Magento/Bundle/Setup/Patch/PatchInitial.php b/app/code/Magento/Bundle/Setup/Patch/PatchInitial.php deleted file mode 100644 index 96bb50260f925..0000000000000 --- a/app/code/Magento/Bundle/Setup/Patch/PatchInitial.php +++ /dev/null @@ -1,226 +0,0 @@ -eavSetupFactory = $eavSetupFactory; - } - - /** - * Do Upgrade - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * @return void - */ - public function apply(ModuleDataSetupInterface $setup) - { - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); - $fieldList = [ - 'price', - 'special_price', - 'special_from_date', - 'special_to_date', - 'minimal_price', - 'cost', - 'tier_price', - 'weight', - ]; - foreach ($fieldList as $field) { - $applyTo = explode( - ',', - $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $field, 'apply_to') - ); - if (!in_array('bundle', $applyTo)) { - $applyTo[] = 'bundle'; - $eavSetup->updateAttribute( - \Magento\Catalog\Model\Product::ENTITY, - $field, - 'apply_to', - implode(',', $applyTo) - ); - } - } - - $applyTo = explode(',', $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'cost', 'apply_to')); - unset($applyTo[array_search('bundle', $applyTo)]); - $eavSetup->updateAttribute(\Magento\Catalog\Model\Product::ENTITY, 'cost', 'apply_to', implode(',', $applyTo)); - /** - * Add attributes to the eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'price_type', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'bundle' - ] - ); - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'sku_type', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'visible' => false, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'unique' => false, - 'apply_to' => 'bundle' - ] - ); - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'weight_type', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => '', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'visible' => false, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'bundle' - ] - ); - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'price_view', - [ - 'group' => 'Advanced Pricing', - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Price View', - 'input' => 'select', - 'class' => '', - 'source' => \Magento\Bundle\Model\Product\Attribute\Source\Price\View::class, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'visible' => true, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'bundle' - ] - ); - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'shipment_type', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Shipment', - 'input' => '', - 'class' => '', - 'source' => '', - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, - 'visible' => false, - 'required' => true, - 'user_defined' => false, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => false, - 'used_in_product_listing' => true, - 'unique' => false, - 'apply_to' => 'bundle' - ] - ); - - } - - /** - * Do Revert - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * @return void - */ - public function revert(ModuleDataSetupInterface $setup) - { - } - - /** - * @inheritdoc - */ - public function isDisabled() - { - return false; - } - - -} diff --git a/app/code/Magento/Bundle/Setup/Patch/Patch202.php b/app/code/Magento/Bundle/Setup/Patch/UpdateBundleRelatedEntityTytpes.php similarity index 70% rename from app/code/Magento/Bundle/Setup/Patch/Patch202.php rename to app/code/Magento/Bundle/Setup/Patch/UpdateBundleRelatedEntityTytpes.php index b59ec3bf9733d..a7ec1baa8f3f1 100644 --- a/app/code/Magento/Bundle/Setup/Patch/Patch202.php +++ b/app/code/Magento/Bundle/Setup/Patch/UpdateBundleRelatedEntityTytpes.php @@ -6,46 +6,48 @@ namespace Magento\Bundle\Setup\Patch; +use Magento\Framework\Setup\ModuleDataSetupInterface; +use Magento\Setup\Model\Patch\DataPatchInterface; +use Magento\Setup\Model\Patch\VersionedDataPatch; use Magento\Catalog\Api\Data\ProductAttributeInterface; use Magento\Eav\Setup\EavSetup; -use Magento\Eav\Setup\EavSetupFactory; -use Magento\Framework\Setup\ModuleContextInterface; -use Magento\Framework\Setup\ModuleDataSetupInterface; - /** - * Patch is mechanism, that allows to do atomic upgrade data changes + * Class PrepareInitialConfig + * @package Magento\Bundle\Setup\Patch */ -class Patch202 implements \Magento\Setup\Model\Patch\DataPatchInterface +class PrepareInitialConfig implements DataPatchInterface, VersionedDataPatch { - - /** - * @param EavSetupFactory $eavSetupFactory + * @var ModuleDataSetupInterface + */ + private $moduleDataSetup; + /** + * @var \Magento\Eav\Setup\EavSetupFactory */ private $eavSetupFactory; /** - * @param EavSetupFactory $eavSetupFactory + * PatchInitial constructor. + * @param ModuleDataSetupInterface $moduleDataSetup + * @param \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory */ - public function __construct(EavSetupFactory $eavSetupFactory) - { + public function __construct( + ModuleDataSetupInterface $moduleDataSetup, + \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory + ) { + + $this->moduleDataSetup = $moduleDataSetup; $this->eavSetupFactory = $eavSetupFactory; } /** - * Do Upgrade - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * @return void + * {@inheritdoc} */ - public function apply(ModuleDataSetupInterface $setup) + public function apply() { - $setup->startSetup(); - /** @var \Magento\Eav\Setup\EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); $attributeSetId = $eavSetup->getDefaultAttributeSetId(ProductAttributeInterface::ENTITY_TYPE_CODE); $eavSetup->addAttributeGroup( @@ -58,34 +60,15 @@ public function apply(ModuleDataSetupInterface $setup) $this->upgradeSkuType($eavSetup); $this->upgradeWeightType($eavSetup); $this->upgradeShipmentType($eavSetup); - - - $setup->endSetup(); - } /** - * Do Revert + * Upgrade Dynamic Price attribute * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context + * @param EavSetup $eavSetup * @return void */ - public function revert(ModuleDataSetupInterface $setup) - { - } - - /** - * @inheritdoc - */ - public function isDisabled() - { - return false; - } - - - private function upgradePriceType(EavSetup $eavSetup - ) + private function upgradePriceType(EavSetup $eavSetup) { $eavSetup->updateAttribute( ProductAttributeInterface::ENTITY_TYPE_CODE, @@ -101,11 +84,15 @@ private function upgradePriceType(EavSetup $eavSetup 'Dynamic Price' ); $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'price_type', 'default_value', 0); - } - private function upgradeSkuType(EavSetup $eavSetup - ) + /** + * Upgrade Dynamic Sku attribute + * + * @param EavSetup $eavSetup + * @return void + */ + private function upgradeSkuType(EavSetup $eavSetup) { $eavSetup->updateAttribute( ProductAttributeInterface::ENTITY_TYPE_CODE, @@ -122,11 +109,15 @@ private function upgradeSkuType(EavSetup $eavSetup ); $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'sku_type', 'default_value', 0); $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'sku_type', 'is_visible', 1); - } - private function upgradeWeightType(EavSetup $eavSetup - ) + /** + * Upgrade Dynamic Weight attribute + * + * @param EavSetup $eavSetup + * @return void + */ + private function upgradeWeightType(EavSetup $eavSetup) { $eavSetup->updateAttribute( ProductAttributeInterface::ENTITY_TYPE_CODE, @@ -143,11 +134,15 @@ private function upgradeWeightType(EavSetup $eavSetup ); $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'weight_type', 'default_value', 0); $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'weight_type', 'is_visible', 1); - } - private function upgradeShipmentType(EavSetup $eavSetup - ) + /** + * Upgrade Ship Bundle Items attribute + * + * @param EavSetup $eavSetup + * @return void + */ + private function upgradeShipmentType(EavSetup $eavSetup) { $attributeSetId = $eavSetup->getDefaultAttributeSetId(ProductAttributeInterface::ENTITY_TYPE_CODE); $eavSetup->addAttributeToGroup( @@ -177,6 +172,29 @@ private function upgradeShipmentType(EavSetup $eavSetup ); $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'shipment_type', 'default_value', 0); $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'shipment_type', 'is_visible', 1); + } + /** + * {@inheritdoc} + */ + public static function getDependencies() + { + return []; + } + + /** + * {@inheritdoc} + */ + public function getVersion() + { + return '2.0.0'; + } + + /** + * {@inheritdoc} + */ + public function getAliases() + { + return []; } } diff --git a/app/code/Magento/Bundle/Setup/Patch/UpdateBundleRelatedSchema.php b/app/code/Magento/Bundle/Setup/Patch/UpdateBundleRelatedSchema.php new file mode 100644 index 0000000000000..d39d5c6820c9d --- /dev/null +++ b/app/code/Magento/Bundle/Setup/Patch/UpdateBundleRelatedSchema.php @@ -0,0 +1,145 @@ +moduleDataSetup = $moduleDataSetup; + } + + /** + * {@inheritdoc} + */ + public function apply() + { + // Updating data of the 'catalog_product_bundle_option_value' table. + $tableName = $this->moduleDataSetup->getTable('catalog_product_bundle_option_value'); + + $select = $this->moduleDataSetup->getConnection()->select() + ->from( + ['values' => $tableName], + ['value_id'] + )->joinLeft( + ['options' => $this->moduleDataSetup->getTable('catalog_product_bundle_option')], + 'values.option_id = options.option_id', + ['parent_product_id' => 'parent_id'] + ); + + $this->moduleDataSetup->getConnection()->query( + $this->moduleDataSetup->getConnection()->insertFromSelect( + $select, + $tableName, + ['value_id', 'parent_product_id'], + \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE + ) + ); + + // Updating data of the 'catalog_product_bundle_selection_price' table. + $tableName = $this->moduleDataSetup->getTable('catalog_product_bundle_selection_price'); + $tmpTableName = $this->moduleDataSetup->getTable('catalog_product_bundle_selection_price_tmp'); + + $existingForeignKeys = $this->moduleDataSetup->getConnection()->getForeignKeys($tableName); + + foreach ($existingForeignKeys as $key) { + $this->moduleDataSetup->getConnection()->dropForeignKey($key['TABLE_NAME'], $key['FK_NAME']); + } + + $this->moduleDataSetup->getConnection()->createTable( + $this->moduleDataSetup->getConnection()->createTableByDdl($tableName, $tmpTableName) + ); + + foreach ($existingForeignKeys as $key) { + $this->moduleDataSetup->getConnection()->addForeignKey( + $key['FK_NAME'], + $key['TABLE_NAME'], + $key['COLUMN_NAME'], + $key['REF_TABLE_NAME'], + $key['REF_COLUMN_NAME'], + $key['ON_DELETE'] + ); + } + + $this->moduleDataSetup->getConnection()->query( + $this->moduleDataSetup->getConnection()->insertFromSelect( + $this->moduleDataSetup->getConnection()->select()->from($tableName), + $tmpTableName + ) + ); + + $this->moduleDataSetup->getConnection()->truncateTable($tableName); + + $columnsToSelect = []; + + foreach ($this->moduleDataSetup->getConnection()->describeTable($tmpTableName) as $column) { + $alias = $column['COLUMN_NAME'] == 'parent_product_id' ? 'selections.' : 'prices.'; + + $columnsToSelect[] = $alias . $column['COLUMN_NAME']; + } + + $select = $this->moduleDataSetup->getConnection()->select() + ->from( + ['prices' => $tmpTableName], + [] + )->joinLeft( + ['selections' => $this->moduleDataSetup->getTable('catalog_product_bundle_selection')], + 'prices.selection_id = selections.selection_id', + [] + )->columns($columnsToSelect); + + $this->moduleDataSetup->getConnection()->query( + $this->moduleDataSetup->getConnection()->insertFromSelect($select, $tableName) + ); + + $this->moduleDataSetup->getConnection()->dropTable($tmpTableName); + } + + /** + * {@inheritdoc} + */ + public static function getDependencies() + { + return []; + } + + /** + * {@inheritdoc} + */ + public function getVersion() + { + return '2.0.4'; + } + + /** + * {@inheritdoc} + */ + public function getAliases() + { + return []; + } +} diff --git a/app/code/Magento/Bundle/Setup/UpgradeData.php b/app/code/Magento/Bundle/Setup/UpgradeData.php deleted file mode 100644 index 750bc79d84801..0000000000000 --- a/app/code/Magento/Bundle/Setup/UpgradeData.php +++ /dev/null @@ -1,255 +0,0 @@ -eavSetupFactory = $eavSetupFactory; - } - - /** - * {@inheritdoc} - * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) - { - $setup->startSetup(); - - if (version_compare($context->getVersion(), '2.0.2', '<')) { - /** @var \Magento\Eav\Setup\EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); - - $attributeSetId = $eavSetup->getDefaultAttributeSetId(ProductAttributeInterface::ENTITY_TYPE_CODE); - $eavSetup->addAttributeGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, - $attributeSetId, - 'Bundle Items', - 16 - ); - - $this->upgradePriceType($eavSetup); - $this->upgradeSkuType($eavSetup); - $this->upgradeWeightType($eavSetup); - $this->upgradeShipmentType($eavSetup); - } - - if (version_compare($context->getVersion(), '2.0.4', '<')) { - // Updating data of the 'catalog_product_bundle_option_value' table. - $tableName = $setup->getTable('catalog_product_bundle_option_value'); - - $select = $setup->getConnection()->select() - ->from( - ['values' => $tableName], - ['value_id'] - )->joinLeft( - ['options' => $setup->getTable('catalog_product_bundle_option')], - 'values.option_id = options.option_id', - ['parent_product_id' => 'parent_id'] - ); - - $setup->getConnection()->query( - $setup->getConnection()->insertFromSelect( - $select, - $tableName, - ['value_id', 'parent_product_id'], - \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE - ) - ); - - // Updating data of the 'catalog_product_bundle_selection_price' table. - $tableName = $setup->getTable('catalog_product_bundle_selection_price'); - $tmpTableName = $setup->getTable('catalog_product_bundle_selection_price_tmp'); - - $existingForeignKeys = $setup->getConnection()->getForeignKeys($tableName); - - foreach ($existingForeignKeys as $key) { - $setup->getConnection()->dropForeignKey($key['TABLE_NAME'], $key['FK_NAME']); - } - - $setup->getConnection()->createTable( - $setup->getConnection()->createTableByDdl($tableName, $tmpTableName) - ); - - foreach ($existingForeignKeys as $key) { - $setup->getConnection()->addForeignKey( - $key['FK_NAME'], - $key['TABLE_NAME'], - $key['COLUMN_NAME'], - $key['REF_TABLE_NAME'], - $key['REF_COLUMN_NAME'], - $key['ON_DELETE'] - ); - } - - $setup->getConnection()->query( - $setup->getConnection()->insertFromSelect( - $setup->getConnection()->select()->from($tableName), - $tmpTableName - ) - ); - - $setup->getConnection()->truncateTable($tableName); - - $columnsToSelect = []; - - foreach ($setup->getConnection()->describeTable($tmpTableName) as $column) { - $alias = $column['COLUMN_NAME'] == 'parent_product_id' ? 'selections.' : 'prices.'; - - $columnsToSelect[] = $alias . $column['COLUMN_NAME']; - } - - $select = $setup->getConnection()->select() - ->from( - ['prices' => $tmpTableName], - [] - )->joinLeft( - ['selections' => $setup->getTable('catalog_product_bundle_selection')], - 'prices.selection_id = selections.selection_id', - [] - )->columns($columnsToSelect); - - $setup->getConnection()->query( - $setup->getConnection()->insertFromSelect($select, $tableName) - ); - - $setup->getConnection()->dropTable($tmpTableName); - } - - $setup->endSetup(); - } - - /** - * Upgrade Dynamic Price attribute - * - * @param EavSetup $eavSetup - * @return void - */ - private function upgradePriceType(EavSetup $eavSetup) - { - $eavSetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, - 'price_type', - 'frontend_input', - 'boolean', - 31 - ); - $eavSetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, - 'price_type', - 'frontend_label', - 'Dynamic Price' - ); - $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'price_type', 'default_value', 0); - } - - /** - * Upgrade Dynamic Sku attribute - * - * @param EavSetup $eavSetup - * @return void - */ - private function upgradeSkuType(EavSetup $eavSetup) - { - $eavSetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, - 'sku_type', - 'frontend_input', - 'boolean', - 21 - ); - $eavSetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, - 'sku_type', - 'frontend_label', - 'Dynamic SKU' - ); - $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'sku_type', 'default_value', 0); - $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'sku_type', 'is_visible', 1); - } - - /** - * Upgrade Dynamic Weight attribute - * - * @param EavSetup $eavSetup - * @return void - */ - private function upgradeWeightType(EavSetup $eavSetup) - { - $eavSetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, - 'weight_type', - 'frontend_input', - 'boolean', - 71 - ); - $eavSetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, - 'weight_type', - 'frontend_label', - 'Dynamic Weight' - ); - $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'weight_type', 'default_value', 0); - $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'weight_type', 'is_visible', 1); - } - - /** - * Upgrade Ship Bundle Items attribute - * - * @param EavSetup $eavSetup - * @return void - */ - private function upgradeShipmentType(EavSetup $eavSetup) - { - $attributeSetId = $eavSetup->getDefaultAttributeSetId(ProductAttributeInterface::ENTITY_TYPE_CODE); - $eavSetup->addAttributeToGroup( - ProductAttributeInterface::ENTITY_TYPE_CODE, - $attributeSetId, - 'Bundle Items', - 'shipment_type', - 1 - ); - $eavSetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, - 'shipment_type', - 'frontend_input', - 'select' - ); - $eavSetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, - 'shipment_type', - 'frontend_label', - 'Ship Bundle Items' - ); - $eavSetup->updateAttribute( - ProductAttributeInterface::ENTITY_TYPE_CODE, - 'shipment_type', - 'source_model', - \Magento\Bundle\Model\Product\Attribute\Source\Shipment\Type::class - ); - $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'shipment_type', 'default_value', 0); - $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'shipment_type', 'is_visible', 1); - } -} diff --git a/app/code/Magento/Bundle/etc/config.xml b/app/code/Magento/Bundle/etc/config.xml deleted file mode 100644 index 152f04e251c35..0000000000000 --- a/app/code/Magento/Bundle/etc/config.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - diff --git a/setup/src/Magento/Setup/Model/Patch/VersionedDataPatch.php b/setup/src/Magento/Setup/Model/Patch/VersionedDataPatch.php new file mode 100644 index 0000000000000..9d01bd5db1622 --- /dev/null +++ b/setup/src/Magento/Setup/Model/Patch/VersionedDataPatch.php @@ -0,0 +1,29 @@ +