Skip to content

Commit

Permalink
Merge pull request #1062 from magento-jackalopes/pr-sprint-15
Browse files Browse the repository at this point in the history
[Jackalopes] - Sprint 15 PR
  • Loading branch information
paliarush authored Apr 26, 2017
2 parents c3cb46a + 065d18b commit ed746e3
Show file tree
Hide file tree
Showing 66 changed files with 1,185 additions and 742 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function getSelectionAttributesDataProvider()
{
return [
[[], null],
[['bundle_selection_attributes' => 'a:1:{i:0;i:1;}'], [0 => 1]],
[['bundle_selection_attributes' => 'serialized string'], [0 => 1]],
];
}

Expand Down
21 changes: 17 additions & 4 deletions app/code/Magento/Catalog/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/**
* Upgrade Data script
* @codeCoverageIgnore
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class UpgradeData implements UpgradeDataInterface
Expand All @@ -35,15 +35,25 @@ class UpgradeData implements UpgradeDataInterface
private $eavSetupFactory;

/**
* Init
* @var UpgradeWidgetData
*/
private $upgradeWidgetData;

/**
* Constructor
*
* @param CategorySetupFactory $categorySetupFactory
* @param EavSetupFactory $eavSetupFactory
* @param UpgradeWidgetData $upgradeWidgetData
*/
public function __construct(CategorySetupFactory $categorySetupFactory, EavSetupFactory $eavSetupFactory)
{
public function __construct(
CategorySetupFactory $categorySetupFactory,
EavSetupFactory $eavSetupFactory,
UpgradeWidgetData $upgradeWidgetData
) {
$this->categorySetupFactory = $categorySetupFactory;
$this->eavSetupFactory = $eavSetupFactory;
$this->upgradeWidgetData = $upgradeWidgetData;
}

/**
Expand Down Expand Up @@ -366,6 +376,9 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
$this->dissallowUsingHtmlForProductName($setup);
}

if ($context->getVersion() && version_compare($context->getVersion(), '2.2.1') < 0) {
$this->upgradeWidgetData->upgrade();
}
$setup->endSetup();
}

Expand Down
120 changes: 120 additions & 0 deletions app/code/Magento/Catalog/Setup/UpgradeWidgetData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Setup;

use Magento\Framework\DB\Select\QueryModifierFactory;
use Magento\Widget\Setup\LayoutUpdateConverter;
use Magento\Eav\Setup\EavSetup;
use Magento\Framework\DB\FieldToConvert;
use Magento\Framework\DB\AggregatedFieldDataConverter;

/**
* Convert serialized widget data for categories and products tables to JSON
*/
class UpgradeWidgetData
{
/**
* @var EavSetup
*/
private $eavSetup;

/**
* @var QueryModifierFactory
*/
private $queryModifierFactory;

/**
* Constructor
*
* @param EavSetup $eavSetup
* @param QueryModifierFactory $queryModifierFactory
* @param AggregatedFieldDataConverter $aggregatedFieldDataConverter
*/
public function __construct(
EavSetup $eavSetup,
QueryModifierFactory $queryModifierFactory,
AggregatedFieldDataConverter $aggregatedFieldDataConverter
) {
$this->eavSetup = $eavSetup;
$this->queryModifierFactory = $queryModifierFactory;
$this->aggregatedFieldDataConverter = $aggregatedFieldDataConverter;
}

/**
* Convert category and product layout update
*
* @return void
* @throws \InvalidArgumentException
*/
public function upgrade()
{
$categoryTypeId = $this->eavSetup->getEntityTypeId(\Magento\Catalog\Model\Category::ENTITY);
$categoryLayoutUpdateAttribute = $this->eavSetup->getAttribute($categoryTypeId, 'custom_layout_update');
$categoryLayoutUpdateAttributeModifier = $this->queryModifierFactory->create(
'in',
[
'values' => [
'attribute_id' => $categoryLayoutUpdateAttribute['attribute_id']
]
]
);
$layoutUpdateValueModifier = $this->queryModifierFactory->create(
'like',
[
'values' => [
'value' => '%conditions_encoded%'
]
]
);
$categoryLayoutUpdateModifier = $this->queryModifierFactory->create(
'composite',
[
'queryModifiers' => [
$categoryLayoutUpdateAttributeModifier,
$layoutUpdateValueModifier
]
]
);
$productTypeId = $this->eavSetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
$productLayoutUpdateAttribute = $this->eavSetup->getAttribute($productTypeId, 'custom_layout_update');
$productLayoutUpdateAttributeModifier = $this->queryModifierFactory->create(
'in',
[
'values' => [
'attribute_id' => $productLayoutUpdateAttribute['attribute_id']
]
]
);
$productLayoutUpdateModifier = $this->queryModifierFactory->create(
'composite',
[
'queryModifiers' => [
$productLayoutUpdateAttributeModifier,
$layoutUpdateValueModifier
]
]
);
$this->aggregatedFieldDataConverter->convert(
[
new FieldToConvert(
LayoutUpdateConverter::class,
$this->eavSetup->getSetup()->getTable('catalog_category_entity_text'),
'value_id',
'value',
$categoryLayoutUpdateModifier
),
new FieldToConvert(
LayoutUpdateConverter::class,
$this->eavSetup->getSetup()->getTable('catalog_product_entity_text'),
'value_id',
'value',
$productLayoutUpdateModifier
),
],
$this->eavSetup->getSetup()->getConnection()
);
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Catalog" setup_version="2.2.0">
<module name="Magento_Catalog" setup_version="2.2.1">
<sequence>
<module name="Magento_Eav"/>
<module name="Magento_Cms"/>
Expand Down
46 changes: 25 additions & 21 deletions app/code/Magento/CatalogRule/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

namespace Magento\CatalogRule\Setup;

use Magento\Framework\DB\FieldDataConverterFactory;
use Magento\Framework\DB\AggregatedFieldDataConverter;
use Magento\Framework\DB\DataConverter\SerializedToJson;
use Magento\Framework\DB\FieldToConvert;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
Expand All @@ -17,26 +18,26 @@
class UpgradeData implements UpgradeDataInterface
{
/**
* @var FieldDataConverterFactory
* @var MetadataPool
*/
private $fieldDataConverterFactory;
private $metadataPool;

/**
* @var MetadataPool
* @var AggregatedFieldDataConverter
*/
private $metadataPool;
private $aggregatedFieldConverter;

/**
* UpgradeData constructor.
*
* @param FieldDataConverterFactory $fieldDataConverterFactory
* @param AggregatedFieldDataConverter $aggregatedFieldConverter
* @param MetadataPool $metadataPool
*/
public function __construct(
FieldDataConverterFactory $fieldDataConverterFactory,
AggregatedFieldDataConverter $aggregatedFieldConverter,
MetadataPool $metadataPool
) {
$this->fieldDataConverterFactory = $fieldDataConverterFactory;
$this->aggregatedFieldConverter = $aggregatedFieldConverter;
$this->metadataPool = $metadataPool;
}

Expand All @@ -63,20 +64,23 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
*/
public function convertSerializedDataToJson($setup)
{
$fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class);
$metadata = $this->metadataPool->getMetadata(RuleInterface::class);

$fieldDataConverter->convert(
$setup->getConnection(),
$setup->getTable('catalogrule'),
$metadata->getLinkField(),
'conditions_serialized'
);
$fieldDataConverter->convert(
$setup->getConnection(),
$setup->getTable('catalogrule'),
$metadata->getLinkField(),
'actions_serialized'
$this->aggregatedFieldConverter->convert(
[
new FieldToConvert(
SerializedToJson::class,
$setup->getTable('catalogrule'),
$metadata->getLinkField(),
'conditions_serialized'
),
new FieldToConvert(
SerializedToJson::class,
$setup->getTable('catalogrule'),
$metadata->getLinkField(),
'actions_serialized'
),
],
$setup->getConnection()
);
}
}

This file was deleted.

Loading

0 comments on commit ed746e3

Please sign in to comment.