PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.4
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 / 20200617122511_CreateSEOLinksTable.php

20200617122511_CreateSEOLinksTable.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.4, at src/config/migrations/20200617122511_CreateSEOLinksTable.php

97 lines 2.5 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 * CreateSEOLinksTable class.
10 */
11 class CreateSEOLinksTable 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 // The table may already have been created by legacy code.
30 // If not, create it exactly as it was.
31 if ( ! $adapter->table_exists( $table_name ) ) {
32 $table = $this->create_table( $table_name, [ 'id' => false ] );
33 $table->column(
34 'id',
35 'biginteger',
36 [
37 'primary_key' => true,
38 'limit' => 20,
39 'unsigned' => true,
40 'auto_increment' => true,
41 ],
42 );
43 $table->column( 'url', 'string', [ 'limit' => 255 ] );
44 $table->column(
45 'post_id',
46 'biginteger',
47 [
48 'limit' => 20,
49 'unsigned' => true,
50 ],
51 );
52 $table->column(
53 'target_post_id',
54 'biginteger',
55 [
56 'limit' => 20,
57 'unsigned' => true,
58 ],
59 );
60 $table->column( 'type', 'string', [ 'limit' => 8 ] );
61 $table->finish();
62 }
63 if ( ! $adapter->has_index( $table_name, [ 'post_id', 'type' ], [ 'name' => 'link_direction' ] ) ) {
64 $this->add_index( $table_name, [ 'post_id', 'type' ], [ 'name' => 'link_direction' ] );
65 }
66
67 // Add these columns outside of the initial table creation as these did not exist on the legacy table.
68 $this->add_column( $table_name, 'indexable_id', 'integer', [ 'unsigned' => true ] );
69 $this->add_column( $table_name, 'target_indexable_id', 'integer', [ 'unsigned' => true ] );
70 $this->add_column( $table_name, 'height', 'integer', [ 'unsigned' => true ] );
71 $this->add_column( $table_name, 'width', 'integer', [ 'unsigned' => true ] );
72 $this->add_column( $table_name, 'size', 'integer', [ 'unsigned' => true ] );
73 $this->add_column( $table_name, 'language', 'string', [ 'limit' => 32 ] );
74 $this->add_column( $table_name, 'region', 'string', [ 'limit' => 32 ] );
75
76 $this->add_index( $table_name, [ 'indexable_id', 'type' ], [ 'name' => 'indexable_link_direction' ] );
77 }
78
79 /**
80 * Migration down.
81 *
82 * @return void
83 */
84 public function down() {
85 $this->drop_table( $this->get_table_name() );
86 }
87
88 /**
89 * Returns the SEO Links table name.
90 *
91 * @return string
92 */
93 private function get_table_name() {
94 return Model::get_table_name( 'SEO_Links' );
95 }
96 }
97