Skip to content

Commit 81c6cce

Browse files
Merge pull request #629 from magento-fearless-kiwis/MAGETWO-61531
MAGETWO-61531: Paypal SSL Curl communication error, TLS 1.2
2 parents 6f19a3d + 4abe90f commit 81c6cce

File tree

7 files changed

+459
-22
lines changed

7 files changed

+459
-22
lines changed

app/code/Magento/Ui/Component/MassAction/Filter.php

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\View\Element\UiComponentInterface;
1313
use Magento\Framework\Data\Collection\AbstractDb;
14+
use Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface;
1415

1516
/**
1617
* Class Filter
@@ -43,6 +44,11 @@ class Filter
4344
*/
4445
protected $filterBuilder;
4546

47+
/**
48+
* @var DataProviderInterface
49+
*/
50+
private $dataProvider;
51+
4652
/**
4753
* @param UiComponentFactory $factory
4854
* @param RequestInterface $request
@@ -74,23 +80,33 @@ public function getComponent()
7480
}
7581

7682
/**
83+
* Adds filters to collection using DataProvider filter results
84+
*
7785
* @param AbstractDb $collection
7886
* @return AbstractDb
7987
* @throws LocalizedException
8088
*/
8189
public function getCollection(AbstractDb $collection)
8290
{
83-
$component = $this->getComponent();
84-
$this->prepareComponent($component);
85-
$dataProvider = $component->getContext()->getDataProvider();
86-
$dataProvider->setLimit(0, false);
87-
$ids = [];
88-
foreach ($dataProvider->getSearchResult()->getItems() as $document) {
89-
$ids[] = $document->getId();
90-
}
91+
$selected = $this->request->getParam(static::SELECTED_PARAM);
92+
$excluded = $this->request->getParam(static::EXCLUDED_PARAM);
9193

92-
$collection->addFieldToFilter($collection->getIdFieldName(), ['in' => $ids]);
93-
return $this->applySelection($collection);
94+
$isExcludedIdsValid = (is_array($excluded) && !empty($excluded));
95+
$isSelectedIdsValid = (is_array($selected) && !empty($selected));
96+
97+
if ('false' !== $excluded) {
98+
if (!$isExcludedIdsValid && !$isSelectedIdsValid) {
99+
throw new LocalizedException(__('Please select item(s).'));
100+
}
101+
}
102+
$idsArray = $this->getFilterIds();
103+
if (!empty($idsArray)) {
104+
$collection->addFieldToFilter(
105+
$collection->getIdFieldName(),
106+
['in' => $idsArray]
107+
);
108+
}
109+
return $collection;
94110
}
95111

96112
/**
@@ -106,9 +122,7 @@ public function applySelectionOnTargetProvider()
106122
if ('false' === $excluded) {
107123
return;
108124
}
109-
$component = $this->getComponent();
110-
$this->prepareComponent($component);
111-
$dataProvider = $component->getContext()->getDataProvider();
125+
$dataProvider = $this->getDataProvider();
112126
try {
113127
if (is_array($excluded) && !empty($excluded)) {
114128
$this->filterBuilder->setConditionType('nin')
@@ -127,6 +141,8 @@ public function applySelectionOnTargetProvider()
127141
}
128142

129143
/**
144+
* Applies selection to collection from POST parameters
145+
*
130146
* @param AbstractDb $collection
131147
* @return AbstractDb
132148
* @throws LocalizedException
@@ -169,7 +185,7 @@ public function prepareComponent(UiComponentInterface $component)
169185
}
170186

171187
/**
172-
* Returns RefererUrl
188+
* Returns Referrer Url
173189
*
174190
* @return string|null
175191
*/
@@ -178,4 +194,33 @@ public function getComponentRefererUrl()
178194
$data = $this->getComponent()->getContext()->getDataProvider()->getConfigData();
179195
return (isset($data['referer_url'])) ? $data['referer_url'] : null;
180196
}
197+
198+
/**
199+
* Get data provider
200+
*
201+
* @return DataProviderInterface
202+
*/
203+
private function getDataProvider()
204+
{
205+
if (!$this->dataProvider) {
206+
$component = $this->getComponent();
207+
$this->prepareComponent($component);
208+
$this->dataProvider = $component->getContext()->getDataProvider();
209+
}
210+
return $this->dataProvider;
211+
}
212+
213+
/**
214+
* Get filter ids as array
215+
*
216+
* @return int[]
217+
*/
218+
private function getFilterIds()
219+
{
220+
$this->applySelectionOnTargetProvider();
221+
if ($this->getDataProvider()->getSearchResult()) {
222+
return $this->getDataProvider()->getSearchResult()->getAllIds();
223+
}
224+
return [];
225+
}
181226
}

0 commit comments

Comments
 (0)