Skip to content

Commit e128283

Browse files
committed
6775 Refactor to use seperate command "reindex_slice" for reindexing slices
1 parent cebae8c commit e128283

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

src/shell/integernet-solr.php

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ public function run()
3232
$entityTypes = explode(',', $entityTypes);
3333
}
3434

35-
$sliceId = null;
36-
$totalNumberSlices = null;
37-
if ($sliceArg = $this->getArg('slice')) {
38-
list($sliceId, $totalNumberSlices) = explode('/', $sliceArg);
39-
}
40-
4135
$emptyIndex = true;
4236
if ($this->getArg('emptyindex')) {
4337
$emptyIndex = 'force';
@@ -49,25 +43,11 @@ public function run()
4943
$autoloader->createAndRegister();
5044

5145
try {
52-
$this->_checkSliceArgument($sliceArg);
53-
5446
if (in_array('product', $entityTypes)) {
55-
5647
$indexer = Mage::helper('integernet_solr')->factory()->getProductIndexer();
57-
58-
if ($this->getArg('use_swap_core')) {
59-
$indexer->activateSwapCore();
60-
}
61-
$indexer->reindex(null, $emptyIndex, $storeIds, $sliceId, $totalNumberSlices);
62-
if ($this->getArg('use_swap_core')) {
63-
$indexer->deactivateSwapCore();
64-
}
65-
48+
$indexer->reindex(null, $emptyIndex, $storeIds);
6649
$storeIdsString = implode(', ', $storeIds);
6750
echo "Solr product index rebuilt for Stores {$storeIdsString}.\n";
68-
if (!is_null($sliceId) && !is_null($totalNumberSlices)) {
69-
echo '(Slice ' . $sliceId . ' of ' . $totalNumberSlices . ')' . "\n";
70-
}
7151
}
7252

7353
if (in_array('page', $entityTypes) && $this->_useCmsIndexer()) {
@@ -87,6 +67,38 @@ public function run()
8767
echo $e->getMessage() . "\n";
8868
}
8969

70+
} else if ($this->getArg('reindex_slice')) {
71+
$storeIdentifiers = $this->getArg('stores');
72+
if (!$storeIdentifiers) {
73+
$storeIdentifiers = 'all';
74+
}
75+
$storeIds = $this->_getStoreIds($storeIdentifiers);
76+
77+
$autoloader = new IntegerNet_Solr_Helper_Autoloader();
78+
$autoloader->createAndRegister();
79+
80+
try {
81+
$sliceArg = $this->getArg('slice');
82+
$this->_checkSliceArgument($sliceArg);
83+
list($sliceId, $totalNumberSlices) = explode('/', $sliceArg);
84+
85+
$indexer = Mage::helper('integernet_solr')->factory()->getProductIndexer();
86+
87+
if ($this->getArg('use_swap_core')) {
88+
$indexer->activateSwapCore();
89+
}
90+
$indexer->reindex(null, false, $storeIds, $sliceId, $totalNumberSlices);
91+
if ($this->getArg('use_swap_core')) {
92+
$indexer->deactivateSwapCore();
93+
}
94+
95+
$storeIdsString = implode(', ', $storeIds);
96+
echo "Solr product index rebuilt for Stores {$storeIdsString}.\n";
97+
echo '(Slice ' . $sliceId . ' of ' . $totalNumberSlices . ')' . "\n";
98+
} catch (Exception $e) {
99+
echo $e->getMessage() . "\n";
100+
}
101+
90102
} else if ($this->getArg('clear')) {
91103
$storeIdentifiers = $this->getArg('stores');
92104
if (!$storeIdentifiers) {
@@ -145,12 +157,18 @@ public function usageHelp()
145157
--emptyindex Force emptying the solr index for the given store(s). If not set, configured value is used.
146158
--noemptyindex Force not emptying the solr index for the given store(s). If not set, configured value is used.
147159
--types <types> Restrict indexing to certain entity types, i.e. "product", "category" or "page" (comma separated). Or "all". If not set, reindex products.
148-
--slice <number>/<total_number>, i.e. "1/5" or "2/5". Use this if you want to index only a part of the products, i.e. for letting indexing run in parallel (for products only).
149-
--use_swap_core Use swap core for indexing instead of live solr core (only if configured correctly) (for products only). This is useful if using slices (see above), it's not needed otherwise.
160+
161+
reindex_slice Reindex solr for given stores (see "stores" param). Use this if you want to index only a part of the products, i.e. for letting indexing run in parallel (for products only).
162+
--slice <number>/<total_number>, i.e. "1/5" or "2/5".
163+
--stores <stores> Reindex given stores (can be store id, store code, comma seperated. Or "all".) If not set, reindex all stores.
164+
--use_swap_core Use swap core for indexing instead of live solr core (only if configured correctly).
150165
151166
clear Clear solr product index for given stores (see "stores" param and "use_swap_core" param)
167+
--stores <stores> Reindex given stores (can be store id, store code, comma seperated. Or "all".) If not set, reindex all stores.
168+
--use_swap_core Use swap core for clearing instead of live solr core (only if configured correctly).
152169
153-
swap-cores Swap cores. This is useful if using slices (see above) after indexing with the "--use_swap_core" param; it's not needed otherwise. See "stores" param.
170+
swap_cores Swap cores. This is useful if using slices (see above) after indexing with the "--use_swap_core" param; it's not needed otherwise.
171+
--stores <stores> Reindex given stores (can be store id, store code, comma seperated. Or "all".) If not set, reindex all stores.
154172
155173
help This help
156174
@@ -221,7 +239,7 @@ protected function _useCmsIndexer()
221239
protected function _checkSliceArgument($sliceArg)
222240
{
223241
if (!strlen($sliceArg)) {
224-
return;
242+
throw new InvalidArgumentException('The "slice" argument must be given.');
225243
}
226244
if (strpos($sliceArg, '/') < 1) {
227245
throw new InvalidArgumentException('The "slice" argument must be of format "1/5" or "20/20"');

0 commit comments

Comments
 (0)