duplicate brands. * * This migration: * 1. Widens id_actionwear (brands) and recharge_entity_id (recharges) to VARCHAR. * 2. Rebuilds the brands table from the feed (now idempotent) to remove the * duplicate/stale rows already present on updated installations. */ class Action_Wear_Sql_Version_1_2_3 extends Action_Wear_Sql_Version_Abstract implements Action_Wear_Sql_Version_Interface { public static function versioningScript() { global $wpdb; $brands = $wpdb->prefix . 'actionwear_brands'; $recharges = $wpdb->prefix . 'actionwear_recharges'; // 1. Widen columns so alphanumeric string ids fit without truncation. $wpdb->query("ALTER TABLE {$brands} MODIFY `id_actionwear` VARCHAR(255) NOT NULL"); $wpdb->query("ALTER TABLE {$recharges} MODIFY `recharge_entity_id` VARCHAR(255) NOT NULL"); Log::write("Migration 1.2.3: id_actionwear (brands) and recharge_entity_id (recharges) -> VARCHAR(255)", Log::INFO, Log::CONTEXT_GENERAL); // 2. Rebuild brands from the feed to drop stale/duplicate rows left by // the previous INSERT IGNORE behaviour. generateBrands is now idempotent // (transactional replace), so this cleans the table safely. $apikey = get_option('_ACTIONWEAR_APIKEY'); if (!empty($apikey)) { try { @set_time_limit(300); @ini_set('memory_limit', '512M'); Product::regenerateBrands(); Log::write("Migration 1.2.3: brands table sanitized and repopulated", Log::INFO, Log::CONTEXT_GENERAL); } catch (\Throwable $th) { Log::write("Migration 1.2.3: Failed to repopulate brands - " . $th->getMessage(), Log::ERROR, Log::CONTEXT_GENERAL); } } } } }