MediaWiki  1.29.1
moveToExternal.php
Go to the documentation of this file.
1 <?php
24 define( 'REPORTING_INTERVAL', 1 );
25 
26 if ( !defined( 'MEDIAWIKI' ) ) {
27  $optionsWithArgs = [ 'e', 's' ];
28  require_once __DIR__ . '/../commandLine.inc';
29  require_once 'resolveStubs.php';
30 
31  $fname = 'moveToExternal';
32 
33  if ( !isset( $args[0] ) ) {
34  print "Usage: php moveToExternal.php [-s <startid>] [-e <endid>] <cluster>\n";
35  exit;
36  }
37 
38  $cluster = $args[0];
39  $dbw = wfGetDB( DB_MASTER );
40 
41  if ( isset( $options['e'] ) ) {
42  $maxID = $options['e'];
43  } else {
44  $maxID = $dbw->selectField( 'text', 'MAX(old_id)', false, $fname );
45  }
46  $minID = isset( $options['s'] ) ? $options['s'] : 1;
47 
48  moveToExternal( $cluster, $maxID, $minID );
49 }
50 
51 function moveToExternal( $cluster, $maxID, $minID = 1 ) {
52  $fname = 'moveToExternal';
53  $dbw = wfGetDB( DB_MASTER );
54  $dbr = wfGetDB( DB_REPLICA );
55 
56  $count = $maxID - $minID + 1;
57  $blockSize = 1000;
58  $numBlocks = ceil( $count / $blockSize );
59  print "Moving text rows from $minID to $maxID to external storage\n";
60  $ext = new ExternalStoreDB;
61  $numMoved = 0;
62 
63  for ( $block = 0; $block < $numBlocks; $block++ ) {
64  $blockStart = $block * $blockSize + $minID;
65  $blockEnd = $blockStart + $blockSize - 1;
66 
67  if ( !( $block % REPORTING_INTERVAL ) ) {
68  print "oldid=$blockStart, moved=$numMoved\n";
70  }
71 
72  $res = $dbr->select( 'text', [ 'old_id', 'old_flags', 'old_text' ],
73  [
74  "old_id BETWEEN $blockStart AND $blockEnd",
75  'old_flags NOT ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
76  ], $fname );
77  foreach ( $res as $row ) {
78  # Resolve stubs
79  $text = $row->old_text;
80  $id = $row->old_id;
81  if ( $row->old_flags === '' ) {
82  $flags = 'external';
83  } else {
84  $flags = "{$row->old_flags},external";
85  }
86 
87  if ( strpos( $flags, 'object' ) !== false ) {
88  $obj = unserialize( $text );
89  $className = strtolower( get_class( $obj ) );
90  if ( $className == 'historyblobstub' ) {
91  # resolveStub( $id, $row->old_text, $row->old_flags );
92  # $numStubs++;
93  continue;
94  } elseif ( $className == 'historyblobcurstub' ) {
95  $text = gzdeflate( $obj->getText() );
96  $flags = 'utf-8,gzip,external';
97  } elseif ( $className == 'concatenatedgziphistoryblob' ) {
98  // Do nothing
99  } else {
100  print "Warning: unrecognised object class \"$className\"\n";
101  continue;
102  }
103  } else {
104  $className = false;
105  }
106 
107  if ( strlen( $text ) < 100 && $className === false ) {
108  // Don't move tiny revisions
109  continue;
110  }
111 
112  # print "Storing " . strlen( $text ) . " bytes to $url\n";
113  # print "old_id=$id\n";
114 
115  $url = $ext->store( $cluster, $text );
116  if ( !$url ) {
117  print "Error writing to external storage\n";
118  exit;
119  }
120  $dbw->update( 'text',
121  [ 'old_flags' => $flags, 'old_text' => $url ],
122  [ 'old_id' => $id ], $fname );
123  $numMoved++;
124  }
125  }
126 }
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
ExternalStoreDB
DB accessable external objects.
Definition: ExternalStoreDB.php:36
$optionsWithArgs
global $optionsWithArgs
Definition: commandLine.inc:24
$maxID
$maxID
Definition: cleanup.php:95
moveToExternal
if(!defined( 'MEDIAWIKI')) moveToExternal( $cluster, $maxID, $minID=1)
Definition: moveToExternal.php:51
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:36
unserialize
unserialize( $serialized)
Definition: ApiMessage.php:185
$res
$res
Definition: database.txt:21
wfWaitForSlaves
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Definition: GlobalFunctions.php:3214
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
REPORTING_INTERVAL
const REPORTING_INTERVAL
Definition: moveToExternal.php:24
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
$args
if( $line===false) $args
Definition: cdb.php:63
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
$ext
$ext
Definition: NoLocalSettings.php:25
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$options
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1049
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2749