PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.5
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 / 20200616130143_ReplacePermalinkHashIndex.php

20200616130143_ReplacePermalinkHashIndex.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.5, at src/config/migrations/20200616130143_ReplacePermalinkHashIndex.php

127 lines 2.2 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 * 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