From 367343c4811b8f9a8ad400886eb30b2955e163a5 Mon Sep 17 00:00:00 2001 From: Dylan Wagstaff Date: Fri, 23 Feb 2018 16:46:44 +1300 Subject: [PATCH] FIX permit reindexing on a Windows machine It appears that when executing in a Microsoft Windows environment the default shell used in the immediate reindex handler is CMD, which has some severely different syntax support from that of a POSIX machine (e.g. GNU bash). This leads to errors to do with double escaping certain parameters passed in via the CLI - culminating in an Injector error about an non-extant class e.g. 'SilverStripe\\CMS\\Model\\SiteTree' - two slashes a namespace separator does not make! --- .../Handlers/SolrReindexImmediateHandler.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Solr/Reindex/Handlers/SolrReindexImmediateHandler.php b/src/Solr/Reindex/Handlers/SolrReindexImmediateHandler.php index c6df3b0..745c94c 100644 --- a/src/Solr/Reindex/Handlers/SolrReindexImmediateHandler.php +++ b/src/Solr/Reindex/Handlers/SolrReindexImmediateHandler.php @@ -60,19 +60,21 @@ class SolrReindexImmediateHandler extends SolrReindexBase $group, $taskName ) { - // Build state + $indexClass = get_class($indexInstance); + + // Build script parameters + $indexClassEscaped = $indexClass; $statevar = json_encode($state); + if (strpos(PHP_OS, "WIN") !== false) { $statevar = '"'.str_replace('"', '\\"', $statevar).'"'; } else { $statevar = "'".$statevar."'"; + $class = addslashes($class); + $indexClassEscaped = addslashes($indexClass); } - // Build script - $indexName = $indexInstance->getIndexName(); - $indexClass = get_class($indexInstance); - $indexClassEscaped = addslashes($indexClass); - $class = addslashes($class); + // Build script line $frameworkPath = ModuleLoader::getModule('silverstripe/framework')->getPath(); $scriptPath = sprintf("%s%scli-script.php", $frameworkPath, DIRECTORY_SEPARATOR); $scriptTask = "php {$scriptPath} dev/tasks/{$taskName}";