wordpress-seo
/
src
/
config
/
migrations
/
20200728095334_AddIndexesForProminentWordsOnIndexables.php
20200728095334_AddIndexesForProminentWordsOnIndexables.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.6, at src/config/migrations/20200728095334_AddIndexesForProminentWordsOnIndexables.php
| 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 | * AddIndexesForProminentWordsOnIndexables class. |
| 10 | */ |
| 11 | class AddIndexesForProminentWordsOnIndexables extends Migration { |
| 12 | |
| 13 | /** |
| 14 | * The plugin this migration belongs to. |
| 15 | * |
| 16 | * @var string |
| 17 | */ |
| 18 | public static $plugin = 'free'; |
| 19 | |
| 20 | /** |
| 21 | * The columns on which an index should be added. |
| 22 | * |
| 23 | * @var string[] |
| 24 | */ |
| 25 | private $columns_with_index = [ |
| 26 | 'prominent_words_version', |
| 27 | 'object_type', |
| 28 | 'object_sub_type', |
| 29 | 'post_status', |
| 30 | ]; |
| 31 | |
| 32 | /** |
| 33 | * Migration up. |
| 34 | * |
| 35 | * @return void |
| 36 | */ |
| 37 | public function up() { |
| 38 | $table_name = $this->get_table_name(); |
| 39 | $adapter = $this->get_adapter(); |
| 40 | |
| 41 | if ( ! $adapter->has_index( $table_name, $this->columns_with_index, [ 'name' => 'prominent_words' ] ) ) { |
| 42 | $this->add_index( |
| 43 | $table_name, |
| 44 | $this->columns_with_index, |
| 45 | [ |
| 46 | 'name' => 'prominent_words', |
| 47 | ], |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Migration down. |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | public function down() { |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Retrieves the table name to use. |
| 62 | * |
| 63 | * @return string The table name to use. |
| 64 | */ |
| 65 | protected function get_table_name() { |
| 66 | return Model::get_table_name( 'Indexable' ); |
| 67 | } |
| 68 | } |
| 69 |