Skip to content

Commit ef783db

Browse files
author
Gurzhyi, Andrii
committed
Merge branch 'develop' of github.corp.magento.com:magento2/magento2ce into MAGETWO-43491
2 parents 399d22b + e65e0a1 commit ef783db

File tree

22 files changed

+340
-55
lines changed

22 files changed

+340
-55
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Console\Command;
7+
8+
use Magento\Framework\DB\Adapter\AdapterInterface;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class ProductAttributesCleanUp extends \Symfony\Component\Console\Command\Command
13+
{
14+
/**
15+
* @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface
16+
*/
17+
protected $productAttributeRepository;
18+
19+
/**
20+
* @var \Magento\Framework\Api\SearchCriteriaBuilder
21+
*/
22+
protected $searchCriteriaBuilder;
23+
24+
/**
25+
* @var \Magento\Catalog\Model\ResourceModel\Attribute
26+
*/
27+
protected $attributeResource;
28+
29+
/**
30+
* @var \Magento\Framework\App\State
31+
*/
32+
protected $appState;
33+
34+
/**
35+
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository
36+
* @param \Magento\Catalog\Model\ResourceModel\Attribute $attributeResource
37+
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
38+
* @param \Magento\Framework\App\State $appState
39+
*/
40+
public function __construct(
41+
\Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository,
42+
\Magento\Catalog\Model\ResourceModel\Attribute $attributeResource,
43+
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
44+
\Magento\Framework\App\State $appState
45+
) {
46+
$this->productAttributeRepository = $productAttributeRepository;
47+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
48+
$this->attributeResource = $attributeResource;
49+
$this->appState = $appState;
50+
parent::__construct();
51+
}
52+
53+
/**
54+
* {@inheritdoc}
55+
*/
56+
protected function configure()
57+
{
58+
$this->setName('catalog:product:attributes:cleanup');
59+
$this->setDescription('Removes unused product attributes.');
60+
}
61+
62+
/**
63+
* {@inheritdoc}
64+
*/
65+
protected function execute(InputInterface $input, OutputInterface $output)
66+
{
67+
$output->setDecorated(true);
68+
$this->appState->setAreaCode('catalog');
69+
$connection = $this->attributeResource->getConnection();
70+
$attributeTables = $this->getAttributeTables();
71+
72+
$progress = new \Symfony\Component\Console\Helper\ProgressBar($output, count($attributeTables));
73+
$progress->setFormat('<comment>%message%</comment> %current%/%max% [%bar%] %percent:3s%% %elapsed%');
74+
75+
$this->attributeResource->beginTransaction();
76+
try {
77+
// Find and remove unused attributes
78+
foreach ($attributeTables as $attributeTable) {
79+
$progress->setMessage($attributeTable . ' ');
80+
$affectedIds = $this->getAffectedAttributeIds($connection, $attributeTable);
81+
if (count($affectedIds) > 0) {
82+
$connection->delete($attributeTable, ['value_id in (?)' => $affectedIds]);
83+
}
84+
$progress->advance();
85+
}
86+
$this->attributeResource->commit();
87+
88+
$output->writeln("");
89+
$output->writeln("<info>Unused product attributes successfully cleaned up:</info>");
90+
$output->writeln("<comment> " . implode("\n ", $attributeTables) . "</comment>");
91+
} catch (\Exception $exception) {
92+
$this->attributeResource->rollBack();
93+
94+
$output->writeln("");
95+
$output->writeln("<error>{$exception->getMessage()}</error>");
96+
}
97+
}
98+
99+
/**
100+
* @return array
101+
* @throws \Magento\Framework\Exception\LocalizedException
102+
*/
103+
private function getAttributeTables()
104+
{
105+
$searchResult = $this->productAttributeRepository->getList($this->searchCriteriaBuilder->create());
106+
$attributeTables = [];
107+
108+
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $productAttribute */
109+
foreach ($searchResult->getItems() as $productAttribute) {
110+
$attributeTable = $productAttribute->getBackend()->getTable();
111+
if (!in_array($attributeTable, $attributeTables)
112+
&& $attributeTable != $this->attributeResource->getTable('catalog_product_entity')
113+
) {
114+
$attributeTables[] = $attributeTable;
115+
}
116+
}
117+
return $attributeTables;
118+
}
119+
120+
/**
121+
* @param AdapterInterface $connection
122+
* @param string $attributeTableName
123+
* @return array
124+
* @throws \Zend_Db_Statement_Exception
125+
*/
126+
private function getAffectedAttributeIds(AdapterInterface $connection, $attributeTableName)
127+
{
128+
$select = $connection->select()->reset();
129+
$select->from(['e' => $this->attributeResource->getTable('catalog_product_entity')], 'ei.value_id');
130+
$select->join(['ei' => $attributeTableName], 'ei.entity_id = e.entity_id AND ei.store_id != 0', '');
131+
$select->join(['s' => $this->attributeResource->getTable('store')], 's.store_id = ei.store_id', '');
132+
$select->join(['sg' => $this->attributeResource->getTable('store_group')], 'sg.group_id = s.group_id', '');
133+
$select->joinLeft(
134+
['pw' => $this->attributeResource->getTable('catalog_product_website')],
135+
'pw.website_id = sg.website_id AND pw.product_id = e.entity_id',
136+
''
137+
);
138+
$select->where('pw.product_id is null');
139+
return $connection->fetchCol($select);
140+
}
141+
}

app/code/Magento/Catalog/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@
493493
<arguments>
494494
<argument name="commands" xsi:type="array">
495495
<item name="imagesResizeCommand" xsi:type="object">Magento\Catalog\Console\Command\ImagesResizeCommand</item>
496+
<item name="productAttributesCleanUp" xsi:type="object">Magento\Catalog\Console\Command\ProductAttributesCleanUp</item>
496497
</argument>
497498
</arguments>
498499
</type>

app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function processPaymentConfiguration(array &$configuration, array $eleme
147147
'customEntry' => 'billingAddress' . $paymentCode . '.region',
148148
],
149149
'validation' => [
150-
'validate-select' => true,
150+
'required-entry' => true,
151151
],
152152
'filterBy' => [
153153
'target' => '${ $.provider }:${ $.parentScope }.country_id',

app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
<item name="customEntry" xsi:type="string">shippingAddress.region</item>
198198
</item>
199199
<item name="validation" xsi:type="array">
200-
<item name="validate-select" xsi:type="string">true</item>
200+
<item name="required-entry" xsi:type="boolean">true</item>
201201
</item>
202202
<!-- Value of region_id field is filtered by the value of county_id attribute -->
203203
<item name="filterBy" xsi:type="array">

app/code/Magento/Checkout/view/frontend/web/js/view/payment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ define(
5353
stepNavigator.registerStep(
5454
'payment',
5555
null,
56-
'Review & Payments',
56+
$t('Review & Payments'),
5757
this.isVisible,
5858
_.bind(this.navigate, this),
5959
20

app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ define(
8383
stepNavigator.registerStep(
8484
'shipping',
8585
'',
86-
'Shipping',
86+
$t('Shipping'),
8787
this.visible, _.bind(this.navigate, this),
8888
10
8989
);

app/code/Magento/Checkout/view/frontend/web/template/cart/totals/grand-total.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-->
77
<tr class="grand totals">
88
<th class="mark" colspan="1" scope="row">
9-
<strong data-bind="text: title"></strong>
9+
<strong data-bind="i18n: title"></strong>
1010
</th>
1111
<td class="amount" data-th="Order Total">
1212
<strong><span class="price" data-bind="text: getValue()"></span></strong>

app/code/Magento/Checkout/view/frontend/web/template/cart/totals/subtotal.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
-->
77
<tr class="totals sub">
8-
<th class="mark" colspan="1" scope="row" data-bind="text: title"></th>
8+
<th class="mark" colspan="1" scope="row" data-bind="i18n: title"></th>
99
<td class="amount" data-th="Subtotal">
1010
<span class="price" data-bind="text: getValue()"></span>
1111
</td>

app/code/Magento/Checkout/view/frontend/web/template/payment.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
-->
77
<li id="payment" role="presentation" class="checkout-payment-method" data-bind="fadeVisible: isVisible">
8-
<div class="step-title" data-bind="text: title" data-role="title"></div>
8+
<div class="step-title" data-bind="i18n: title" data-role="title"></div>
99
<div id="checkout-step-payment"
1010
class="step-content"
1111
data-role="content"

app/code/Magento/Checkout/view/frontend/web/template/summary/shipping.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- ko if: quoteIsVirtual == 0 -->
88
<tr class="totals shipping excl">
99
<th class="mark" scope="row">
10-
<span class="label" data-bind="text: title"></span>
10+
<span class="label" data-bind="i18n: title"></span>
1111
<span class="value" data-bind="text: getShippingMethodTitle()"></span>
1212
</th>
1313
<td class="amount">

0 commit comments

Comments
 (0)