ABIENTOT_PLUGIN_URL . 'assets/admin/import-profiler-worker.js', 'ajax' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'abientot_compatibility_report' ), 'busy' => __( 'Analyzing locally…', 'abientot' ), 'ready' => __( 'Review the complete report before sending. Analysis is bounded and may be incomplete.', 'abientot' ), 'failed' => __( 'Analysis could not finish. Reset and select the file again.', 'abientot' ), 'uncertain' => __( 'The send result is uncertain. Do not retry automatically; check your mail transport.', 'abientot' ), 'title' => 'Abientot compatibility report' ) ); } public function panel(): void { if ( ! current_user_can( 'abientot_manage_settings' ) ) { return; } ?>

missing(); } if ( ( $input['consent'] ?? '' ) !== '1' ) { return $this->missing(); } if ( array_diff( array_keys( $input ), array( 'consent', 'report' ) ) || ! is_string( $input['report'] ?? null ) ) { return $this->invalid(); } try { $report = ReportSchema::decode( $input['report'] ); } catch ( \Throwable $error ) { return $this->invalid(); } // Never release an inherited lock, nor invoke external transport while owning one. if ( BookingLock::is_held() || ! BookingLock::acquire() ) { return $this->limited(); } $claimed = false; try { $now = time(); $site = 'abientot_compatibility_site_send'; $account = 'abientot_compatibility_user_' . get_current_user_id(); foreach ( array( $site, $account ) as $key ) { wp_cache_delete( $key, 'options' ); $last = get_option( $key, 0 ); if ( ( ! is_int( $last ) && ( ! is_string( $last ) || ! preg_match( '/^[0-9]{1,12}$/D', $last ) ) ) || ( (int) $last > 0 && $now - (int) $last < 300 ) ) { return $this->limited(); } } // Timestamp only, no report, source hash or account details. Failure consumes any // successful earlier claim rather than risking a repeated transport attempt. if ( ! update_option( $site, $now, false ) || ! update_option( $account, $now, false ) ) { return $this->limited(); } $claimed = true; } catch ( \Throwable $error ) { return $this->limited(); } finally { BookingLock::release(); } if ( ! $claimed || BookingLock::is_held() ) { return $this->limited(); } try { $accepted = wp_mail( 'contact@abientot.app', 'Migration report', ReportSchema::body( $report ), array( 'Content-Type: text/plain; charset=UTF-8' ), array() ); } catch ( \Throwable $error ) { return array( 'ok' => false, 'message' => __( 'The send result is uncertain. Do not retry automatically; check your mail transport.', 'abientot' ) ); } return array( 'ok' => (bool) $accepted, 'message' => $accepted ? __( 'Your mail transport accepted the report. Inbox delivery is not confirmed.', 'abientot' ) : __( 'Your mail transport did not accept the report. No automatic retry will occur.', 'abientot' ) ); } private function invalid(): array { return array( 'ok' => false, 'message' => __( 'The compatibility report is invalid. Analyze the file again.', 'abientot' ) ); } private function limited(): array { return array( 'ok' => false, 'message' => __( 'A report was recently attempted or sending is unavailable. Wait at least five minutes; do not retry an uncertain send.', 'abientot' ) ); } public function ajax(): void { if ( ! check_ajax_referer( 'abientot_compatibility_report', 'nonce', false ) ) { wp_send_json_error( $this->missing() ); } if ( ! current_user_can( 'abientot_manage_settings' ) ) { wp_send_json_error( $this->missing() ); } if ( ! \Abientot\Support\Request::is_post() ) { wp_send_json_error( $this->missing() ); } $input = \Abientot\Support\Request::post_fields( 'abientot_compatibility_report', array( 'consent', 'report' => 'textarea', ), 'nonce' ); $result = $this->send( $input ); if ( $result['ok'] ) { wp_send_json_success( $result ); } else { wp_send_json_error( $result ); } } private function missing(): array { return array( 'ok' => false, 'message' => __( 'Permission, session or explicit consent is missing.', 'abientot' ), ); } }