Skip to content

Commit 9cc94b0

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-41241
2 parents 271c82d + b37999c commit 9cc94b0

File tree

289 files changed

+4293
-1698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

289 files changed

+4293
-1698
lines changed

.travis.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
sudo: required
2+
dist: trusty
3+
14
language: php
25
php:
36
- 5.5
@@ -44,12 +47,10 @@ before_script:
4447
# Install MySQL 5.6, create DB for integration tests
4548
- >
4649
sh -c "if [ '$TEST_SUITE' = 'integration_part_1' ] || [ '$TEST_SUITE' = 'integration_part_2' ] || [ '$TEST_SUITE' = 'integration_integrity' ]; then
47-
sudo apt-get remove --purge mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5;
48-
sudo apt-get autoremove;
49-
sudo apt-get autoclean;
50-
sudo apt-add-repository ppa:ondrej/mysql-5.6 -y;
51-
sudo apt-get update;
52-
sudo apt-get install mysql-server-5.6 mysql-client-5.6;
50+
sudo apt-get remove -y -qq --purge mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5;
51+
sudo apt-get -y -qq autoremove;
52+
sudo apt-get -y -qq autoclean;
53+
sudo apt-get install -y -qq mysql-server-5.6 mysql-client-5.6;
5354
mysql -uroot -e 'SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION; CREATE DATABASE magento_integration_tests;';
5455
mv dev/tests/integration/etc/install-config-mysql.travis.php.dist dev/tests/integration/etc/install-config-mysql.php;
5556
fi"
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/Model/Product/Type/AbstractType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,12 @@ protected function _prepareOptions(\Magento\Framework\DataObject $buyRequest, $p
574574
{
575575
$transport = new \StdClass();
576576
$transport->options = [];
577+
$options = null;
577578
if ($product->getHasOptions()) {
578-
foreach ($product->getOptions() as $option) {
579+
$options = $product->getOptions();
580+
}
581+
if ($options !== null) {
582+
foreach ($options as $option) {
579583
/* @var $option \Magento\Catalog\Model\Product\Option */
580584
$group = $option->groupFactory($option->getType())
581585
->setOption($option)

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/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu
107107
$query
108108
);
109109
} elseif ($filter->getField() === 'category_ids') {
110-
return 'category_ids_index.category_id = ' . $filter->getValue();
110+
return 'category_ids_index.category_id = ' . (int) $filter->getValue();
111111
} elseif ($attribute->isStatic()) {
112112
$alias = $this->tableMapper->getMappingAlias($filter);
113113
$resultQuery = str_replace(
@@ -194,10 +194,10 @@ private function processTermSelect(FilterInterface $filter, $isNegation)
194194
$value = sprintf(
195195
'%s IN (%s)',
196196
($isNegation ? 'NOT' : ''),
197-
implode(',', $filter->getValue())
197+
implode(',', array_map([$this->connection, 'quote'], $filter->getValue()))
198198
);
199199
} else {
200-
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
200+
$value = ($isNegation ? '!' : '') . '= ' . $this->connection->quote($filter->getValue());
201201
}
202202
$resultQuery = sprintf(
203203
'%1$s.value %2$s',
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogSearch\Model\Indexer;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Framework\Indexer\IndexStructureInterface;
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Store\Model\ScopeInterface;
12+
13+
class IndexStructureFactory
14+
{
15+
/**
16+
* Object Manager instance
17+
*
18+
* @var ObjectManagerInterface
19+
*/
20+
protected $objectManager = null;
21+
22+
/**
23+
* Instance name to create
24+
*
25+
* @var string
26+
*/
27+
protected $structures = null;
28+
29+
/**
30+
* @var ScopeConfigInterface
31+
*/
32+
private $scopeConfig;
33+
34+
/**
35+
* Configuration path by which current indexer handler stored
36+
*
37+
* @var string
38+
*/
39+
private $configPath;
40+
41+
/**
42+
* Factory constructor
43+
*
44+
* @param ObjectManagerInterface $objectManager
45+
* @param ScopeConfigInterface $scopeConfig
46+
* @param string $configPath
47+
* @param string[] $structures
48+
*/
49+
public function __construct(
50+
ObjectManagerInterface $objectManager,
51+
ScopeConfigInterface $scopeConfig,
52+
$configPath,
53+
array $structures = []
54+
) {
55+
$this->objectManager = $objectManager;
56+
$this->scopeConfig = $scopeConfig;
57+
$this->configPath = $configPath;
58+
$this->structures = $structures;
59+
}
60+
61+
/**
62+
* Create index structure
63+
*
64+
* @param array $data
65+
* @return IndexStructureInterface
66+
*/
67+
public function create(array $data = [])
68+
{
69+
$currentStructure = $this->scopeConfig->getValue($this->configPath, ScopeInterface::SCOPE_STORE);
70+
if (!isset($this->structures[$currentStructure])) {
71+
throw new \LogicException(
72+
'There is no such index structure: ' . $currentStructure
73+
);
74+
}
75+
$indexStructure = $this->objectManager->create($this->structures[$currentStructure], $data);
76+
77+
if (!$indexStructure instanceof IndexStructureInterface) {
78+
throw new \InvalidArgumentException(
79+
$indexStructure . ' doesn\'t implement \Magento\Framework\Indexer\IndexStructureInterface'
80+
);
81+
}
82+
83+
return $indexStructure;
84+
}
85+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogSearch\Model\Indexer;
7+
8+
use Magento\Framework\Indexer\IndexStructureInterface;
9+
10+
class IndexStructureProxy implements IndexStructureInterface
11+
{
12+
/**
13+
* @var IndexStructureInterface
14+
*/
15+
private $indexStructureEntity;
16+
17+
/**
18+
* @var IndexStructureFactory
19+
*/
20+
private $indexStructureFactory;
21+
22+
/**
23+
* @param IndexStructureFactory $indexStructureFactory
24+
*/
25+
public function __construct(
26+
IndexStructureFactory $indexStructureFactory
27+
) {
28+
$this->indexStructureFactory = $indexStructureFactory;
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function delete(
35+
$index,
36+
array $dimensions = []
37+
) {
38+
return $this->getEntity()->delete($index, $dimensions);
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function create(
45+
$index,
46+
array $fields,
47+
array $dimensions = []
48+
) {
49+
return $this->getEntity()->create($index, $fields, $dimensions);
50+
}
51+
52+
/**
53+
* Get instance of current index structure
54+
*
55+
* @return IndexStructureInterface
56+
*/
57+
private function getEntity()
58+
{
59+
if (empty($this->indexStructureEntity)) {
60+
$this->indexStructureEntity = $this->indexStructureFactory->create();
61+
}
62+
return $this->indexStructureEntity;
63+
}
64+
}

app/code/Magento/CatalogSearch/Model/Indexer/IndexerHandler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\ResourceConnection;
1010
use Magento\Framework\DB\Adapter\AdapterInterface;
1111
use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
12+
use Magento\Framework\Indexer\IndexStructureInterface;
1213
use Magento\Framework\Search\Request\Dimension;
1314
use Magento\Framework\Search\Request\IndexScopeResolverInterface;
1415
use Magento\Framework\Indexer\SaveHandler\Batch;
@@ -17,7 +18,7 @@
1718
class IndexerHandler implements IndexerInterface
1819
{
1920
/**
20-
* @var IndexStructure
21+
* @var IndexStructureInterface
2122
*/
2223
private $indexStructure;
2324

@@ -57,7 +58,7 @@ class IndexerHandler implements IndexerInterface
5758
private $indexScopeResolver;
5859

5960
/**
60-
* @param IndexStructure $indexStructure
61+
* @param IndexStructureInterface $indexStructure
6162
* @param ResourceConnection $resource
6263
* @param Config $eavConfig
6364
* @param Batch $batch
@@ -66,7 +67,7 @@ class IndexerHandler implements IndexerInterface
6667
* @param int $batchSize
6768
*/
6869
public function __construct(
69-
IndexStructure $indexStructure,
70+
IndexStructureInterface $indexStructure,
7071
ResourceConnection $resource,
7172
Config $eavConfig,
7273
Batch $batch,

0 commit comments

Comments
 (0)