MediaWiki  master
FileJournal.php
Go to the documentation of this file.
1 <?php
29 use Wikimedia\ObjectFactory;
30 use Wikimedia\Timestamp\ConvertibleTimestamp;
31 
41 abstract class FileJournal {
43  protected $backend;
45  protected $ttlDays;
46 
55  public function __construct( array $config ) {
56  $this->backend = $config['backend'];
57  $this->ttlDays = $config['ttlDays'] ?? false;
58  }
59 
69  final public static function factory( array $config, $backend ) {
70  wfDeprecated( __METHOD__, '1.35' );
71 
72  $jrn = ObjectFactory::getObjectFromSpec(
73  [ 'backend' => $backend ] + $config,
74  [ 'specIsArg' => true, 'assertClass' => __CLASS__ ]
75  );
76 
77  return $jrn;
78  }
79 
85  final public function getTimestampedUUID() {
86  $s = '';
87  for ( $i = 0; $i < 5; $i++ ) {
88  $s .= mt_rand( 0, 2147483647 );
89  }
90  $s = Wikimedia\base_convert( sha1( $s ), 16, 36, 31 );
91 
92  $timestamp = ConvertibleTimestamp::convert( TS_MW, time() );
93 
94  return substr( Wikimedia\base_convert( $timestamp, 10, 36, 9 ) . $s, 0, 31 );
95  }
96 
108  final public function logChangeBatch( array $entries, $batchId ) {
109  if ( $entries === [] ) {
110  return StatusValue::newGood();
111  }
112 
113  return $this->doLogChangeBatch( $entries, $batchId );
114  }
115 
123  abstract protected function doLogChangeBatch( array $entries, $batchId );
124 
130  final public function getCurrentPosition() {
131  return $this->doGetCurrentPosition();
132  }
133 
138  abstract protected function doGetCurrentPosition();
139 
146  final public function getPositionAtTime( $time ) {
147  return $this->doGetPositionAtTime( $time );
148  }
149 
155  abstract protected function doGetPositionAtTime( $time );
156 
175  final public function getChangeEntries( $start = null, $limit = 0, &$next = null ) {
176  $entries = $this->doGetChangeEntries( $start, $limit ? $limit + 1 : 0 );
177  if ( $limit && count( $entries ) > $limit ) {
178  $last = array_pop( $entries ); // remove the extra entry
179  $next = $last['id']; // update for next call
180  } else {
181  $next = null; // end of list
182  }
183 
184  return $entries;
185  }
186 
193  abstract protected function doGetChangeEntries( $start, $limit );
194 
200  final public function purgeOldLogs() {
201  return $this->doPurgeOldLogs();
202  }
203 
208  abstract protected function doPurgeOldLogs();
209 }
FileJournal\doGetPositionAtTime
doGetPositionAtTime( $time)
FileJournal\doGetChangeEntries
doGetChangeEntries( $start, $limit)
FileJournal\$backend
string $backend
Definition: FileJournal.php:43
$s
$s
Definition: mergeMessageFileList.php:184
FileJournal\getPositionAtTime
getPositionAtTime( $time)
Get the position ID of the latest journal entry at some point in time.
Definition: FileJournal.php:146
FileJournal\getCurrentPosition
getCurrentPosition()
Get the position ID of the latest journal entry.
Definition: FileJournal.php:130
FileJournal\doGetCurrentPosition
doGetCurrentPosition()
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1027
FileJournal\doPurgeOldLogs
doPurgeOldLogs()
FileJournal
Class for handling file operation journaling.
Definition: FileJournal.php:41
FileJournal\logChangeBatch
logChangeBatch(array $entries, $batchId)
Log changes made by a batch file operation.
Definition: FileJournal.php:108
FileJournal\__construct
__construct(array $config)
Construct a new instance from configuration.
Definition: FileJournal.php:55
FileJournal\getChangeEntries
getChangeEntries( $start=null, $limit=0, &$next=null)
Get an array of file change log entries.
Definition: FileJournal.php:175
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
FileJournal\doLogChangeBatch
doLogChangeBatch(array $entries, $batchId)
FileJournal\$ttlDays
int false $ttlDays
Definition: FileJournal.php:45
FileJournal\purgeOldLogs
purgeOldLogs()
Purge any old log entries.
Definition: FileJournal.php:200
Wikimedia
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
FileJournal\getTimestampedUUID
getTimestampedUUID()
Get a statistically unique ID string.
Definition: FileJournal.php:85
FileJournal\factory
static factory(array $config, $backend)
Create an appropriate FileJournal object from config.
Definition: FileJournal.php:69