20171228151840_WpYoastIndexable.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * Yoast SEO Plugin File.
  4. *
  5. * @package WPSEO\Migrations
  6. */
  7. use Yoast\WP\Free\ORM\Yoast_Model;
  8. use YoastSEO_Vendor\Ruckusing_Migration_Base;
  9. /**
  10. * Indexable migration.
  11. */
  12. class WpYoastIndexable extends Ruckusing_Migration_Base {
  13. /**
  14. * Migration up.
  15. */
  16. public function up() {
  17. $table_name = $this->get_table_name();
  18. $indexable_table = $this->create_table( $table_name );
  19. $indexable_table->column( 'permalink', 'string', [ 'null' => true, 'limit' => 191 ] );
  20. $indexable_table->column( 'object_id', 'integer', [ 'unsigned' => true, 'null' => true, 'limit' => 11 ] );
  21. $indexable_table->column( 'object_type', 'string', [ 'limit' => 16 ] );
  22. $indexable_table->column( 'object_sub_type', 'string', [ 'null' => true, 'limit' => 100 ] );
  23. $indexable_table->column(
  24. 'number_of_pages',
  25. 'integer',
  26. [
  27. 'unsigned' => true,
  28. 'null' => true,
  29. 'default' => null,
  30. 'limit' => 11,
  31. ]
  32. );
  33. $indexable_table->column( 'canonical', 'string', [ 'null' => true, 'limit' => 191 ] );
  34. $indexable_table->column( 'title', 'string', [ 'null' => true, 'limit' => 191 ] );
  35. $indexable_table->column( 'description', 'text', [ 'null' => true ] );
  36. $indexable_table->column( 'breadcrumb_title', 'string', [ 'null' => true, 'limit' => 191 ] );
  37. $indexable_table->column( 'is_robots_noindex', 'boolean', [ 'null' => true, 'default' => false ] );
  38. $indexable_table->column( 'is_robots_nofollow', 'boolean', [ 'null' => true, 'default' => false ] );
  39. $indexable_table->column( 'is_robots_noarchive', 'boolean', [ 'null' => true, 'default' => false ] );
  40. $indexable_table->column( 'is_robots_noimageindex', 'boolean', [ 'null' => true, 'default' => false ] );
  41. $indexable_table->column( 'is_robots_nosnippet', 'boolean', [ 'null' => true, 'default' => false ] );
  42. $indexable_table->column( 'primary_focus_keyword', 'string', [ 'null' => true, 'limit' => 191 ] );
  43. $indexable_table->column( 'primary_focus_keyword_score', 'integer', [ 'null' => true, 'limit' => 3 ] );
  44. $indexable_table->column( 'readability_score', 'integer', [ 'null' => true, 'limit' => 3 ] );
  45. $indexable_table->column( 'is_cornerstone', 'boolean', [ 'default' => false ] );
  46. $indexable_table->column( 'link_count', 'integer', [ 'null' => true, 'limit' => 11 ] );
  47. $indexable_table->column( 'incoming_link_count', 'integer', [ 'null' => true, 'limit' => 11 ] );
  48. // Exexcute the SQL to create the table.
  49. $indexable_table->finish();
  50. $this->add_index(
  51. $table_name,
  52. [
  53. 'permalink',
  54. ],
  55. [
  56. 'name' => 'unique_permalink',
  57. 'unique' => true,
  58. ]
  59. );
  60. $this->add_index(
  61. $table_name,
  62. [
  63. 'object_type',
  64. 'object_sub_type',
  65. ],
  66. [
  67. 'name' => 'indexable',
  68. ]
  69. );
  70. $this->add_index(
  71. $table_name,
  72. [
  73. 'primary_focus_keyword_score',
  74. 'object_type',
  75. 'object_sub_type',
  76. ],
  77. [
  78. 'name' => 'primary_focus_keyword_score',
  79. ]
  80. );
  81. $this->add_index(
  82. $table_name,
  83. [
  84. 'is_cornerstone',
  85. 'object_type',
  86. 'object_sub_type',
  87. ],
  88. [
  89. 'name' => 'cornerstones',
  90. ]
  91. );
  92. $this->add_index(
  93. $table_name,
  94. [
  95. 'incoming_link_count',
  96. 'object_type',
  97. 'object_sub_type',
  98. ],
  99. [
  100. 'name' => 'orphaned_content',
  101. ]
  102. );
  103. $this->add_index(
  104. $table_name,
  105. [
  106. 'is_robots_noindex',
  107. 'object_id',
  108. 'object_type',
  109. 'object_sub_type',
  110. ],
  111. [
  112. 'name' => 'robots_noindex',
  113. ]
  114. );
  115. $this->add_timestamps( $table_name );
  116. }
  117. /**
  118. * Migration down.
  119. */
  120. public function down() {
  121. $this->drop_table( $this->get_table_name() );
  122. }
  123. /**
  124. * Retrieves the table name to use.
  125. *
  126. * @return string The table name to use.
  127. */
  128. protected function get_table_name() {
  129. return Yoast_Model::get_table_name( 'Indexable' );
  130. }
  131. }