cleanupAncientTables.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Cleans up old database tables, dropping old indexes and fields.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup Maintenance
  22. */
  23. require_once __DIR__ . '/Maintenance.php';
  24. /**
  25. * Maintenance script to cleans up old database tables, dropping old indexes
  26. * and fields.
  27. *
  28. * @ingroup Maintenance
  29. */
  30. class CleanupAncientTables extends Maintenance {
  31. public function __construct() {
  32. parent::__construct();
  33. $this->addDescription( 'Cleanup ancient tables and indexes' );
  34. $this->addOption( 'force', 'Actually run this script' );
  35. }
  36. public function execute() {
  37. if ( !$this->hasOption( 'force' ) ) {
  38. $this->error( "This maintenance script will remove old columns and indexes.\n"
  39. . "It is recommended to backup your database first, and ensure all your data has\n"
  40. . "been migrated to newer tables. If you want to continue, run this script again\n"
  41. . "with --force.\n"
  42. );
  43. }
  44. $db = $this->getDB( DB_MASTER );
  45. $ancientTables = [
  46. 'blobs', // 1.4
  47. 'brokenlinks', // 1.4
  48. 'cur', // 1.4
  49. 'ip_blocks_old', // Temporary in 1.6
  50. 'links', // 1.4
  51. 'linkscc', // 1.4
  52. // 'math', // 1.18, but don't want to drop if math extension is enabled...
  53. 'old', // 1.4
  54. 'oldwatchlist', // pre 1.1?
  55. 'trackback', // 1.19
  56. 'user_rights', // 1.5
  57. 'validate', // 1.6
  58. ];
  59. foreach ( $ancientTables as $table ) {
  60. if ( $db->tableExists( $table, __METHOD__ ) ) {
  61. $this->output( "Dropping table $table..." );
  62. $db->dropTable( $table, __METHOD__ );
  63. $this->output( "done.\n" );
  64. }
  65. }
  66. $this->output( "Cleaning up text table\n" );
  67. $oldIndexes = [
  68. 'old_namespace',
  69. 'old_timestamp',
  70. 'name_title_timestamp',
  71. 'user_timestamp',
  72. 'usertext_timestamp',
  73. ];
  74. foreach ( $oldIndexes as $index ) {
  75. if ( $db->indexExists( 'text', $index, __METHOD__ ) ) {
  76. $this->output( "Dropping index $index from the text table..." );
  77. $db->query( "DROP INDEX " . $db->addIdentifierQuotes( $index )
  78. . " ON " . $db->tableName( 'text' ) );
  79. $this->output( "done.\n" );
  80. }
  81. }
  82. $oldFields = [
  83. 'old_namespace',
  84. 'old_title',
  85. 'old_comment',
  86. 'old_user',
  87. 'old_user_text',
  88. 'old_timestamp',
  89. 'old_minor_edit',
  90. 'inverse_timestamp',
  91. ];
  92. foreach ( $oldFields as $field ) {
  93. if ( $db->fieldExists( 'text', $field, __METHOD__ ) ) {
  94. $this->output( "Dropping the $field field from the text table..." );
  95. $db->query( "ALTER TABLE " . $db->tableName( 'text' )
  96. . " DROP COLUMN " . $db->addIdentifierQuotes( $field ) );
  97. $this->output( "done.\n" );
  98. }
  99. }
  100. $this->output( "Done!\n" );
  101. }
  102. }
  103. $maintClass = CleanupAncientTables::class;
  104. require_once RUN_MAINTENANCE_IF_MAIN;