MediaWiki  1.30.0
populateRecentChangesSource.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
27 
35  public function __construct() {
36  parent::__construct();
37  $this->addDescription(
38  'Populates rc_source field of the recentchanges table with the data in rc_type.' );
39  $this->setBatchSize( 100 );
40  }
41 
42  protected function doDBUpdates() {
43  $dbw = $this->getDB( DB_MASTER );
44  if ( !$dbw->fieldExists( 'recentchanges', 'rc_source' ) ) {
45  $this->error( 'rc_source field in recentchanges table does not exist.' );
46  }
47 
48  $start = $dbw->selectField( 'recentchanges', 'MIN(rc_id)', false, __METHOD__ );
49  if ( !$start ) {
50  $this->output( "Nothing to do.\n" );
51 
52  return true;
53  }
54  $end = $dbw->selectField( 'recentchanges', 'MAX(rc_id)', false, __METHOD__ );
55  $end += $this->mBatchSize - 1;
56  $blockStart = $start;
57  $blockEnd = $start + $this->mBatchSize - 1;
58 
59  $updatedValues = $this->buildUpdateCondition( $dbw );
60 
61  while ( $blockEnd <= $end ) {
62  $cond = "rc_id BETWEEN $blockStart AND $blockEnd";
63 
64  $dbw->update(
65  'recentchanges',
66  [ $updatedValues ],
67  [
68  "rc_source = ''",
69  "rc_id BETWEEN $blockStart AND $blockEnd"
70  ],
71  __METHOD__
72  );
73 
74  $this->output( "." );
76 
77  $blockStart += $this->mBatchSize;
78  $blockEnd += $this->mBatchSize;
79  }
80 
81  $this->output( "\nDone.\n" );
82  }
83 
84  protected function getUpdateKey() {
85  return __CLASS__;
86  }
87 
88  protected function buildUpdateCondition( IDatabase $dbw ) {
89  $rcNew = $dbw->addQuotes( RC_NEW );
90  $rcSrcNew = $dbw->addQuotes( RecentChange::SRC_NEW );
91  $rcEdit = $dbw->addQuotes( RC_EDIT );
92  $rcSrcEdit = $dbw->addQuotes( RecentChange::SRC_EDIT );
93  $rcLog = $dbw->addQuotes( RC_LOG );
94  $rcSrcLog = $dbw->addQuotes( RecentChange::SRC_LOG );
95  $rcExternal = $dbw->addQuotes( RC_EXTERNAL );
96  $rcSrcExternal = $dbw->addQuotes( RecentChange::SRC_EXTERNAL );
97 
98  return "rc_source = CASE
99  WHEN rc_type = $rcNew THEN $rcSrcNew
100  WHEN rc_type = $rcEdit THEN $rcSrcEdit
101  WHEN rc_type = $rcLog THEN $rcSrcLog
102  WHEN rc_type = $rcExternal THEN $rcSrcExternal
103  ELSE ''
104  END";
105  }
106 }
107 
108 $maintClass = "PopulateRecentChangesSource";
109 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance\$mBatchSize
int $mBatchSize
Batch size.
Definition: Maintenance.php:103
PopulateRecentChangesSource\buildUpdateCondition
buildUpdateCondition(IDatabase $dbw)
Definition: populateRecentChangesSource.php:88
RC_EXTERNAL
const RC_EXTERNAL
Definition: Defines.php:146
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
PopulateRecentChangesSource\__construct
__construct()
Default constructor.
Definition: populateRecentChangesSource.php:35
RC_LOG
const RC_LOG
Definition: Defines.php:145
PopulateRecentChangesSource
Maintenance script to populate the rc_source field.
Definition: populateRecentChangesSource.php:34
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
RC_EDIT
const RC_EDIT
Definition: Defines.php:143
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:3010
RecentChange\SRC_LOG
const SRC_LOG
Definition: RecentChange.php:72
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
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: Maintenance.php:1562
RecentChange\SRC_EDIT
const SRC_EDIT
Definition: RecentChange.php:70
DB_MASTER
const DB_MASTER
Definition: defines.php:26
RecentChange\SRC_NEW
const SRC_NEW
Definition: RecentChange.php:71
PopulateRecentChangesSource\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: populateRecentChangesSource.php:42
RC_NEW
const RC_NEW
Definition: Defines.php:144
$maintClass
$maintClass
Definition: populateRecentChangesSource.php:108
Wikimedia\Rdbms\IDatabase\addQuotes
addQuotes( $s)
Adds quotes and backslashes.
PopulateRecentChangesSource\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: populateRecentChangesSource.php:84
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1251
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:392
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:314
RecentChange\SRC_EXTERNAL
const SRC_EXTERNAL
Definition: RecentChange.php:73