@@ -95,6 +95,26 @@ protected function configureBatchJob(\Lomkit\Rest\Actions\Action $action, array
9595 */
9696 public function dispatch ($ chunkCount )
9797 {
98+ if ($ this ->action ->isStandalone ()) {
99+ $ modelsImpacted = $ this ->handleStandalone ();
100+ } else {
101+ $ modelsImpacted = $ this ->handleClassic ($ chunkCount );
102+ }
103+
104+ if (!is_null ($ this ->batchJob )) {
105+ $ this ->batchJob ->dispatch ();
106+ }
107+
108+ return $ modelsImpacted ;
109+ }
110+
111+ /**
112+ * Dispatch the given action.
113+ *
114+ * @param int $chunkCount
115+ * @return int
116+ */
117+ public function handleClassic (int $ chunkCount ) {
98118 $ searchQuery =
99119 app ()->make (QueryBuilder::class, ['resource ' => $ this ->request ->resource , 'query ' => null ])
100120 ->search ($ this ->request ->input ('search ' , []));
@@ -112,25 +132,34 @@ function ($chunk) {
112132 }
113133 );
114134
115- if (!is_null ($ this ->batchJob )) {
116- $ this ->batchJob ->dispatch ();
117- }
118-
119135 return $ searchQuery ->count ();
120136 }
121137
138+ /**
139+ * Dispatch the given standalone action.
140+ *
141+ * @return int
142+ *
143+ */
144+ public function handleStandalone () {
145+
146+ $ this ->forModels (
147+ \Illuminate \Database \Eloquent \Collection::make ()
148+ );
149+
150+ return 0 ;
151+ }
152+
122153 /**
123154 * Dispatch the given action.
124155 *
125156 * @param Collection $models
126157 *
127- * @throws \Throwable
128- *
129158 * @return mixed|void
130159 */
131160 public function forModels (Collection $ models )
132161 {
133- if ($ models ->isEmpty ()) {
162+ if ($ models ->isEmpty () && ! $ this -> action -> isStandalone () ) {
134163 return ;
135164 }
136165
0 commit comments