Skip to content

Commit

Permalink
Merge pull request #271 from silverstripe/patch/reset-state-on-varian…
Browse files Browse the repository at this point in the history
…t-completion

FIX: #270 - Reset variant state back to original state after processing
  • Loading branch information
robbieaverill authored Jan 8, 2020
2 parents df8cf3d + 72bc71a commit 53b373f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Solr/Reindex/Handlers/SolrReindexBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ protected function processVariant(
$batchSize,
$taskName
) {
// Get current state
$originalState = SearchVariant::current_state();
// Set state
SearchVariant::activate_state($state);

Expand All @@ -122,6 +124,9 @@ protected function processVariant(
for ($group = 0; $group < $groups; $group++) {
$this->processGroup($logger, $indexInstance, $state, $class, $groups, $group, $taskName);
}

// Reset state to originalState
SearchVariant::activate_state($originalState);
}

/**
Expand Down Expand Up @@ -168,7 +173,11 @@ public function runGroup(
) {
// Set time limit and state
Environment::increaseTimeLimitTo();
// Get current state
$originalState = SearchVariant::current_state();
// Set state
SearchVariant::activate_state($state);

$logger->info("Adding $class");

// Prior to adding these records to solr, delete existing solr records
Expand All @@ -187,6 +196,9 @@ public function runGroup(
}
$logger->info("Updated " . implode(',', $processed));

// Reset state to originalState
SearchVariant::activate_state($originalState);

// This will slow down things a tiny bit, but it is done so that we don't timeout to the database during a reindex
DB::query('SELECT 1');

Expand Down

0 comments on commit 53b373f

Please sign in to comment.