1818use Firesphere \ElasticSearch \Indexes \ElasticIndex ;
1919use Firesphere \ElasticSearch \Services \ElasticCoreService ;
2020use Firesphere \SearchBackend \Helpers \FieldResolver ;
21+ use Firesphere \SearchBackend \Indexes \CoreIndex ;
2122use Firesphere \SearchBackend \Traits \LoggerTrait ;
2223use Psr \Container \NotFoundExceptionInterface ;
2324use SilverStripe \Control \HTTPRequest ;
@@ -36,14 +37,23 @@ class ElasticConfigureTask extends BuildTask
3637{
3738 use LoggerTrait;
3839
39- /**
40- * @var bool[]
41- */
42- public $ result ;
4340 /**
4441 * @var string URLSegment
4542 */
4643 private static $ segment = 'ElasticConfigureTask ' ;
44+ /**
45+ * DBHTML and DBText etc. should never be made sortable
46+ * It doesn't make sense for large text objects
47+ * @var string[]
48+ */
49+ private static $ unSsortables = [
50+ 'HTML ' ,
51+ 'Text '
52+ ];
53+ /**
54+ * @var bool[]
55+ */
56+ public $ result ;
4757 /**
4858 * @var string Title
4959 */
@@ -57,16 +67,6 @@ class ElasticConfigureTask extends BuildTask
5767 */
5868 protected $ service ;
5969
60- /**
61- * DBHTML and DBText etc. should never be made sortable
62- * It doesn't make sense for large text objects
63- * @var string[]
64- */
65- private static $ unSsortables = [
66- 'HTML ' ,
67- 'Text '
68- ];
69-
7070 /**
7171 * @throws NotFoundExceptionInterface
7272 */
@@ -95,13 +95,8 @@ public function run($request)
9595 try {
9696 /** @var ElasticIndex $instance */
9797 $ instance = Injector::inst ()->get ($ index , false );
98-
99- if ($ request ->getVar ('clear ' ) && $ instance ->indexExists ()) {
100- $ this ->getLogger ()->info (sprintf ('Clearing index %s ' , $ instance ->getIndexName ()));
101- $ deleteResult = $ this ->service ->getClient ()->indices ()->delete (['index ' => $ instance ->getIndexName ()]);
102- $ result [] = $ deleteResult ->asBool ();
103- }
104-
98+ // If delete in advance, do so
99+ $ instance ->deleteIndex ($ request );
105100 $ configResult = $ this ->configureIndex ($ instance );
106101 $ result [] = $ configResult ->asBool ();
107102 } catch (Exception $ error ) {
@@ -123,26 +118,26 @@ public function run($request)
123118 }
124119
125120 /**
126- * Update/create a store
127- * @param ElasticIndex $instance
121+ * Update/create a single index.
122+ * @param ElasticIndex $index
128123 * @return Elasticsearch
129124 * @throws ClientResponseException
130125 * @throws MissingParameterException
131- * @throws ServerResponseException
132126 * @throws NotFoundExceptionInterface
127+ * @throws ServerResponseException
133128 */
134- protected function configureIndex ($ instance ): Elasticsearch
129+ public function configureIndex (CoreIndex $ index ): Elasticsearch
135130 {
136- $ indexName = $ instance ->getIndexName ();
131+ $ indexName = $ index ->getIndexName ();
137132
138- $ instanceConfig = $ this ->createConfigForIndex ($ instance );
133+ $ instanceConfig = $ this ->createConfigForIndex ($ index );
139134
140135 $ mappings = $ this ->convertForJSON ($ instanceConfig );
141136
142137 $ body = ['index ' => $ indexName ];
143138 $ client = $ this ->service ->getClient ();
144139
145- $ method = $ this ->getMethod ($ instance );
140+ $ method = $ this ->getMethod ($ index );
146141 $ msg = "%s index %s " ;
147142 $ msgType = 'Updating ' ;
148143 if ($ method === 'create ' ) {
0 commit comments