@@ -93,13 +93,15 @@ protected function _getStoreConfig($storeId = null)
93
93
* @param array|null $productIds Restrict to given Products if this is set
94
94
* @param boolean|string $emptyIndex Whether to truncate the index before refilling it
95
95
* @param null|int[] $restrictToStoreIds
96
+ * @param null|int $sliceId
97
+ * @param null|int $totalNumberSlices
96
98
* @throws \Exception
97
99
* @throws \IntegerNet\Solr\Exception
98
100
*/
99
- public function reindex ($ productIds = null , $ emptyIndex = false , $ restrictToStoreIds = null )
101
+ public function reindex ($ productIds = null , $ emptyIndex = false , $ restrictToStoreIds = null , $ sliceId = null , $ totalNumberSlices = null )
100
102
{
101
- if (is_null ($ productIds )) {
102
- $ this ->_getResource ()-> checkSwapCoresConfiguration ($ restrictToStoreIds );
103
+ if (is_null ($ productIds ) && is_null ( $ sliceId ) ) {
104
+ $ this ->checkSwapCoresConfiguration ($ restrictToStoreIds );
103
105
}
104
106
105
107
foreach ($ this ->_config as $ storeId => $ storeConfig ) {
@@ -114,40 +116,44 @@ public function reindex($productIds = null, $emptyIndex = false, $restrictToStor
114
116
$ this ->storeEmulation ->start ($ storeId );
115
117
try {
116
118
117
- if (is_null ($ productIds ) && $ storeConfig ->getIndexingConfig ()->isSwapCores ()) {
118
- $ this ->_getResource ()-> setUseSwapIndex ();
119
+ if (is_null ($ productIds ) && is_null ( $ sliceId ) && $ storeConfig ->getIndexingConfig ()->isSwapCores ()) {
120
+ $ this ->activateSwapCore ();
119
121
}
120
122
121
123
if (
122
- ($ emptyIndex && $ storeConfig ->getIndexingConfig ()->isDeleteDocumentsBeforeIndexing ())
124
+ ($ emptyIndex && is_null ( $ sliceId ) && $ storeConfig ->getIndexingConfig ()->isDeleteDocumentsBeforeIndexing ())
123
125
|| $ emptyIndex === 'force '
124
126
) {
125
- $ this ->_getResource ()-> deleteAllDocuments ( $ storeId, self :: CONTENT_TYPE );
127
+ $ this ->clearIndex ( $ storeId );
126
128
}
127
129
128
130
$ pageSize = intval ($ storeConfig ->getIndexingConfig ()->getPagesize ());
129
131
if ($ pageSize <= 0 ) {
130
132
$ pageSize = 100 ;
131
133
}
132
134
135
+ if ($ productIds == null ) {
136
+ $ productIds = $ this ->productRepository ->getAllProductIds ($ sliceId , $ totalNumberSlices );
137
+ }
138
+
133
139
$ associations = $ this ->productRepository ->getProductAssociations ($ productIds );
134
140
$ chunks = ProductIdChunks::withAssociationsTogether (
135
- $ productIds == null ? $ this -> productRepository -> getAllProductIds () : $ productIds ,
141
+ $ productIds ,
136
142
$ associations ,
137
143
$ pageSize );
138
144
$ productIterator = $ this ->productRepository ->getProductsInChunks ($ storeId , $ chunks );
139
145
$ this ->_indexProductCollection ($ emptyIndex , $ productIterator , $ storeId , $ productIds , $ associations );
140
146
141
- $ this ->_getResource ()-> setUseSwapIndex ( false );
147
+ $ this ->deactivateSwapCore ( );
142
148
} catch (\Exception $ e ) {
143
149
$ this ->storeEmulation ->stop ();
144
150
throw $ e ;
145
151
}
146
152
$ this ->storeEmulation ->stop ();
147
153
}
148
154
149
- if (is_null ($ productIds )) {
150
- $ this ->_getResource ()-> swapCores ($ restrictToStoreIds );
155
+ if (is_null ($ productIds ) && is_null ( $ sliceId ) ) {
156
+ $ this ->swapCores ($ restrictToStoreIds );
151
157
}
152
158
}
153
159
@@ -514,5 +520,39 @@ protected function _indexProductCollection($emptyIndex, PagedProductIterator $pr
514
520
return $ storeId ;
515
521
}
516
522
523
+ /**
524
+ * @param $storeId
525
+ */
526
+ public function clearIndex ($ storeId )
527
+ {
528
+ $ this ->_getResource ()->deleteAllDocuments ($ storeId , self ::CONTENT_TYPE );
529
+ }
530
+
531
+ public function activateSwapCore ()
532
+ {
533
+ $ this ->_getResource ()->setUseSwapIndex ();
534
+ }
535
+
536
+ public function deactivateSwapCore ()
537
+ {
538
+ $ this ->_getResource ()->setUseSwapIndex (false );
539
+ }
540
+
541
+ /**
542
+ * @param null|int[] $restrictToStoreIds
543
+ */
544
+ public function swapCores ($ restrictToStoreIds )
545
+ {
546
+ $ this ->_getResource ()->swapCores ($ restrictToStoreIds );
547
+ }
548
+
549
+ /**
550
+ * @param $restrictToStoreIds
551
+ */
552
+ public function checkSwapCoresConfiguration ($ restrictToStoreIds )
553
+ {
554
+ return $ this ->_getResource ()->checkSwapCoresConfiguration ($ restrictToStoreIds );
555
+ }
556
+
517
557
518
558
}
0 commit comments