@@ -104,49 +104,58 @@ public function process()
104
104
return ;
105
105
}
106
106
107
+ $ algoliaService = Injector::inst ()->create (AlgoliaService::class);
107
108
$ task = new AlgoliaReindex ();
108
109
109
110
$ batchSize = $ task ->config ()->get ('batch_size ' );
110
111
$ batching = $ this ->config ()->get ('use_batching ' );
111
112
112
113
foreach ($ remainingChildren as $ class => $ ids ) {
113
- $ take = array_slice ( $ ids , 0 , $ batchSize );
114
- $ this -> indexData [ $ class ] = array_slice ( $ ids , $ batchSize ) ;
114
+ foreach ( $ algoliaService -> indexes as $ indexName => $ index ) {
115
+ $ classes = ( isset ( $ index [ ' includeClasses ' ])) ? $ index [ ' includeClasses ' ] : [] ;
115
116
116
- if (!empty ( $ take )) {
117
- $ this -> currentStep += count ( $ take ) ;
118
- $ errors = [];
117
+ if (!in_array ( $ class , $ classes )) {
118
+ continue ;
119
+ }
119
120
120
- try {
121
- if ($ batching ) {
122
- if ($ task ->indexItems ($ class , DataObject::get ($ class )->filter ('ID ' , $ take ), false )) {
123
- $ this ->addMessage ('Successfully indexing ' . $ class . ' [ ' . implode (', ' , $ take ) . '] ' );
124
- } else {
125
- $ this ->addMessage ('Error indexing ' . $ class . ' [ ' . implode (', ' , $ take ) . '] ' );
126
- }
127
- } else {
128
- $ items = DataObject::get ($ class )->filter ('ID ' , $ take );
121
+ $ take = array_slice ($ ids , 0 , $ batchSize );
122
+ $ this ->indexData [$ class ] = array_slice ($ ids , $ batchSize );
123
+
124
+ if (!empty ($ take )) {
125
+ $ this ->currentStep += count ($ take );
126
+ $ errors = [];
129
127
130
- foreach ($ items as $ item ) {
131
- if ($ task ->indexItem ($ item )) {
132
- $ this ->addMessage ('Successfully indexed ' . $ class . ' [ ' . $ item ->ID . '] ' );
128
+ try {
129
+ if ($ batching ) {
130
+ if ($ task ->indexItems ($ indexName , DataObject::get ($ class )->filter ('ID ' , $ take ), false )) {
131
+ $ this ->addMessage ('Successfully indexing ' . $ class . ' [ ' . implode (', ' , $ take ) . '] ' );
133
132
} else {
134
- $ this ->addMessage ('Error indexing ' . $ class . ' [ ' . $ item ->ID . '] ' );
133
+ $ this ->addMessage ('Error indexing ' . $ class . ' [ ' . implode (', ' , $ take ) . '] ' );
134
+ }
135
+ } else {
136
+ $ items = DataObject::get ($ class )->filter ('ID ' , $ take );
137
+
138
+ foreach ($ items as $ item ) {
139
+ if ($ task ->indexItem ($ item )) {
140
+ $ this ->addMessage ('Successfully indexed ' . $ class . ' [ ' . $ item ->ID . '] ' );
141
+ } else {
142
+ $ this ->addMessage ('Error indexing ' . $ class . ' [ ' . $ item ->ID . '] ' );
143
+ }
135
144
}
136
145
}
137
- }
138
146
139
- $ errors = $ task ->getErrors ();
140
- } catch (Throwable $ e ) {
141
- $ errors [] = $ e ->getMessage ();
142
- }
147
+ $ errors = $ task ->getErrors ();
148
+ } catch (Throwable $ e ) {
149
+ $ errors [] = $ e ->getMessage ();
150
+ }
143
151
144
- if (!empty ($ errors )) {
145
- $ this ->addMessage (implode (', ' , $ errors ));
146
- $ task ->clearErrors ();
152
+ if (!empty ($ errors )) {
153
+ $ this ->addMessage (implode (', ' , $ errors ));
154
+ $ task ->clearErrors ();
155
+ }
156
+ } else {
157
+ unset($ this ->indexData [$ class ]);
147
158
}
148
- } else {
149
- unset($ this ->indexData [$ class ]);
150
159
}
151
160
}
152
161
}
0 commit comments