| 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 AddColumnsToIndexables. |
| 10 |
*/ |
| 11 |
class AddColumnsToIndexables 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 |
public function up() { |
| 24 |
$tables = $this->get_tables(); |
| 25 |
$blog_id = \get_current_blog_id(); |
| 26 |
foreach ( $tables as $table ) { |
| 27 |
$this->add_column( |
| 28 |
$table, |
| 29 |
'blog_id', |
| 30 |
'biginteger', |
| 31 |
[ |
| 32 |
'null' => false, |
| 33 |
'limit' => 20, |
| 34 |
'default' => $blog_id, |
| 35 |
] |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
$attr_limit_32 = [ |
| 40 |
'null' => true, |
| 41 |
'limit' => 32, |
| 42 |
]; |
| 43 |
$attr_limit_64 = [ |
| 44 |
'null' => true, |
| 45 |
'limit' => 64, |
| 46 |
]; |
| 47 |
|
| 48 |
$indexable_table = $this->get_indexable_table(); |
| 49 |
$this->add_column( $indexable_table, 'language', 'string', $attr_limit_32 ); |
| 50 |
$this->add_column( $indexable_table, 'region', 'string', $attr_limit_32 ); |
| 51 |
$this->add_column( $indexable_table, 'schema_page_type', 'string', $attr_limit_64 ); |
| 52 |
$this->add_column( $indexable_table, 'schema_article_type', 'string', $attr_limit_64 ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Migration down. |
| 57 |
*/ |
| 58 |
public function down() { |
| 59 |
$tables = $this->get_tables(); |
| 60 |
foreach ( $tables as $table ) { |
| 61 |
$this->remove_column( $table, 'blog_id' ); |
| 62 |
} |
| 63 |
|
| 64 |
$indexable_table = $this->get_indexable_table(); |
| 65 |
$this->remove_column( $indexable_table, 'language' ); |
| 66 |
$this->remove_column( $indexable_table, 'region' ); |
| 67 |
$this->remove_column( $indexable_table, 'schema_page_type' ); |
| 68 |
$this->remove_column( $indexable_table, 'schema_article_type' ); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Retrieves the Indexable table. |
| 73 |
* |
| 74 |
* @return string The Indexable table name. |
| 75 |
*/ |
| 76 |
protected function get_indexable_table() { |
| 77 |
return Model::get_table_name( 'Indexable' ); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Retrieves the table names to use. |
| 82 |
* |
| 83 |
* @return string[] The table names to use. |
| 84 |
*/ |
| 85 |
protected function get_tables() { |
| 86 |
return [ |
| 87 |
$this->get_indexable_table(), |
| 88 |
Model::get_table_name( 'Indexable_Hierarchy' ), |
| 89 |
Model::get_table_name( 'Primary_Term' ), |
| 90 |
]; |
| 91 |
} |
| 92 |
} |
| 93 |
|