File tree Expand file tree Collapse file tree 3 files changed +30
-6
lines changed
lib/internal/Magento/Framework/Indexer/SaveHandler Expand file tree Collapse file tree 3 files changed +30
-6
lines changed Original file line number Diff line number Diff line change 5
5
*/
6
6
namespace Magento \Theme \Model \Indexer \Design ;
7
7
8
+ use Magento \Framework \App \ObjectManager ;
8
9
use Magento \Framework \Indexer \ActionInterface ;
9
10
use Magento \Framework \Indexer \FieldsetPool ;
10
11
use Magento \Framework \Indexer \HandlerPool ;
@@ -93,13 +94,30 @@ protected function execute(array $ids = [])
93
94
/** @var \Magento\Theme\Model\ResourceModel\Design\Config\Scope\Collection $collection */
94
95
$ collection = $ this ->collectionFactory ->create ();
95
96
$ this ->prepareFields ();
96
- if (!count ($ ids )) {
97
+
98
+ $ tmp = $ this ->isFlatTableExists ();
99
+
100
+ if (!$ this ->isFlatTableExists ()) {
101
+ // instead of clean index check if table exists and create it if not
97
102
$ this ->getSaveHandler ()->cleanIndex ([]);
98
103
}
99
104
$ this ->getSaveHandler ()->deleteIndex ([], new \ArrayObject ($ ids ));
100
105
$ this ->getSaveHandler ()->saveIndex ([], $ collection );
101
106
}
102
107
108
+ private function isFlatTableExists ()
109
+ {
110
+ /** @var \Magento\Framework\App\ResourceConnection $resource */
111
+ $ resource = ObjectManager::getInstance ()->get (\Magento \Framework \App \ResourceConnection::class);
112
+
113
+ /** @var \Magento\Framework\DB\Adapter\AdapterInterface $connection */
114
+ $ connection = ObjectManager::getInstance ()->get (\Magento \Framework \App \ResourceConnection::class)->getConnection ();
115
+
116
+ $ tableName = $ resource ->getTableName ('design_config_grid_flat ' );
117
+
118
+ return $ connection ->isTableExists ($ tableName );
119
+ }
120
+
103
121
/**
104
122
* Execute full indexation
105
123
*
Original file line number Diff line number Diff line change 17
17
<field name =" store_group_id" xsi : type =" filterable" dataType =" int" />
18
18
<field name =" store_id" xsi : type =" filterable" dataType =" int" />
19
19
</fieldset >
20
- <saveHandler class =" Magento\Theme\Model\ Indexer\Design\IndexerHandler " />
20
+ <saveHandler class =" Magento\Framework\ Indexer\SaveHandler\Grid " />
21
21
<structure class =" Magento\Framework\Indexer\GridStructure" />
22
22
</indexer >
23
23
</config >
Original file line number Diff line number Diff line change @@ -69,10 +69,16 @@ protected function prepareFilterableFields(array $documents)
69
69
*/
70
70
public function deleteIndex ($ dimensions , \Traversable $ ids )
71
71
{
72
- foreach ($ this ->batch ->getItems ($ ids , $ this ->batchSize ) as $ batchIds ) {
73
- $ this ->connection ->delete (
74
- $ this ->getTableName ('filterable ' , $ dimensions ),
75
- ['entity_id IN(?) ' => $ batchIds ]
72
+ if (!empty (iterator_to_array ($ ids ))) {
73
+ foreach ($ this ->batch ->getItems ($ ids , $ this ->batchSize ) as $ batchIds ) {
74
+ $ this ->connection ->delete (
75
+ $ this ->getTableName ('filterable ' , $ dimensions ),
76
+ ['entity_id IN(?) ' => $ batchIds ]
77
+ );
78
+ }
79
+ } else {
80
+ $ this ->connection ->truncateTable (
81
+ $ this ->getTableName ('filterable ' , $ dimensions )
76
82
);
77
83
}
78
84
}
You can’t perform that action at this time.
0 commit comments