populateLogUsertext.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Makes the required database updates for Special:ProtectedPages
  4. * to show all protected pages, even ones before the page restrictions
  5. * schema change. All remaining page_restriction column values are moved
  6. * to the new table.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. * http://www.gnu.org/copyleft/gpl.html
  22. *
  23. * @file
  24. * @ingroup Maintenance
  25. */
  26. require_once __DIR__ . '/Maintenance.php';
  27. /**
  28. * Maintenance script that makes the required database updates for
  29. * Special:ProtectedPages to show all protected pages.
  30. *
  31. * @ingroup Maintenance
  32. */
  33. class PopulateLogUsertext extends LoggedUpdateMaintenance {
  34. public function __construct() {
  35. parent::__construct();
  36. $this->addDescription( 'Populates the log_user_text field' );
  37. $this->setBatchSize( 100 );
  38. }
  39. protected function getUpdateKey() {
  40. return 'populate log_usertext';
  41. }
  42. protected function updateSkippedMessage() {
  43. return 'log_user_text column of logging table already populated.';
  44. }
  45. protected function doDBUpdates() {
  46. $db = $this->getDB( DB_MASTER );
  47. $start = $db->selectField( 'logging', 'MIN(log_id)', false, __METHOD__ );
  48. if ( !$start ) {
  49. $this->output( "Nothing to do.\n" );
  50. return true;
  51. }
  52. $end = $db->selectField( 'logging', 'MAX(log_id)', false, __METHOD__ );
  53. # Do remaining chunk
  54. $end += $this->mBatchSize - 1;
  55. $blockStart = $start;
  56. $blockEnd = $start + $this->mBatchSize - 1;
  57. while ( $blockEnd <= $end ) {
  58. $this->output( "...doing log_id from $blockStart to $blockEnd\n" );
  59. $cond = "log_id BETWEEN $blockStart AND $blockEnd AND log_user = user_id";
  60. $res = $db->select( [ 'logging', 'user' ],
  61. [ 'log_id', 'user_name' ], $cond, __METHOD__ );
  62. $this->beginTransaction( $db, __METHOD__ );
  63. foreach ( $res as $row ) {
  64. $db->update( 'logging', [ 'log_user_text' => $row->user_name ],
  65. [ 'log_id' => $row->log_id ], __METHOD__ );
  66. }
  67. $this->commitTransaction( $db, __METHOD__ );
  68. $blockStart += $this->mBatchSize;
  69. $blockEnd += $this->mBatchSize;
  70. wfWaitForSlaves();
  71. }
  72. $this->output( "Done populating log_user_text field.\n" );
  73. return true;
  74. }
  75. }
  76. $maintClass = "PopulateLogUsertext";
  77. require_once RUN_MAINTENANCE_IF_MAIN;