Skip to content

Commit 805f7e2

Browse files
author
Serhiy Shkolyarenko
committed
Merge remote-tracking branch 'mainline/develop' into exception_logger
2 parents 1e16bc8 + 131ada4 commit 805f7e2

File tree

60 files changed

+2058
-109
lines changed

Some content is hidden

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

60 files changed

+2058
-109
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Magento\Catalog\Model\Indexer\Category\Product;
1010

11+
use Magento\Framework\DB\Query\BatchIteratorInterface as BatchIteratorInterface;
12+
use Magento\Framework\DB\Query\Generator as QueryGenerator;
1113
use Magento\Framework\App\ResourceConnection;
1214
use Magento\Framework\EntityManager\MetadataPool;
1315

@@ -102,20 +104,29 @@ abstract class AbstractAction
102104
*/
103105
protected $tempTreeIndexTableName;
104106

107+
/**
108+
* @var QueryGenerator
109+
*/
110+
private $queryGenerator;
111+
105112
/**
106113
* @param ResourceConnection $resource
107114
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
108115
* @param \Magento\Catalog\Model\Config $config
116+
* @param QueryGenerator $queryGenerator
109117
*/
110118
public function __construct(
111119
\Magento\Framework\App\ResourceConnection $resource,
112120
\Magento\Store\Model\StoreManagerInterface $storeManager,
113-
\Magento\Catalog\Model\Config $config
121+
\Magento\Catalog\Model\Config $config,
122+
QueryGenerator $queryGenerator = null
114123
) {
115124
$this->resource = $resource;
116125
$this->connection = $resource->getConnection();
117126
$this->storeManager = $storeManager;
118127
$this->config = $config;
128+
$this->queryGenerator = $queryGenerator ?: \Magento\Framework\App\ObjectManager::getInstance()
129+
->get(QueryGenerator::class);
119130
}
120131

121132
/**
@@ -309,15 +320,26 @@ protected function isRangingNeeded()
309320
* @param int $range
310321
* @return \Magento\Framework\DB\Select[]
311322
*/
312-
protected function prepareSelectsByRange(\Magento\Framework\DB\Select $select, $field, $range = self::RANGE_CATEGORY_STEP)
313-
{
314-
return $this->isRangingNeeded() ? $this->connection->selectsByRange(
315-
$field,
316-
$select,
317-
$range
318-
) : [
319-
$select
320-
];
323+
protected function prepareSelectsByRange(
324+
\Magento\Framework\DB\Select $select,
325+
$field,
326+
$range = self::RANGE_CATEGORY_STEP
327+
) {
328+
if($this->isRangingNeeded()) {
329+
$iterator = $this->queryGenerator->generate(
330+
$field,
331+
$select,
332+
$range,
333+
\Magento\Framework\DB\Query\BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
334+
);
335+
336+
$queries = [];
337+
foreach ($iterator as $query) {
338+
$queries[] = $query;
339+
}
340+
return $queries;
341+
}
342+
return [$select];
321343
}
322344

323345
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<field code="is_searchable" locked="true" />
3131
</attribute>
3232
<attribute code="category_ids">
33+
<field code="is_global" locked="true" />
3334
<field code="is_searchable" locked="true" />
3435
<field code="used_for_sort_by" locked="true" />
3536
<field code="is_used_in_grid" locked="true" />

app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Void.php renamed to app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/VoidAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use Magento\Backend\App\Action;
99

10-
class Void extends \Magento\Backend\App\Action
10+
class VoidAction extends Action
1111
{
1212
/**
1313
* Authorization level of a basic admin session

app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/Void.php renamed to app/code/Magento/Sales/Controller/Adminhtml/Order/Invoice/VoidAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
namespace Magento\Sales\Controller\Adminhtml\Order\Invoice;
88

9-
class Void extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View
9+
class VoidAction extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\View
1010
{
1111
/**
1212
* Void invoice action

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/VoidTest.php renamed to app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Creditmemo/VoidActionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
namespace Magento\Sales\Test\Unit\Controller\Adminhtml\Order\Creditmemo;
77

88
/**
9-
* Class VoidTest
9+
* Class VoidActionTest
1010
* @SuppressWarnings(PHPMD.TooManyFields)
1111
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1212
*/
13-
class VoidTest extends \PHPUnit_Framework_TestCase
13+
class VoidActionTest extends \PHPUnit_Framework_TestCase
1414
{
1515
/**
1616
* @var \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\AddComment
@@ -179,7 +179,7 @@ protected function setUp()
179179

180180
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
181181
$this->controller = $objectManager->getObject(
182-
\Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Void::class,
182+
\Magento\Sales\Controller\Adminhtml\Order\Creditmemo\VoidAction::class,
183183
[
184184
'context' => $this->contextMock,
185185
'creditmemoLoader' => $this->loaderMock,

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/VoidTest.php renamed to app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/VoidActionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
use Magento\Sales\Api\InvoiceRepositoryInterface;
1111

1212
/**
13-
* Class VoidTest
13+
* Class VoidActionTest
1414
* @package Magento\Sales\Controller\Adminhtml\Order\Invoice
1515
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1616
*/
17-
class VoidTest extends \PHPUnit_Framework_TestCase
17+
class VoidActionTest extends \PHPUnit_Framework_TestCase
1818
{
1919
/**
2020
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -166,7 +166,7 @@ protected function setUp()
166166
->getMockForAbstractClass();
167167

168168
$this->controller = $objectManager->getObject(
169-
\Magento\Sales\Controller\Adminhtml\Order\Invoice\Void::class,
169+
\Magento\Sales\Controller\Adminhtml\Order\Invoice\VoidAction::class,
170170
[
171171
'context' => $contextMock,
172172
'resultForwardFactory' => $this->resultForwardFactoryMock

app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,19 @@ public function setValidationFilter(
165165
\Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON
166166
);
167167

168-
$orWhereConditions = [
168+
$autoGeneratedCouponCondition = [
169169
$connection->quoteInto(
170-
'(main_table.coupon_type = ? AND rule_coupons.type = 0)',
170+
"main_table.coupon_type = ?",
171171
\Magento\SalesRule\Model\Rule::COUPON_TYPE_AUTO
172172
),
173+
$connection->quoteInto(
174+
"rule_coupons.type = ?",
175+
\Magento\SalesRule\Api\Data\CouponInterface::TYPE_GENERATED
176+
),
177+
];
178+
179+
$orWhereConditions = [
180+
"(" . implode($autoGeneratedCouponCondition, " AND ") . ")",
173181
$connection->quoteInto(
174182
'(main_table.coupon_type = ? AND main_table.use_auto_generation = 1 AND rule_coupons.type = 1)',
175183
\Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Mtf\Util\Filesystem;
7+
8+
/**
9+
* Filesystem helper.
10+
*/
11+
class FileHelper
12+
{
13+
/**
14+
* Normalizes a file/directory path.
15+
*
16+
* @param string $path
17+
* @param string $ds
18+
* @return string
19+
*/
20+
public function normalizePath($path, $ds = DIRECTORY_SEPARATOR)
21+
{
22+
$path = rtrim(strtr($path, '/\\', $ds . $ds), $ds);
23+
if (strpos($ds . $path, "{$ds}.") === false && strpos($path, "{$ds}{$ds}") === false) {
24+
return $path;
25+
}
26+
27+
return $this->realpath($ds, $path);
28+
}
29+
30+
/**
31+
* Returns canonicalized pathname.
32+
*
33+
* @param string $ds
34+
* @param string $path
35+
* @return string
36+
*/
37+
private function realpath($ds, $path)
38+
{
39+
$parts = [];
40+
foreach (explode($ds, $path) as $part) {
41+
if ($part === '..' && !empty($parts) && end($parts) !== '..') {
42+
array_pop($parts);
43+
} elseif ($part === '.' || $part === '' && !empty($parts)) {
44+
continue;
45+
} else {
46+
$parts[] = $part;
47+
}
48+
}
49+
50+
$path = implode($ds, $parts);
51+
52+
return $path === '' ? '.' : $path;
53+
}
54+
55+
/**
56+
* Creates a new directory.
57+
*
58+
* @param string $path
59+
* @param int $mode
60+
* @param bool $recursive
61+
* @return bool
62+
* @throws \Exception
63+
*/
64+
public function createDirectory($path, $mode = 0775, $recursive = true)
65+
{
66+
if (is_dir($path)) {
67+
return true;
68+
}
69+
$parentDir = dirname($path);
70+
71+
if ($recursive && !is_dir($parentDir) && $parentDir !== $path) {
72+
$this->createDirectory($parentDir, $mode, true);
73+
}
74+
75+
try {
76+
if (!mkdir($path, $mode)) {
77+
return false;
78+
}
79+
} catch (\Exception $e) {
80+
if (!is_dir($path)) {
81+
throw new \Exception("Failed to create directory \"$path\"");
82+
}
83+
}
84+
85+
try {
86+
return chmod($path, $mode);
87+
} catch (\Exception $e) {
88+
throw new \Exception("Failed to change permissions for directory \"$path\"");
89+
}
90+
}
91+
92+
/**
93+
* Create a new file with content.
94+
*
95+
* @param string $filename
96+
* @param string $content
97+
* @return bool
98+
*/
99+
public function createFile($filename, $content)
100+
{
101+
return file_put_contents($filename, $content) !== false;
102+
}
103+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Mtf\Util\Generate\File;
7+
8+
use Magento\Mtf\Util\Filesystem\FileHelper;
9+
10+
/**
11+
* File generator.
12+
*/
13+
class Generator
14+
{
15+
/**
16+
* Base directory for files.
17+
*/
18+
const ROOT_DIRECTORY = '/var/tests/data/';
19+
20+
/**
21+
* Directory for saving files.
22+
*
23+
* @var string
24+
*/
25+
private $directory;
26+
27+
/**
28+
* Filesystem helper.
29+
*
30+
* @var FileHelper
31+
*/
32+
private $fileHelper;
33+
34+
/**
35+
* @param FileHelper $fileHelper
36+
* @param string $directory
37+
*/
38+
public function __construct(FileHelper $fileHelper, $directory)
39+
{
40+
$this->fileHelper = $fileHelper;
41+
$this->directory = $this->fileHelper->normalizePath(MTF_BP . static::ROOT_DIRECTORY . $directory);
42+
}
43+
44+
/**
45+
* Method is generate file by template.
46+
*
47+
* @param TemplateInterface $template
48+
* @return string Full path to the generated file.
49+
* @throws \Exception
50+
*/
51+
public function generate(TemplateInterface $template)
52+
{
53+
$filename = $this->fileHelper->normalizePath($this->directory . '/' . $template->getName());
54+
if (!$this->fileHelper->createDirectory($this->directory)
55+
|| !$this->fileHelper->createFile($filename, $template->render())
56+
) {
57+
throw new \Exception(
58+
'Can’t create file with "' . get_class($template) .'" (file "' . $filename . '").'
59+
);
60+
}
61+
62+
return $filename;
63+
}
64+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Mtf\Util\Generate\File;
7+
8+
/**
9+
* Interface for file template.
10+
*/
11+
interface TemplateInterface
12+
{
13+
/**
14+
* Create and return file content.
15+
*
16+
* @return string
17+
*/
18+
public function render();
19+
20+
/**
21+
* Get filename. Without directory.
22+
*
23+
* @return string
24+
*/
25+
public function getName();
26+
}

0 commit comments

Comments
 (0)