| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\Database\Migrations; |
| 4 |
|
| 5 |
class AttributeGroupsMigrator extends Migrator |
| 6 |
{ |
| 7 |
public static string $tableName = 'fct_atts_groups'; |
| 8 |
|
| 9 |
public static function getSqlSchema(): string |
| 10 |
{ |
| 11 |
return "`id` BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, |
| 12 |
`title` VARCHAR(192) NOT NULL, |
| 13 |
`slug` VARCHAR(192) NOT NULL UNIQUE, |
| 14 |
`description` longtext NULL, |
| 15 |
`settings` longtext NULL, |
| 16 |
`created_at` DATETIME NULL, |
| 17 |
`updated_at` DATETIME NULL"; |
| 18 |
} |
| 19 |
|
| 20 |
public static function migrated() |
| 21 |
{ |
| 22 |
static::dropLegacyTitleUniqueIndexes(); |
| 23 |
} |
| 24 |
|
| 25 |
public static function dropLegacyTitleUniqueIndexes() |
| 26 |
{ |
| 27 |
global $wpdb; |
| 28 |
|
| 29 |
$tableName = static::getTableName(); |
| 30 |
|
| 31 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 32 |
$indexes = $wpdb->get_results($wpdb->prepare( |
| 33 |
"SHOW INDEX FROM %i WHERE Column_name = %s", |
| 34 |
$tableName, |
| 35 |
'title' |
| 36 |
), ARRAY_A); |
| 37 |
|
| 38 |
if (empty($indexes)) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
foreach ($indexes as $index) { |
| 43 |
if (($index['Non_unique'] ?? '1') !== '0') { |
| 44 |
continue; |
| 45 |
} |
| 46 |
|
| 47 |
static::dropIndexIfExists($index['Key_name']); |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|