NEW Use symfony/process to execute immediate system commands for reindexing

This commit is contained in:
Robbie Averill 2018-02-16 12:05:46 +13:00
parent 436b7663e1
commit de4e2ba889
2 changed files with 9 additions and 3 deletions

View File

@ -23,7 +23,8 @@
"require": {
"silverstripe/framework": "^4.0",
"monolog/monolog": "~1.15",
"ptcinc/solr-php-client": "^1.0"
"ptcinc/solr-php-client": "^1.0",
"symfony/process": "^3.2"
},
"require-dev": {
"silverstripe/cms": "^4.0",

View File

@ -8,6 +8,7 @@ use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\FullTextSearch\Solr\Solr;
use SilverStripe\FullTextSearch\Solr\SolrIndex;
use SilverStripe\ORM\DB;
use Symfony\Component\Process\Process;
/**
* Invokes an immediate reindex
@ -77,11 +78,15 @@ class SolrReindexImmediateHandler extends SolrReindexBase
$scriptTask = "php {$scriptPath} dev/tasks/{$taskName}";
$cmd = "{$scriptTask} index={$indexClassEscaped} class={$class} group={$group} groups={$groups} variantstate={$statevar}";
$cmd .= " verbose=1 2>&1";
$cmd .= " verbose=1";
$logger->info("Running '$cmd'");
// Execute script via shell
$res = $logger ? passthru($cmd) : `$cmd`;
$process = new Process($cmd);
$process->inheritEnvironmentVariables();
$process->run();
$res = $process->getOutput();
if ($logger) {
$logger->info(preg_replace('/\r\n|\n/', '$0 ', $res));
}