MediaWiki  1.23.8
populateParentId.php
Go to the documentation of this file.
1 <?php
26 require_once __DIR__ . '/Maintenance.php';
27 
35  public function __construct() {
36  parent::__construct();
37  $this->mDescription = "Populates rev_parent_id";
38  }
39 
40  protected function getUpdateKey() {
41  return 'populate rev_parent_id';
42  }
43 
44  protected function updateSkippedMessage() {
45  return 'rev_parent_id column of revision table already populated.';
46  }
47 
48  protected function doDBUpdates() {
49  $db = wfGetDB( DB_MASTER );
50  if ( !$db->tableExists( 'revision' ) ) {
51  $this->error( "revision table does not exist" );
52  return false;
53  }
54  $this->output( "Populating rev_parent_id column\n" );
55  $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ );
56  $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__ );
57  if ( is_null( $start ) || is_null( $end ) ) {
58  $this->output( "...revision table seems to be empty, nothing to do.\n" );
59  return true;
60  }
61  # Do remaining chunk
62  $blockStart = intval( $start );
63  $blockEnd = intval( $start ) + $this->mBatchSize - 1;
64  $count = 0;
65  $changed = 0;
66  while ( $blockStart <= $end ) {
67  $this->output( "...doing rev_id from $blockStart to $blockEnd\n" );
68  $cond = "rev_id BETWEEN $blockStart AND $blockEnd";
69  $res = $db->select( 'revision',
70  array( 'rev_id', 'rev_page', 'rev_timestamp', 'rev_parent_id' ),
71  array( $cond, 'rev_parent_id' => null ), __METHOD__ );
72  # Go through and update rev_parent_id from these rows.
73  # Assume that the previous revision of the title was
74  # the original previous revision of the title when the
75  # edit was made...
76  foreach ( $res as $row ) {
77  # First, check rows with the same timestamp other than this one
78  # with a smaller rev ID. The highest ID "wins". This avoids loops
79  # as timestamp can only decrease and never loops with IDs (from parent to parent)
80  $previousID = $db->selectField( 'revision', 'rev_id',
81  array( 'rev_page' => $row->rev_page, 'rev_timestamp' => $row->rev_timestamp,
82  "rev_id < " . intval( $row->rev_id ) ),
83  __METHOD__,
84  array( 'ORDER BY' => 'rev_id DESC' ) );
85  # If there are none, check the the highest ID with a lower timestamp
86  if ( !$previousID ) {
87  # Get the highest older timestamp
88  $lastTimestamp = $db->selectField( 'revision', 'rev_timestamp',
89  array( 'rev_page' => $row->rev_page, "rev_timestamp < " . $db->addQuotes( $row->rev_timestamp ) ),
90  __METHOD__,
91  array( 'ORDER BY' => 'rev_timestamp DESC' ) );
92  # If there is one, let the highest rev ID win
93  if ( $lastTimestamp ) {
94  $previousID = $db->selectField( 'revision', 'rev_id',
95  array( 'rev_page' => $row->rev_page, 'rev_timestamp' => $lastTimestamp ),
96  __METHOD__,
97  array( 'ORDER BY' => 'rev_id DESC' ) );
98  }
99  }
100  $previousID = intval( $previousID );
101  if ( $previousID != $row->rev_parent_id ) {
102  $changed++;
103  }
104  # Update the row...
105  $db->update( 'revision',
106  array( 'rev_parent_id' => $previousID ),
107  array( 'rev_id' => $row->rev_id ),
108  __METHOD__ );
109  $count++;
110  }
111  $blockStart += $this->mBatchSize;
112  $blockEnd += $this->mBatchSize;
113  wfWaitForSlaves();
114  }
115  $this->output( "rev_parent_id population complete ... {$count} rows [{$changed} changed]\n" );
116  return true;
117  }
118 }
119 
120 $maintClass = "PopulateParentId";
121 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\$mBatchSize
int $mBatchSize
Batch size.
Definition: Maintenance.php:97
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3659
$maintClass
$maintClass
Definition: populateParentId.php:120
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
PopulateParentId\__construct
__construct()
Default constructor.
Definition: populateParentId.php:35
PopulateParentId\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: populateParentId.php:40
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: Maintenance.php:1209
PopulateParentId\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition: populateParentId.php:44
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
wfWaitForSlaves
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
Definition: GlobalFunctions.php:3804
PopulateParentId\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: populateParentId.php:48
PopulateParentId
Maintenance script that makes the required database updates for rev_parent_id to be of any use.
Definition: populateParentId.php:34
$count
$count
Definition: UtfNormalTest2.php:96
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
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
$res
$res
Definition: database.txt:21
$changed
$changed
Definition: UtfNormalGenerate.php:130