| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Config\Migrations; |
| 4 |
|
| 5 |
use Yoast\WP\Lib\Migrations\Migration; |
| 6 |
use Yoast\WP\Lib\Model; |
| 7 |
|
| 8 |
/** |
| 9 |
* Class AddCollationToTables. |
| 10 |
*/ |
| 11 |
class AddCollationToTables extends Migration { |
| 12 |
|
| 13 |
/** |
| 14 |
* The plugin this migration belongs to. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
public static $plugin = 'free'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Migration up. |
| 22 |
* |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
public function up() { |
| 26 |
global $wpdb; |
| 27 |
|
| 28 |
$charset_collate = $wpdb->get_charset_collate(); |
| 29 |
if ( empty( $charset_collate ) ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
$tables = [ |
| 34 |
Model::get_table_name( 'migrations' ), |
| 35 |
Model::get_table_name( 'Indexable' ), |
| 36 |
Model::get_table_name( 'Indexable_Hierarchy' ), |
| 37 |
Model::get_table_name( 'Primary_Term' ), |
| 38 |
]; |
| 39 |
|
| 40 |
foreach ( $tables as $table ) { |
| 41 |
$this->query( 'ALTER TABLE ' . $table . ' CONVERT TO ' . \str_replace( 'DEFAULT ', '', $charset_collate ) ); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Migration down. |
| 47 |
* |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
public function down() { |
| 51 |
// No down required. |
| 52 |
} |
| 53 |
} |
| 54 |
|