MediaWiki  1.27.2
populateRecentChangesSource.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
33  public function __construct() {
34  parent::__construct();
35  $this->addDescription(
36  'Populates rc_source field of the recentchanges table with the data in rc_type.' );
37  $this->setBatchSize( 100 );
38  }
39 
40  protected function doDBUpdates() {
41  $dbw = $this->getDB( DB_MASTER );
42  if ( !$dbw->fieldExists( 'recentchanges', 'rc_source' ) ) {
43  $this->error( 'rc_source field in recentchanges table does not exist.' );
44  }
45 
46  $start = $dbw->selectField( 'recentchanges', 'MIN(rc_id)', false, __METHOD__ );
47  if ( !$start ) {
48  $this->output( "Nothing to do.\n" );
49 
50  return true;
51  }
52  $end = $dbw->selectField( 'recentchanges', 'MAX(rc_id)', false, __METHOD__ );
53  $end += $this->mBatchSize - 1;
54  $blockStart = $start;
55  $blockEnd = $start + $this->mBatchSize - 1;
56 
57  $updatedValues = $this->buildUpdateCondition( $dbw );
58 
59  while ( $blockEnd <= $end ) {
60  $cond = "rc_id BETWEEN $blockStart AND $blockEnd";
61 
62  $dbw->update(
63  'recentchanges',
64  [ $updatedValues ],
65  [
66  "rc_source = ''",
67  "rc_id BETWEEN $blockStart AND $blockEnd"
68  ],
69  __METHOD__
70  );
71 
72  $this->output( "." );
74 
75  $blockStart += $this->mBatchSize;
76  $blockEnd += $this->mBatchSize;
77  }
78 
79  $this->output( "\nDone.\n" );
80  }
81 
82  protected function getUpdateKey() {
83  return __CLASS__;
84  }
85 
86  protected function buildUpdateCondition( DatabaseBase $dbw ) {
87  $rcNew = $dbw->addQuotes( RC_NEW );
88  $rcSrcNew = $dbw->addQuotes( RecentChange::SRC_NEW );
89  $rcEdit = $dbw->addQuotes( RC_EDIT );
90  $rcSrcEdit = $dbw->addQuotes( RecentChange::SRC_EDIT );
91  $rcLog = $dbw->addQuotes( RC_LOG );
92  $rcSrcLog = $dbw->addQuotes( RecentChange::SRC_LOG );
93  $rcExternal = $dbw->addQuotes( RC_EXTERNAL );
94  $rcSrcExternal = $dbw->addQuotes( RecentChange::SRC_EXTERNAL );
95 
96  return "rc_source = CASE
97  WHEN rc_type = $rcNew THEN $rcSrcNew
98  WHEN rc_type = $rcEdit THEN $rcSrcEdit
99  WHEN rc_type = $rcLog THEN $rcSrcLog
100  WHEN rc_type = $rcExternal THEN $rcSrcExternal
101  ELSE ''
102  END";
103  }
104 }
105 
106 $maintClass = "PopulateRecentChangesSource";
107 require_once RUN_MAINTENANCE_IF_MAIN;
wfWaitForSlaves($ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the slaves to catch up to the master position.
getDB($db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Maintenance script to populate the rc_source field.
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
const SRC_EXTERNAL
addQuotes($s)
Adds quotes and backslashes.
Definition: Database.php:1958
addDescription($text)
Set the description text.
output($out, $channel=null)
Throw some output to the user.
Database abstraction object.
Definition: Database.php:32
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
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
int $mBatchSize
Batch size.
Definition: Maintenance.php:99
error($err, $die=0)
Throw an error to the user.
const RC_EXTERNAL
Definition: Defines.php:172
const DB_MASTER
Definition: Defines.php:47
const RC_NEW
Definition: Defines.php:170
setBatchSize($s=0)
Set the batch size.
const RC_EDIT
Definition: Defines.php:169
const RC_LOG
Definition: Defines.php:171