| 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 |
* ReplacePermalinkHashIndex class. |
| 10 |
*/ |
| 11 |
class ReplacePermalinkHashIndex 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 |
$table_name = $this->get_table_name(); |
| 27 |
$adapter = $this->get_adapter(); |
| 28 |
|
| 29 |
if ( ! $adapter->has_table( $table_name ) ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
$this->change_column( |
| 34 |
$table_name, |
| 35 |
'permalink_hash', |
| 36 |
'string', |
| 37 |
[ |
| 38 |
'null' => true, |
| 39 |
'limit' => 40, |
| 40 |
], |
| 41 |
); |
| 42 |
|
| 43 |
if ( $adapter->has_index( $table_name, [ 'permalink_hash' ], [ 'name' => 'permalink_hash' ] ) ) { |
| 44 |
$this->remove_index( |
| 45 |
$table_name, |
| 46 |
[ |
| 47 |
'permalink_hash', |
| 48 |
], |
| 49 |
[ |
| 50 |
'name' => 'permalink_hash', |
| 51 |
], |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
if ( ! $adapter->has_index( $table_name, [ 'permalink_hash', 'object_type' ], [ 'name' => 'permalink_hash_and_object_type' ] ) ) { |
| 56 |
$this->add_index( |
| 57 |
$table_name, |
| 58 |
[ |
| 59 |
'permalink_hash', |
| 60 |
'object_type', |
| 61 |
], |
| 62 |
[ |
| 63 |
'name' => 'permalink_hash_and_object_type', |
| 64 |
], |
| 65 |
); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Migration down. |
| 71 |
* |
| 72 |
* @return void |
| 73 |
*/ |
| 74 |
public function down() { |
| 75 |
$table_name = $this->get_table_name(); |
| 76 |
$adapter = $this->get_adapter(); |
| 77 |
|
| 78 |
if ( ! $adapter->has_table( $table_name ) ) { |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
if ( $adapter->has_index( $table_name, [ 'permalink_hash', 'object_type' ], [ 'name' => 'permalink_hash_and_object_type' ] ) ) { |
| 83 |
$this->remove_index( |
| 84 |
$table_name, |
| 85 |
[ |
| 86 |
'permalink_hash', |
| 87 |
'object_type', |
| 88 |
], |
| 89 |
[ |
| 90 |
'name' => 'permalink_hash_and_object_type', |
| 91 |
], |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
$this->change_column( |
| 96 |
$table_name, |
| 97 |
'permalink_hash', |
| 98 |
'string', |
| 99 |
[ |
| 100 |
'null' => true, |
| 101 |
'limit' => 191, |
| 102 |
], |
| 103 |
); |
| 104 |
|
| 105 |
if ( ! $adapter->has_index( $table_name, [ 'permalink_hash' ], [ 'name' => 'permalink_hash' ] ) ) { |
| 106 |
$this->add_index( |
| 107 |
$table_name, |
| 108 |
[ |
| 109 |
'permalink_hash', |
| 110 |
], |
| 111 |
[ |
| 112 |
'name' => 'permalink_hash', |
| 113 |
], |
| 114 |
); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Retrieves the table name to use for storing indexables. |
| 120 |
* |
| 121 |
* @return string The table name to use. |
| 122 |
*/ |
| 123 |
protected function get_table_name() { |
| 124 |
return Model::get_table_name( 'Indexable' ); |
| 125 |
} |
| 126 |
} |
| 127 |
|