[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/maintenance/storage/ -> resolveStubs.php (source)

   1  <?php
   2  /**
   3   * Convert history stubs that point to an external row to direct external
   4   * pointers.
   5   *
   6   * This program is free software; you can redistribute it and/or modify
   7   * it under the terms of the GNU General Public License as published by
   8   * the Free Software Foundation; either version 2 of the License, or
   9   * (at your option) any later version.
  10   *
  11   * This program is distributed in the hope that it will be useful,
  12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14   * GNU General Public License for more details.
  15   *
  16   * You should have received a copy of the GNU General Public License along
  17   * with this program; if not, write to the Free Software Foundation, Inc.,
  18   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19   * http://www.gnu.org/copyleft/gpl.html
  20   *
  21   * @file
  22   * @ingroup Maintenance ExternalStorage
  23   */
  24  
  25  define( 'REPORTING_INTERVAL', 100 );
  26  
  27  if ( !defined( 'MEDIAWIKI' ) ) {
  28      $optionsWithArgs = array( 'm' );
  29  
  30      require_once  __DIR__ . '/../commandLine.inc';
  31  
  32      resolveStubs();
  33  }
  34  
  35  /**
  36   * Convert history stubs that point to an external row to direct
  37   * external pointers
  38   */
  39  function resolveStubs() {
  40      $fname = 'resolveStubs';
  41  
  42      $dbr = wfGetDB( DB_SLAVE );
  43      $maxID = $dbr->selectField( 'text', 'MAX(old_id)', false, $fname );
  44      $blockSize = 10000;
  45      $numBlocks = intval( $maxID / $blockSize ) + 1;
  46  
  47      for ( $b = 0; $b < $numBlocks; $b++ ) {
  48          wfWaitForSlaves();
  49  
  50          printf( "%5.2f%%\n", $b / $numBlocks * 100 );
  51          $start = intval( $maxID / $numBlocks ) * $b + 1;
  52          $end = intval( $maxID / $numBlocks ) * ( $b + 1 );
  53  
  54          $res = $dbr->select( 'text', array( 'old_id', 'old_text', 'old_flags' ),
  55              "old_id>=$start AND old_id<=$end " .
  56              "AND old_flags LIKE '%object%' AND old_flags NOT LIKE '%external%' " .
  57              'AND LOWER(CONVERT(LEFT(old_text,22) USING latin1)) = \'o:15:"historyblobstub"\'',
  58              $fname );
  59          foreach ( $res as $row ) {
  60              resolveStub( $row->old_id, $row->old_text, $row->old_flags );
  61          }
  62      }
  63      print "100%\n";
  64  }
  65  
  66  /**
  67   * Resolve a history stub
  68   * @param int $id
  69   * @param string $stubText
  70   * @param string $flags
  71   */
  72  function resolveStub( $id, $stubText, $flags ) {
  73      $fname = 'resolveStub';
  74  
  75      $stub = unserialize( $stubText );
  76      $flags = explode( ',', $flags );
  77  
  78      $dbr = wfGetDB( DB_SLAVE );
  79      $dbw = wfGetDB( DB_MASTER );
  80  
  81      if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
  82          print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
  83  
  84          return;
  85      }
  86  
  87      # Get the (maybe) external row
  88      $externalRow = $dbr->selectRow(
  89          'text',
  90          array( 'old_text' ),
  91          array(
  92              'old_id' => $stub->mOldId,
  93              'old_flags' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() )
  94          ),
  95          $fname
  96      );
  97  
  98      if ( !$externalRow ) {
  99          # Object wasn't external
 100          return;
 101      }
 102  
 103      # Preserve the legacy encoding flag, but switch from object to external
 104      if ( in_array( 'utf-8', $flags ) ) {
 105          $newFlags = 'external,utf-8';
 106      } else {
 107          $newFlags = 'external';
 108      }
 109  
 110      # Update the row
 111      # print "oldid=$id\n";
 112      $dbw->update( 'text',
 113          array( /* SET */
 114              'old_flags' => $newFlags,
 115              'old_text' => $externalRow->old_text . '/' . $stub->mHash
 116          ),
 117          array( /* WHERE */
 118              'old_id' => $id
 119          ), $fname
 120      );
 121  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1