<?php
/**
 * File Path: includes/migrations/class-mbs-migration-1-3.php
 *
 * MBS_Migration_1_3 — Normalise section keys
 *
 * Rename short/underscore section keys to canonical long hyphenated form.
 *
 * @package MyBookShowroom
 * @since   3.2.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class MBS_Migration_1_3
 *
 * Rename short/underscore section keys to canonical long hyphenated form.
 *
 * @implements MBS_Migration
 */
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- DAO/migration: table names via $wpdb->prefix are trusted server-controlled values, not user input
// phpcs:disable PluginCheck.Security.DirectDB.UnescapedDBParameter -- same reason: $wpdb->prefix table names are safe; $where_sql is built from sanitized server-controlled inputs
class MBS_Migration_1_3 implements MBS_Migration { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	/**
	 * {@inheritdoc}
	 *
	 * @return string
	 */
	public function version(): string {
		return '1.3';
	}

	/**
	 * {@inheritdoc}
	 *
	 * Rename short/underscore section keys to canonical long hyphenated form.
	 *
	 * @return void
	 */
	public function up(): void {
		global $wpdb;
		$table = $wpdb->prefix . 'mbs_section_order';
		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- no user input
		$wpdb->query( "UPDATE {$table} SET section_key = 'about-the-book' WHERE section_key IN ('about', 'about_the_book')" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- DAO layer -- direct DB access is intentional per MBS architecture
		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
		$wpdb->query( "UPDATE {$table} SET section_key = 'audio-sample' WHERE section_key IN ('audio', 'audio_sample')" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- DAO layer -- direct DB access is intentional per MBS architecture
		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
		$wpdb->query( "UPDATE {$table} SET section_key = 'look-inside' WHERE section_key = 'look_inside'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- DAO layer -- direct DB access is intentional per MBS architecture
		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
		$wpdb->query( "UPDATE {$table} SET section_key = 'amazon-reviews' WHERE section_key = 'amazon_reviews'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- DAO layer -- direct DB access is intentional per MBS architecture
		// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
		$wpdb->query( "UPDATE {$table} SET section_key = 'social-share' WHERE section_key = 'social_share'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- DAO layer -- direct DB access is intentional per MBS architecture
	}
}
