| 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 |
* Indexable migration. |
| 10 |
*/ |
| 11 |
class WpYoastIndexable 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 |
$this->add_table(); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Migration down. |
| 31 |
* |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public function down() { |
| 35 |
$this->drop_table( $this->get_table_name() ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Creates the indexable table. |
| 40 |
* |
| 41 |
* @return void |
| 42 |
*/ |
| 43 |
private function add_table() { |
| 44 |
$table_name = $this->get_table_name(); |
| 45 |
|
| 46 |
$indexable_table = $this->create_table( $table_name ); |
| 47 |
|
| 48 |
// Permalink. |
| 49 |
$indexable_table->column( 'permalink', 'mediumtext', [ 'null' => true ] ); |
| 50 |
$indexable_table->column( |
| 51 |
'permalink_hash', |
| 52 |
'string', |
| 53 |
[ |
| 54 |
'null' => true, |
| 55 |
'limit' => 191, |
| 56 |
], |
| 57 |
); |
| 58 |
|
| 59 |
// Object information. |
| 60 |
$indexable_table->column( |
| 61 |
'object_id', |
| 62 |
'integer', |
| 63 |
[ |
| 64 |
'unsigned' => true, |
| 65 |
'null' => true, |
| 66 |
'limit' => 11, |
| 67 |
], |
| 68 |
); |
| 69 |
$indexable_table->column( |
| 70 |
'object_type', |
| 71 |
'string', |
| 72 |
[ |
| 73 |
'null' => false, |
| 74 |
'limit' => 32, |
| 75 |
], |
| 76 |
); |
| 77 |
$indexable_table->column( |
| 78 |
'object_sub_type', |
| 79 |
'string', |
| 80 |
[ |
| 81 |
'null' => true, |
| 82 |
'limit' => 32, |
| 83 |
], |
| 84 |
); |
| 85 |
|
| 86 |
// Ownership. |
| 87 |
$indexable_table->column( |
| 88 |
'author_id', |
| 89 |
'integer', |
| 90 |
[ |
| 91 |
'unsigned' => true, |
| 92 |
'null' => true, |
| 93 |
'limit' => 11, |
| 94 |
], |
| 95 |
); |
| 96 |
$indexable_table->column( |
| 97 |
'post_parent', |
| 98 |
'integer', |
| 99 |
[ |
| 100 |
'unsigned' => true, |
| 101 |
'null' => true, |
| 102 |
'limit' => 11, |
| 103 |
], |
| 104 |
); |
| 105 |
|
| 106 |
// Title and description. |
| 107 |
$indexable_table->column( |
| 108 |
'title', |
| 109 |
'string', |
| 110 |
[ |
| 111 |
'null' => true, |
| 112 |
'limit' => 191, |
| 113 |
], |
| 114 |
); |
| 115 |
$indexable_table->column( 'description', 'text', [ 'null' => true ] ); |
| 116 |
$indexable_table->column( |
| 117 |
'breadcrumb_title', |
| 118 |
'string', |
| 119 |
[ |
| 120 |
'null' => true, |
| 121 |
'limit' => 191, |
| 122 |
], |
| 123 |
); |
| 124 |
|
| 125 |
// Post metadata: status, public, protected. |
| 126 |
$indexable_table->column( |
| 127 |
'post_status', |
| 128 |
'string', |
| 129 |
[ |
| 130 |
'null' => true, |
| 131 |
'limit' => 191, |
| 132 |
], |
| 133 |
); |
| 134 |
$indexable_table->column( |
| 135 |
'is_public', |
| 136 |
'boolean', |
| 137 |
[ |
| 138 |
'null' => true, |
| 139 |
'default' => null, |
| 140 |
], |
| 141 |
); |
| 142 |
$indexable_table->column( 'is_protected', 'boolean', [ 'default' => false ] ); |
| 143 |
$indexable_table->column( |
| 144 |
'has_public_posts', |
| 145 |
'boolean', |
| 146 |
[ |
| 147 |
'null' => true, |
| 148 |
'default' => null, |
| 149 |
], |
| 150 |
); |
| 151 |
|
| 152 |
$indexable_table->column( |
| 153 |
'number_of_pages', |
| 154 |
'integer', |
| 155 |
[ |
| 156 |
'unsigned' => true, |
| 157 |
'null' => true, |
| 158 |
'default' => null, |
| 159 |
'limit' => 11, |
| 160 |
], |
| 161 |
); |
| 162 |
|
| 163 |
$indexable_table->column( 'canonical', 'mediumtext', [ 'null' => true ] ); |
| 164 |
|
| 165 |
// SEO and readability analysis. |
| 166 |
$indexable_table->column( |
| 167 |
'primary_focus_keyword', |
| 168 |
'string', |
| 169 |
[ |
| 170 |
'null' => true, |
| 171 |
'limit' => 191, |
| 172 |
], |
| 173 |
); |
| 174 |
$indexable_table->column( |
| 175 |
'primary_focus_keyword_score', |
| 176 |
'integer', |
| 177 |
[ |
| 178 |
'null' => true, |
| 179 |
'limit' => 3, |
| 180 |
], |
| 181 |
); |
| 182 |
$indexable_table->column( |
| 183 |
'readability_score', |
| 184 |
'integer', |
| 185 |
[ |
| 186 |
'null' => true, |
| 187 |
'limit' => 3, |
| 188 |
], |
| 189 |
); |
| 190 |
$indexable_table->column( 'is_cornerstone', 'boolean', [ 'default' => false ] ); |
| 191 |
|
| 192 |
// Robots. |
| 193 |
$indexable_table->column( |
| 194 |
'is_robots_noindex', |
| 195 |
'boolean', |
| 196 |
[ |
| 197 |
'null' => true, |
| 198 |
'default' => false, |
| 199 |
], |
| 200 |
); |
| 201 |
$indexable_table->column( |
| 202 |
'is_robots_nofollow', |
| 203 |
'boolean', |
| 204 |
[ |
| 205 |
'null' => true, |
| 206 |
'default' => false, |
| 207 |
], |
| 208 |
); |
| 209 |
$indexable_table->column( |
| 210 |
'is_robots_noarchive', |
| 211 |
'boolean', |
| 212 |
[ |
| 213 |
'null' => true, |
| 214 |
'default' => false, |
| 215 |
], |
| 216 |
); |
| 217 |
$indexable_table->column( |
| 218 |
'is_robots_noimageindex', |
| 219 |
'boolean', |
| 220 |
[ |
| 221 |
'null' => true, |
| 222 |
'default' => false, |
| 223 |
], |
| 224 |
); |
| 225 |
$indexable_table->column( |
| 226 |
'is_robots_nosnippet', |
| 227 |
'boolean', |
| 228 |
[ |
| 229 |
'null' => true, |
| 230 |
'default' => false, |
| 231 |
], |
| 232 |
); |
| 233 |
|
| 234 |
// Twitter. |
| 235 |
$indexable_table->column( |
| 236 |
'twitter_title', |
| 237 |
'string', |
| 238 |
[ |
| 239 |
'null' => true, |
| 240 |
'limit' => 191, |
| 241 |
], |
| 242 |
); |
| 243 |
$indexable_table->column( 'twitter_image', 'mediumtext', [ 'null' => true ] ); |
| 244 |
$indexable_table->column( 'twitter_description', 'mediumtext', [ 'null' => true ] ); |
| 245 |
$indexable_table->column( |
| 246 |
'twitter_image_id', |
| 247 |
'string', |
| 248 |
[ |
| 249 |
'null' => true, |
| 250 |
'limit' => 191, |
| 251 |
], |
| 252 |
); |
| 253 |
$indexable_table->column( |
| 254 |
'twitter_image_source', |
| 255 |
'string', |
| 256 |
[ |
| 257 |
'null' => true, |
| 258 |
'limit' => 191, |
| 259 |
], |
| 260 |
); |
| 261 |
|
| 262 |
// Open-Graph. |
| 263 |
$indexable_table->column( |
| 264 |
'open_graph_title', |
| 265 |
'string', |
| 266 |
[ |
| 267 |
'null' => true, |
| 268 |
'limit' => 191, |
| 269 |
], |
| 270 |
); |
| 271 |
$indexable_table->column( 'open_graph_description', 'mediumtext', [ 'null' => true ] ); |
| 272 |
$indexable_table->column( 'open_graph_image', 'mediumtext', [ 'null' => true ] ); |
| 273 |
$indexable_table->column( |
| 274 |
'open_graph_image_id', |
| 275 |
'string', |
| 276 |
[ |
| 277 |
'null' => true, |
| 278 |
'limit' => 191, |
| 279 |
], |
| 280 |
); |
| 281 |
$indexable_table->column( |
| 282 |
'open_graph_image_source', |
| 283 |
'string', |
| 284 |
[ |
| 285 |
'null' => true, |
| 286 |
'limit' => 191, |
| 287 |
], |
| 288 |
); |
| 289 |
$indexable_table->column( 'open_graph_image_meta', 'text', [ 'null' => true ] ); |
| 290 |
|
| 291 |
// Link count. |
| 292 |
$indexable_table->column( |
| 293 |
'link_count', |
| 294 |
'integer', |
| 295 |
[ |
| 296 |
'null' => true, |
| 297 |
'limit' => 11, |
| 298 |
], |
| 299 |
); |
| 300 |
$indexable_table->column( |
| 301 |
'incoming_link_count', |
| 302 |
'integer', |
| 303 |
[ |
| 304 |
'null' => true, |
| 305 |
'limit' => 11, |
| 306 |
], |
| 307 |
); |
| 308 |
|
| 309 |
// Prominent words. |
| 310 |
$indexable_table->column( |
| 311 |
'prominent_words_version', |
| 312 |
'integer', |
| 313 |
[ |
| 314 |
'null' => true, |
| 315 |
'limit' => 11, |
| 316 |
'unsigned' => true, |
| 317 |
'default' => null, |
| 318 |
], |
| 319 |
); |
| 320 |
|
| 321 |
$indexable_table->finish(); |
| 322 |
|
| 323 |
$this->add_indexes( $table_name ); |
| 324 |
|
| 325 |
$this->add_timestamps( $table_name ); |
| 326 |
} |
| 327 |
|
| 328 |
/** |
| 329 |
* Adds indexes to the indexable table. |
| 330 |
* |
| 331 |
* @param string $indexable_table_name The name of the indexable table. |
| 332 |
* |
| 333 |
* @return void |
| 334 |
*/ |
| 335 |
private function add_indexes( $indexable_table_name ) { |
| 336 |
$this->add_index( |
| 337 |
$indexable_table_name, |
| 338 |
[ |
| 339 |
'object_type', |
| 340 |
'object_sub_type', |
| 341 |
], |
| 342 |
[ |
| 343 |
'name' => 'object_type_and_sub_type', |
| 344 |
], |
| 345 |
); |
| 346 |
|
| 347 |
$this->add_index( |
| 348 |
$indexable_table_name, |
| 349 |
'permalink_hash', |
| 350 |
[ |
| 351 |
'name' => 'permalink_hash', |
| 352 |
], |
| 353 |
); |
| 354 |
} |
| 355 |
|
| 356 |
/** |
| 357 |
* Retrieves the table name to use for storing indexables. |
| 358 |
* |
| 359 |
* @return string The table name to use. |
| 360 |
*/ |
| 361 |
protected function get_table_name() { |
| 362 |
return Model::get_table_name( 'Indexable' ); |
| 363 |
} |
| 364 |
} |
| 365 |
|