PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / config / migrations / 20200420073606_AddColumnsToIndexables.php

20200420073606_AddColumnsToIndexables.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at src/config/migrations/20200420073606_AddColumnsToIndexables.php

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