Skip to content

Commit 4765dc5

Browse files
ACPT-1360
Fixing resetState methods so that the object's state is the same as it was when first constructed
1 parent cb60376 commit 4765dc5

File tree

9 files changed

+24
-17
lines changed

9 files changed

+24
-17
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Collection/AbstractCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public function __construct(
8181
*/
8282
public function _resetState(): void
8383
{
84-
parent::_resetState();
8584
$this->_storeId = null;
85+
parent::_resetState();
8686
}
8787

8888
/**

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ public function __construct(
397397
*/
398398
public function _resetState(): void
399399
{
400-
parent::_resetState();
401400
$this->_flatEnabled = [];
402401
$this->_addUrlRewrite = false;
403402
$this->_urlRewriteCategory = '';
@@ -419,7 +418,7 @@ public function _resetState(): void
419418
$this->linkField = null;
420419
$this->backend = null;
421420
$this->emptyItem = null;
422-
$this->_construct();
421+
parent::_resetState();
423422
}
424423

425424
/**

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ public function __construct(
224224
*/
225225
public function _resetState(): void
226226
{
227-
parent::_resetState();
228227
$this->queryText = null;
229228
$this->search = null;
230229
$this->searchCriteriaBuilder = null;
231230
$this->searchResult = null;
232231
$this->filterBuilder = null;
233232
$this->searchOrders = null;
233+
parent::_resetState();
234234
}
235235

236236
/**

app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ protected function _construct()
186186
*/
187187
public function _resetState(): void
188188
{
189-
parent::_resetState();
190189
$this->_itemsById = [];
191190
$this->_staticFields = [];
192191
$this->_entity = null;
@@ -196,6 +195,11 @@ public function _resetState(): void
196195
$this->_joinEntities = [];
197196
$this->_joinAttributes = [];
198197
$this->_joinFields = [];
198+
parent::_resetState();
199+
$this->_construct();
200+
$this->setConnection($this->getEntity()->getConnection());
201+
$this->_prepareStaticFields();
202+
$this->_initSelect();
199203
}
200204

201205
/**

app/code/Magento/Eav/Model/ResourceModel/Form/Attribute/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ protected function _construct()
101101
*/
102102
public function _resetState(): void
103103
{
104-
parent::_resetState();
105104
$this->_store = null;
106105
$this->_entityType = null;
106+
parent::_resetState();
107107
}
108108

109109
/**

app/code/Magento/Reports/Model/ResourceModel/Report/Collection.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Collection extends \Magento\Framework\Data\Collection
5555
protected $_reports;
5656

5757
/**
58-
* Page size
58+
* Page size|null
5959
*
6060
* @var int
6161
*/
@@ -100,6 +100,15 @@ public function __construct(
100100
parent::__construct($entityFactory);
101101
}
102102

103+
/**
104+
* @inheritDoc
105+
*/
106+
public function _resetState(): void
107+
{
108+
$this->_pageSize = null;
109+
parent::_resetState();
110+
}
111+
103112
/**
104113
* Set period
105114
*

lib/internal/Magento/Framework/Data/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ public function __wakeup()
933933
public function _resetState(): void
934934
{
935935
$this->clear();
936-
// TODO: Is it safe to move the following into clear() ?
936+
$this->_isCollectionLoaded = null;
937937
$this->_orders = [];
938938
$this->_filters = [];
939939
$this->_isFiltersRendered = false;

lib/internal/Magento/Framework/Model/ResourceModel/Db/Collection/AbstractCollection.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,12 @@ protected function _construct() //phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
151151
public function _resetState(): void
152152
{
153153
parent::_resetState();
154-
$this->_model = null;
155-
$this->_resourceModel = null;
156154
$this->_fieldsToSelect = null;
157155
$this->expressionFieldsToSelect = [];
158156
$this->_initialFieldsToSelect = null;
159157
$this->_fieldsToSelectChanged = false;
160158
$this->_joinedTables = [];
161-
$this->_mainTable = null;
162159
$this->_resetItemsDataChanged = false;
163-
$this->_eventPrefix = '';
164-
$this->_eventObject = '';
165160
$this->_construct();
166161
$this->_initSelect();
167162
}

lib/internal/Magento/Framework/View/Asset/Repository.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ class Repository implements ResetAfterRequestInterface
5050
private $assetSource;
5151

5252
/**
53-
* @var \Magento\Framework\View\Asset\ContextInterface[]
53+
* @var \Magento\Framework\View\Asset\ContextInterface[]|null
5454
*/
5555
private $fallbackContext;
5656

5757
/**
58-
* @var \Magento\Framework\View\Asset\ContextInterface[]
58+
* @var \Magento\Framework\View\Asset\ContextInterface[]|null
5959
*/
6060
private $fileContext;
6161

@@ -475,7 +475,7 @@ private function getRepositoryFilesMap($fileId, array $params)
475475
*/
476476
public function _resetState(): void
477477
{
478-
$this->fallbackContext = [];
479-
$this->fileContext = [];
478+
$this->fallbackContext = null;
479+
$this->fileContext = null;
480480
}
481481
}

0 commit comments

Comments
 (0)