MediaWiki  1.23.2
DBFileJournal.php
Go to the documentation of this file.
1 <?php
29 class DBFileJournal extends FileJournal {
31  protected $dbw;
32 
33  protected $wiki = false; // string; wiki DB name
34 
41  protected function __construct( array $config ) {
42  parent::__construct( $config );
43 
44  $this->wiki = $config['wiki'];
45  }
46 
53  protected function doLogChangeBatch( array $entries, $batchId ) {
54  $status = Status::newGood();
55 
56  try {
57  $dbw = $this->getMasterDB();
58  } catch ( DBError $e ) {
59  $status->fatal( 'filejournal-fail-dbconnect', $this->backend );
60 
61  return $status;
62  }
63 
64  $now = wfTimestamp( TS_UNIX );
65 
66  $data = array();
67  foreach ( $entries as $entry ) {
68  $data[] = array(
69  'fj_batch_uuid' => $batchId,
70  'fj_backend' => $this->backend,
71  'fj_op' => $entry['op'],
72  'fj_path' => $entry['path'],
73  'fj_new_sha1' => $entry['newSha1'],
74  'fj_timestamp' => $dbw->timestamp( $now )
75  );
76  }
77 
78  try {
79  $dbw->insert( 'filejournal', $data, __METHOD__ );
80  if ( mt_rand( 0, 99 ) == 0 ) {
81  $this->purgeOldLogs(); // occasionally delete old logs
82  }
83  } catch ( DBError $e ) {
84  $status->fatal( 'filejournal-fail-dbquery', $this->backend );
85 
86  return $status;
87  }
88 
89  return $status;
90  }
91 
96  protected function doGetCurrentPosition() {
97  $dbw = $this->getMasterDB();
98 
99  return $dbw->selectField( 'filejournal', 'MAX(fj_id)',
100  array( 'fj_backend' => $this->backend ),
101  __METHOD__
102  );
103  }
104 
110  protected function doGetPositionAtTime( $time ) {
111  $dbw = $this->getMasterDB();
112 
113  $encTimestamp = $dbw->addQuotes( $dbw->timestamp( $time ) );
114 
115  return $dbw->selectField( 'filejournal', 'fj_id',
116  array( 'fj_backend' => $this->backend, "fj_timestamp <= $encTimestamp" ),
117  __METHOD__,
118  array( 'ORDER BY' => 'fj_timestamp DESC' )
119  );
120  }
121 
128  protected function doGetChangeEntries( $start, $limit ) {
129  $dbw = $this->getMasterDB();
130 
131  $res = $dbw->select( 'filejournal', '*',
132  array(
133  'fj_backend' => $this->backend,
134  'fj_id >= ' . $dbw->addQuotes( (int)$start ) ), // $start may be 0
135  __METHOD__,
136  array_merge( array( 'ORDER BY' => 'fj_id ASC' ),
137  $limit ? array( 'LIMIT' => $limit ) : array() )
138  );
139 
140  $entries = array();
141  foreach ( $res as $row ) {
142  $item = array();
143  foreach ( (array)$row as $key => $value ) {
144  $item[substr( $key, 3 )] = $value; // "fj_op" => "op"
145  }
146  $entries[] = $item;
147  }
148 
149  return $entries;
150  }
151 
157  protected function doPurgeOldLogs() {
158  $status = Status::newGood();
159  if ( $this->ttlDays <= 0 ) {
160  return $status; // nothing to do
161  }
162 
163  $dbw = $this->getMasterDB();
164  $dbCutoff = $dbw->timestamp( time() - 86400 * $this->ttlDays );
165 
166  $dbw->delete( 'filejournal',
167  array( 'fj_timestamp < ' . $dbw->addQuotes( $dbCutoff ) ),
168  __METHOD__
169  );
170 
171  return $status;
172  }
173 
180  protected function getMasterDB() {
181  if ( !$this->dbw ) {
182  // Get a separate connection in autocommit mode
183  $lb = wfGetLBFactory()->newMainLB();
184  $this->dbw = $lb->getConnection( DB_MASTER, array(), $this->wiki );
185  $this->dbw->clearFlag( DBO_TRX );
186  }
187 
188  return $this->dbw;
189  }
190 }
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1358
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
DBFileJournal\doPurgeOldLogs
doPurgeOldLogs()
Definition: DBFileJournal.php:156
DBFileJournal
Version of FileJournal that logs to a DB table.
Definition: DBFileJournal.php:29
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2483
wiki
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory if not default wiki
Definition: maintenance.txt:1
DBFileJournal\doLogChangeBatch
doLogChangeBatch(array $entries, $batchId)
Definition: DBFileJournal.php:52
Status\newGood
static newGood( $value=null)
Factory function for good results.
Definition: Status.php:77
$limit
if( $sleep) $limit
Definition: importImages.php:99
DBFileJournal\getMasterDB
getMasterDB()
Get a master connection to the logging DB.
Definition: DBFileJournal.php:179
DatabaseBase\timestamp
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
Definition: Database.php:3607
DBFileJournal\__construct
__construct(array $config)
Construct a new instance from configuration.
Definition: DBFileJournal.php:40
$lb
if( $wgAPIRequestLog) $lb
Definition: api.php:126
DatabaseBase\addQuotes
addQuotes( $s)
Adds quotes and backslashes.
Definition: Database.php:2477
DatabaseBase\selectField
selectField( $table, $var, $cond='', $fname=__METHOD__, $options=array())
A SELECT wrapper which returns a single field from a single result row.
Definition: Database.php:1281
DatabaseBase\select
select( $table, $vars, $conds='', $fname=__METHOD__, $options=array(), $join_conds=array())
Execute a SELECT query constructed using the various parameters provided.
Definition: Database.php:1575
FileJournal
Class for handling file operation journaling.
Definition: FileJournal.php:38
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
DBError
Database error base class.
Definition: DatabaseError.php:28
DBFileJournal\$wiki
$wiki
Definition: DBFileJournal.php:32
DBFileJournal\doGetChangeEntries
doGetChangeEntries( $start, $limit)
Definition: DBFileJournal.php:127
$value
$value
Definition: styleTest.css.php:45
DatabaseBase
Database abstraction object.
Definition: Database.php:219
DBFileJournal\$dbw
DatabaseBase $dbw
Definition: DBFileJournal.php:30
FileJournal\purgeOldLogs
purgeOldLogs()
Purge any old log entries.
Definition: FileJournal.php:189
wfGetLBFactory
& wfGetLBFactory()
Get the load balancer factory object.
Definition: GlobalFunctions.php:3669
DBFileJournal\doGetPositionAtTime
doGetPositionAtTime( $time)
Definition: DBFileJournal.php:109
DatabaseBase\delete
delete( $table, $conds, $fname=__METHOD__)
DELETE query wrapper.
Definition: Database.php:2884
TS_UNIX
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
Definition: GlobalFunctions.php:2426
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
DBFileJournal\doGetCurrentPosition
doGetCurrentPosition()
Definition: DBFileJournal.php:95
$e
if( $useReadline) $e
Definition: eval.php:66
$res
$res
Definition: database.txt:21
DBO_TRX
const DBO_TRX
Definition: Defines.php:42
DatabaseBase\insert
insert( $table, $a, $fname=__METHOD__, $options=array())
INSERT wrapper, inserts an array into a table.
Definition: Database.php:1860