20190529075734_WpYoastExpandIndexable.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * Class WpYoastExpandIndexable
  11. */
  12. class WpYoastExpandIndexable extends Ruckusing_Migration_Base {
  13. /**
  14. * Migration up.
  15. */
  16. public function up() {
  17. $table_name = $this->get_table_name();
  18. $this->add_column( $table_name, 'og_title', 'string', [ 'null' => true, 'limit' => 191 ] );
  19. $this->add_column( $table_name, 'og_image', 'mediumtext', [ 'null' => true ] );
  20. $this->add_column( $table_name, 'og_description', 'mediumtext', [ 'null' => true ] );
  21. $this->add_column( $table_name, 'twitter_title', 'string', [ 'null' => true, 'limit' => 191 ] );
  22. $this->add_column( $table_name, 'twitter_image', 'mediumtext', [ 'null' => true ] );
  23. $this->add_column( $table_name, 'twitter_description', 'mediumtext', [ 'null' => true ] );
  24. $this->add_column( $table_name, 'permalink_hash', 'string', [ 'null' => true, 'limit' => 191 ] );
  25. $this->add_index( $table_name, 'permalink_hash' );
  26. $this->remove_index(
  27. $table_name,
  28. [
  29. 'permalink',
  30. ],
  31. [
  32. 'name' => 'unique_permalink',
  33. 'unique' => true,
  34. ]
  35. );
  36. $this->change_column( $table_name, 'permalink', 'mediumtext', [ 'null' => true ] );
  37. $this->change_column( $table_name, 'canonical', 'mediumtext', [ 'null' => true ] );
  38. }
  39. /**
  40. * Migration down.
  41. */
  42. public function down() {
  43. $table_name = $this->get_table_name();
  44. $this->remove_column( $table_name, 'og_title' );
  45. $this->remove_column( $table_name, 'og_image' );
  46. $this->remove_column( $table_name, 'og_description' );
  47. $this->remove_column( $table_name, 'twitter_title' );
  48. $this->remove_column( $table_name, 'twitter_image' );
  49. $this->remove_column( $table_name, 'twitter_description' );
  50. $this->remove_index( $table_name, 'permalink_hash' );
  51. $this->remove_column( $table_name, 'permalink_hash' );
  52. $this->change_column( $table_name, 'permalink', 'string', [ 'null' => true, 'limit' => 191 ] );
  53. $this->change_column( $table_name, 'canonical', 'string', [ 'null' => true, 'limit' => 191 ] );
  54. $this->add_index(
  55. $table_name,
  56. [
  57. 'permalink',
  58. ],
  59. [
  60. 'name' => 'unique_permalink',
  61. 'unique' => true,
  62. ]
  63. );
  64. }
  65. /**
  66. * Retrieves the table name to use.
  67. *
  68. * @return string The table name to use.
  69. */
  70. protected function get_table_name() {
  71. return Yoast_Model::get_table_name( 'Indexable' );
  72. }
  73. }