'running', 'started_at' => current_time( 'mysql', true ), ) ); $type = $step_def['type'] ?? 'manual'; if ( 'api' === $type ) { $result = CHECKLISTDEK_Payload_Mapper::execute( $site_id, $step_def, array( 'run_id' => $run_id, 'step_index' => $step_index, 'step_title' => $step_def['title'] ?? '', ) ); if ( is_wp_error( $result ) ) { CHECKLISTDEK_Run_Repository::update_step( $run_id, $step_index, array( 'status' => 'failed', 'error_message' => $result->get_error_message(), 'completed_at' => current_time( 'mysql', true ), ) ); CHECKLISTDEK_Webhook_Dispatcher::dispatch( 'step_failed', array( 'run_id' => $run_id, 'step_index' => $step_index, 'step_title' => $step_def['title'] ?? '', 'error' => $result->get_error_message(), ) ); return array( 'success' => false, 'message' => $result->get_error_message(), ); } CHECKLISTDEK_Run_Repository::update_step( $run_id, $step_index, array( 'status' => 'completed', 'response' => $result, 'completed_at' => current_time( 'mysql', true ), ) ); return array( 'success' => true, 'response' => $result, ); } // Manual steps require explicit checkmark. $client = CHECKLISTDEK_Remote_Client::from_site( $site_id ); $link = ''; $admin_path = CHECKLISTDEK_Admin_Deep_Links::resolve_path( $step_def ); if ( $client && $admin_path ) { $link = $client->admin_link( $admin_path ); } CHECKLISTDEK_Run_Repository::update_step( $run_id, $step_index, array( 'status' => 'awaiting_manual', 'response' => array( 'deep_link' => $link ), ) ); return array( 'success' => true, 'manual' => true, 'deep_link' => $link, ); } /** * Mark a manual step complete. * * @param int $run_id Run ID. * @param int $step_index Step index. * @return bool */ public static function mark_manual_complete( $run_id, $step_index ) { $result = CHECKLISTDEK_Run_Repository::update_step( $run_id, $step_index, array( 'status' => 'completed', 'manual_checked' => true, 'completed_at' => current_time( 'mysql', true ), ) ); if ( $result ) { CHECKLISTDEK_Audit_Log::log( 'manual_step_completed', array( 'step_index' => $step_index ), 0, $run_id ); } return $result; } /** * Revert a manually completed step back to awaiting action. * * @param int $run_id Run ID. * @param int $step_index Step index. * @return bool */ public static function mark_manual_incomplete( $run_id, $step_index ) { $run = CHECKLISTDEK_Run_Repository::find( $run_id ); if ( ! $run ) { return false; } $step = null; foreach ( $run['steps'] as $row ) { if ( (int) $row['step_index'] === (int) $step_index ) { $step = $row; break; } } if ( ! $step || 'manual' !== ( $step['step_type'] ?? '' ) || 'completed' !== ( $step['status'] ?? '' ) ) { return false; } if ( empty( $step['manual_checked'] ) ) { return false; } $response = is_array( $step['response'] ) ? $step['response'] : array(); unset( $response['completed_by'] ); $result = CHECKLISTDEK_Run_Repository::update_step( $run_id, $step_index, array( 'status' => 'awaiting_manual', 'manual_checked' => false, 'completed_at' => '', 'response' => $response, ) ); if ( $result ) { CHECKLISTDEK_Audit_Log::log( 'manual_step_uncompleted', array( 'step_index' => $step_index ), 0, $run_id ); } return $result; } }