@@ -33,6 +33,24 @@ public function hook_init() {
3333 $ this ->getExternalTables = false ;
3434 }
3535
36+ /**
37+ * Helper method to return success response
38+ */
39+ private function success ($ data ) {
40+ $ this ->response ['success ' ] = true ;
41+ $ this ->response ['data ' ] = $ data ;
42+ return ;
43+ }
44+
45+ /**
46+ * Helper method to return error response
47+ */
48+ private function error ($ message ) {
49+ $ this ->response ['success ' ] = false ;
50+ $ this ->response ['error ' ] = $ message ;
51+ return ;
52+ }
53+
3654 /**
3755 * Override getObject to preserve raw Unix timestamps before date conversion
3856 * This ensures timezone-independent date handling in JavaScript
@@ -159,44 +177,59 @@ private function getStatusBadge($analysis) {
159177 * URL: /AIErrorAnalysis/applyFix/id/{analysis_id}
160178 */
161179 public function applyFix () {
180+ error_log ("AIErrorAnalysisController::applyFix() called " );
181+
162182 if (!isset ($ this ->api ->value )) {
183+ error_log ("AIErrorAnalysisController::applyFix() - No analysis ID provided " );
163184 return $ this ->error ("Analysis ID required " );
164185 }
165186
187+ error_log ("AIErrorAnalysisController::applyFix() - Analysis ID: " . $ this ->api ->value );
188+
166189 $ analysis = new ModelObject ($ this ->model );
167190 if (!$ analysis ->retrieve ('id ' , $ this ->api ->value , [
168191 ['field ' => 'kyte_account ' , 'value ' => $ this ->api ->account ->id ]
169192 ])) {
193+ error_log ("AIErrorAnalysisController::applyFix() - Analysis not found " );
170194 return $ this ->error ("Analysis not found " );
171195 }
172196
197+ error_log ("AIErrorAnalysisController::applyFix() - Analysis retrieved: ID= {$ analysis ->id }, status= {$ analysis ->analysis_status }, fix_status= {$ analysis ->fix_status }" );
198+
173199 // Validate state
174200 if ($ analysis ->analysis_status !== 'completed ' ) {
201+ error_log ("AIErrorAnalysisController::applyFix() - Analysis not completed " );
175202 return $ this ->error ("Analysis must be completed before applying fix " );
176203 }
177204
178205 if ($ analysis ->is_fixable != 1 ) {
206+ error_log ("AIErrorAnalysisController::applyFix() - Error not fixable " );
179207 return $ this ->error ("This error is not fixable " );
180208 }
181209
182210 if ($ analysis ->fix_status === 'applied_manual ' || $ analysis ->fix_status === 'applied_auto ' ) {
211+ error_log ("AIErrorAnalysisController::applyFix() - Fix already applied " );
183212 return $ this ->error ("Fix has already been applied " );
184213 }
185214
186215 // Apply the fix
187216 try {
217+ error_log ("AIErrorAnalysisController::applyFix() - Calling AIErrorFixApplier " );
188218 $ applier = new AIErrorFixApplier ($ this ->api );
189219 $ success = $ applier ->apply ($ analysis , $ this ->user ->id );
190220
191221 if ($ success ) {
222+ error_log ("AIErrorAnalysisController::applyFix() - Fix applied successfully " );
192223 return $ this ->success ([
193224 'message ' => 'Fix applied successfully ' ,
194225 'analysis ' => $ analysis ->getAllParams ()
195226 ]);
196227 } else {
228+ error_log ("AIErrorAnalysisController::applyFix() - Apply failed (returned false) " );
197229 return $ this ->error ("Failed to apply fix. Check logs for details. " );
198230 }
199231 } catch (\Exception $ e ) {
232+ error_log ("AIErrorAnalysisController::applyFix() - Exception: " . $ e ->getMessage ());
200233 return $ this ->error ("Error applying fix: " . $ e ->getMessage ());
201234 }
202235 }
0 commit comments