Skip to content

Commit 44f95e4

Browse files
committed
Merge remote-tracking branch 'upstream/2.1-develop' into MAGETWO-84432-magento-magento2-12368
2 parents 6829b27 + 95eaf87 commit 44f95e4

File tree

26 files changed

+32157
-3753
lines changed

26 files changed

+32157
-3753
lines changed

app/code/Magento/Catalog/Block/Product/ListProduct.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,21 @@ public function prepareSortableFieldsByCategory($category)
318318
public function getIdentities()
319319
{
320320
$identities = [];
321-
foreach ($this->_getProductCollection() as $item) {
322-
$identities = array_merge($identities, $item->getIdentities());
323-
}
321+
324322
$category = $this->getLayer()->getCurrentCategory();
325323
if ($category) {
326324
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $category->getId();
327325
}
326+
327+
//Check if category page shows only static block (No products)
328+
if ($category->getData('display_mode') == Category::DM_PAGE) {
329+
return $identities;
330+
}
331+
332+
foreach ($this->_getProductCollection() as $item) {
333+
$identities = array_merge($identities, $item->getIdentities());
334+
}
335+
328336
return $identities;
329337
}
330338

app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function testGetIdentities()
179179
->will($this->returnValue($currentCategory));
180180

181181
$this->assertEquals(
182-
[$productTag, $categoryTag ],
182+
[$categoryTag, $productTag],
183183
$this->block->getIdentities()
184184
);
185185
}

app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ protected function _reindexRows($productIds = [])
248248
}
249249
}
250250

251-
$this->cacheContext->registerEntities(Product::CACHE_TAG, $productIds);
251+
$this->cacheContext->registerEntities(Product::CACHE_TAG, $processIds);
252252
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
253253

254254
return $this;

app/code/Magento/Cms/Controller/Adminhtml/Page/PostDataProcessor.php

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
*/
77
namespace Magento\Cms\Controller\Adminhtml\Page;
88

9+
use Magento\Cms\Model\Page\DomValidationState;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Config\Dom\ValidationException;
12+
13+
/**
14+
* Class PostDataProcessor
15+
* @package Magento\Cms\Controller\Adminhtml\Page
16+
*/
917
class PostDataProcessor
1018
{
1119
/**
@@ -23,19 +31,28 @@ class PostDataProcessor
2331
*/
2432
protected $messageManager;
2533

34+
/**
35+
* @var DomValidationState
36+
*/
37+
private $validationState;
38+
2639
/**
2740
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
2841
* @param \Magento\Framework\Message\ManagerInterface $messageManager
2942
* @param \Magento\Framework\View\Model\Layout\Update\ValidatorFactory $validatorFactory
43+
* @param DomValidationState $validationState
3044
*/
3145
public function __construct(
3246
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
3347
\Magento\Framework\Message\ManagerInterface $messageManager,
34-
\Magento\Framework\View\Model\Layout\Update\ValidatorFactory $validatorFactory
48+
\Magento\Framework\View\Model\Layout\Update\ValidatorFactory $validatorFactory,
49+
DomValidationState $validationState = null
3550
) {
3651
$this->dateFilter = $dateFilter;
3752
$this->messageManager = $messageManager;
3853
$this->validatorFactory = $validatorFactory;
54+
$this->validationState = $validationState
55+
?: ObjectManager::getInstance()->get(DomValidationState::class);
3956
}
4057

4158
/**
@@ -61,27 +78,27 @@ public function filter($data)
6178
* Validate post data
6279
*
6380
* @param array $data
64-
* @return bool Return FALSE if someone item is invalid
81+
* @return bool Return FALSE if some item is invalid
6582
*/
6683
public function validate($data)
6784
{
68-
$errorNo = true;
6985
if (!empty($data['layout_update_xml']) || !empty($data['custom_layout_update_xml'])) {
70-
/** @var $validatorCustomLayout \Magento\Framework\View\Model\Layout\Update\Validator */
71-
$validatorCustomLayout = $this->validatorFactory->create();
72-
if (!empty($data['layout_update_xml']) && !$validatorCustomLayout->isValid($data['layout_update_xml'])) {
73-
$errorNo = false;
74-
}
75-
if (!empty($data['custom_layout_update_xml'])
76-
&& !$validatorCustomLayout->isValid($data['custom_layout_update_xml'])
77-
) {
78-
$errorNo = false;
79-
}
80-
foreach ($validatorCustomLayout->getMessages() as $message) {
81-
$this->messageManager->addError($message);
86+
/** @var $layoutXmlValidator \Magento\Framework\View\Model\Layout\Update\Validator */
87+
$layoutXmlValidator = $this->validatorFactory->create(
88+
[
89+
'validationState' => $this->validationState,
90+
]
91+
);
92+
93+
if (!$this->validateData($data, $layoutXmlValidator)) {
94+
$validatorMessages = $layoutXmlValidator->getMessages();
95+
foreach ($validatorMessages as $message) {
96+
$this->messageManager->addErrorMessage($message);
97+
}
98+
return false;
8299
}
83100
}
84-
return $errorNo;
101+
return true;
85102
}
86103

87104
/**
@@ -108,4 +125,32 @@ public function validateRequireEntry(array $data)
108125
}
109126
return $errorNo;
110127
}
128+
129+
/**
130+
* Validate data, avoid cyclomatic complexity
131+
*
132+
* @param array $data
133+
* @param \Magento\Framework\View\Model\Layout\Update\Validator $layoutXmlValidator
134+
* @return bool
135+
*/
136+
private function validateData($data, $layoutXmlValidator)
137+
{
138+
try {
139+
if (!empty($data['layout_update_xml']) && !$layoutXmlValidator->isValid($data['layout_update_xml'])) {
140+
return false;
141+
}
142+
if (!empty($data['custom_layout_update_xml']) &&
143+
!$layoutXmlValidator->isValid($data['custom_layout_update_xml'])
144+
) {
145+
return false;
146+
}
147+
} catch (ValidationException $e) {
148+
return false;
149+
} catch (\Exception $e) {
150+
$this->messageManager->addExceptionMessage($e, $e->getMessage());
151+
return false;
152+
}
153+
154+
return true;
155+
}
111156
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Application config file resolver
4+
*
5+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
namespace Magento\Cms\Model\Page;
9+
10+
/**
11+
* Class DomValidationState
12+
* @package Magento\Cms\Model\Page
13+
*/
14+
class DomValidationState implements \Magento\Framework\Config\ValidationStateInterface
15+
{
16+
/**
17+
* Retrieve validation state
18+
* Used in cms page post processor to force validate layout update xml
19+
*
20+
* @return boolean
21+
*/
22+
public function isValidationRequired()
23+
{
24+
return true;
25+
}
26+
}

app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Output\OutputInterface;
10+
use Magento\Framework\Indexer;
11+
use Magento\Framework\Mview;
1012

1113
/**
1214
* Command for displaying status of indexers.
@@ -30,21 +32,84 @@ protected function configure()
3032
*/
3133
protected function execute(InputInterface $input, OutputInterface $output)
3234
{
35+
$table = $this->getHelperSet()->get('table');
36+
$table->setHeaders(['Title', 'Status', 'Update On', 'Schedule Status', 'Schedule Updated']);
37+
38+
$rows = [];
39+
3340
$indexers = $this->getIndexers($input);
3441
foreach ($indexers as $indexer) {
35-
$status = 'unknown';
36-
switch ($indexer->getStatus()) {
37-
case \Magento\Framework\Indexer\StateInterface::STATUS_VALID:
38-
$status = 'Ready';
39-
break;
40-
case \Magento\Framework\Indexer\StateInterface::STATUS_INVALID:
41-
$status = 'Reindex required';
42-
break;
43-
case \Magento\Framework\Indexer\StateInterface::STATUS_WORKING:
44-
$status = 'Processing';
45-
break;
42+
$view = $indexer->getView();
43+
44+
$rowData = [
45+
'Title' => $indexer->getTitle(),
46+
'Status' => $this->getStatus($indexer),
47+
'Update On' => $indexer->isScheduled() ? 'Schedule' : 'Save',
48+
'Schedule Status' => '',
49+
'Updated' => '',
50+
];
51+
52+
if ($indexer->isScheduled()) {
53+
$state = $view->getState();
54+
$rowData['Schedule Status'] = "{$state->getStatus()} ({$this->getPendingCount($view)} in backlog)";
55+
$rowData['Updated'] = $state->getUpdated();
4656
}
47-
$output->writeln(sprintf('%-50s ', $indexer->getTitle() . ':') . $status);
57+
58+
$rows[] = $rowData;
59+
}
60+
61+
usort($rows, function ($comp1, $comp2) {
62+
return strcmp($comp1['Title'], $comp2['Title']);
63+
});
64+
65+
$table->addRows($rows);
66+
$table->render($output);
67+
}
68+
69+
/**
70+
* @param Indexer\IndexerInterface $indexer
71+
* @return string
72+
*/
73+
private function getStatus(Indexer\IndexerInterface $indexer)
74+
{
75+
$status = 'unknown';
76+
switch ($indexer->getStatus()) {
77+
case \Magento\Framework\Indexer\StateInterface::STATUS_VALID:
78+
$status = 'Ready';
79+
break;
80+
case \Magento\Framework\Indexer\StateInterface::STATUS_INVALID:
81+
$status = 'Reindex required';
82+
break;
83+
case \Magento\Framework\Indexer\StateInterface::STATUS_WORKING:
84+
$status = 'Processing';
85+
break;
4886
}
87+
return $status;
88+
}
89+
90+
/**
91+
* @param Mview\ViewInterface $view
92+
* @return string
93+
*/
94+
private function getPendingCount(Mview\ViewInterface $view)
95+
{
96+
$changelog = $view->getChangelog();
97+
98+
try {
99+
$currentVersionId = $changelog->getVersion();
100+
} catch (Mview\View\ChangelogTableNotExistsException $e) {
101+
return '';
102+
}
103+
104+
$state = $view->getState();
105+
106+
$pendingCount = count($changelog->getList($state->getVersionId(), $currentVersionId));
107+
108+
$pendingString = "<error>$pendingCount</error>";
109+
if ($pendingCount <= 0) {
110+
$pendingString = "<info>$pendingCount</info>";
111+
}
112+
113+
return $pendingString;
49114
}
50115
}

0 commit comments

Comments
 (0)