Skip to content

Commit

Permalink
feat: added support for running rebuild task with specific version mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rasstislav committed Oct 20, 2023
1 parent e65f8d9 commit f5f6a0a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Dev/Task/RebuildAllIndexesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Versioned\Versioned;
use Throwable;

/**
Expand Down Expand Up @@ -40,11 +41,19 @@ class RebuildAllIndexesTask extends BuildTask
*/
public function run($request): void
{
foreach (ClassInfo::subclassesFor(Index::class, false) as $indexClass) {
/** @var Index $index */
$index = Injector::inst()->create($indexClass);
$stage = $request->getVar('stage');

$index->rebuild();
}
Versioned::withVersionedMode(function () use ($stage) {
if ($stage) {
Versioned::set_stage($stage);
}

foreach (ClassInfo::subclassesFor(Index::class, false) as $indexClass) {
/** @var Index $index */
$index = Injector::inst()->create($indexClass);

$index->rebuild();
}
});
}
}

0 comments on commit f5f6a0a

Please sign in to comment.