File tree Expand file tree Collapse file tree 4 files changed +24
-35
lines changed
lib/internal/Magento/Framework/Indexer/SaveHandler Expand file tree Collapse file tree 4 files changed +24
-35
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 ;
9
8
use Magento \Framework \Indexer \ActionInterface ;
10
9
use Magento \Framework \Indexer \FieldsetPool ;
11
10
use Magento \Framework \Indexer \HandlerPool ;
@@ -94,30 +93,13 @@ protected function execute(array $ids = [])
94
93
/** @var \Magento\Theme\Model\ResourceModel\Design\Config\Scope\Collection $collection */
95
94
$ collection = $ this ->collectionFactory ->create ();
96
95
$ this ->prepareFields ();
97
-
98
- $ tmp = $ this ->isFlatTableExists ();
99
-
100
- if (!$ this ->isFlatTableExists ()) {
101
- // instead of clean index check if table exists and create it if not
96
+ if (!count ($ ids )) {
102
97
$ this ->getSaveHandler ()->cleanIndex ([]);
103
98
}
104
99
$ this ->getSaveHandler ()->deleteIndex ([], new \ArrayObject ($ ids ));
105
100
$ this ->getSaveHandler ()->saveIndex ([], $ collection );
106
101
}
107
102
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
-
121
103
/**
122
104
* Execute full indexation
123
105
*
Original file line number Diff line number Diff line change @@ -44,16 +44,29 @@ public function __construct(
44
44
}
45
45
46
46
/**
47
- * Clean index table by truncation
47
+ * @return bool
48
+ */
49
+ private function isFlatTableExists ()
50
+ {
51
+ $ adapter = $ this ->resource ->getConnection ('write ' );
52
+ $ tableName = $ this ->flatScopeResolver ->resolve ($ this ->getIndexName (), []);
53
+
54
+ return $ adapter ->isTableExists ($ tableName );
55
+ }
56
+
57
+ /**
58
+ * Clean index table by deleting all records
48
59
*
49
60
* @inheritdoc
50
61
*/
51
62
public function cleanIndex ($ dimensions )
52
63
{
53
- $ adapter = $ this ->resource ->getConnection ('write ' );
54
- $ tableName = $ this ->flatScopeResolver ->resolve ($ this ->getIndexName (), $ dimensions );
55
- if ($ adapter ->isTableExists ($ tableName )) {
56
- $ adapter ->truncateTable ($ tableName );
64
+ if ($ this ->isFlatTableExists ()) {
65
+ $ adapter = $ this ->resource ->getConnection ('write ' );
66
+ $ tableName = $ this ->flatScopeResolver ->resolve ($ this ->getIndexName (), $ dimensions );
67
+ $ adapter ->delete ($ tableName );
68
+ } else {
69
+ $ this ->indexStructure ->create ($ this ->getIndexName (), $ this ->fields , $ dimensions );
57
70
}
58
71
}
59
72
}
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\Framework\ Indexer\SaveHandler\Grid " />
20
+ <saveHandler class =" Magento\Theme\Model\ Indexer\Design\IndexerHandler " />
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,16 +69,10 @@ protected function prepareFilterableFields(array $documents)
69
69
*/
70
70
public function deleteIndex ($ dimensions , \Traversable $ ids )
71
71
{
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 )
72
+ foreach ($ this ->batch ->getItems ($ ids , $ this ->batchSize ) as $ batchIds ) {
73
+ $ this ->connection ->delete (
74
+ $ this ->getTableName ('filterable ' , $ dimensions ),
75
+ ['entity_id IN(?) ' => $ batchIds ]
82
76
);
83
77
}
84
78
}
You can’t perform that action at this time.
0 commit comments