MediaWiki  1.34.0
FileJournal.php
Go to the documentation of this file.
1 <?php
29 use Wikimedia\ObjectFactory;
30 use Wikimedia\Timestamp\ConvertibleTimestamp;
31 
40 abstract class FileJournal {
42  protected $backend;
44  protected $ttlDays;
45 
52  public function __construct( array $config ) {
53  $this->ttlDays = $config['ttlDays'] ?? false;
54  }
55 
64  final public static function factory( array $config, $backend ) {
65  $jrn = ObjectFactory::getObjectFromSpec(
66  $config,
67  [ 'specIsArg' => true, 'assertClass' => __CLASS__ ]
68  );
69  $jrn->backend = $backend;
70 
71  return $jrn;
72  }
73 
79  final public function getTimestampedUUID() {
80  $s = '';
81  for ( $i = 0; $i < 5; $i++ ) {
82  $s .= mt_rand( 0, 2147483647 );
83  }
84  $s = Wikimedia\base_convert( sha1( $s ), 16, 36, 31 );
85 
86  $timestamp = ConvertibleTimestamp::convert( TS_MW, time() );
87 
88  return substr( Wikimedia\base_convert( $timestamp, 10, 36, 9 ) . $s, 0, 31 );
89  }
90 
102  final public function logChangeBatch( array $entries, $batchId ) {
103  if ( $entries === [] ) {
104  return StatusValue::newGood();
105  }
106 
107  return $this->doLogChangeBatch( $entries, $batchId );
108  }
109 
117  abstract protected function doLogChangeBatch( array $entries, $batchId );
118 
124  final public function getCurrentPosition() {
125  return $this->doGetCurrentPosition();
126  }
127 
132  abstract protected function doGetCurrentPosition();
133 
140  final public function getPositionAtTime( $time ) {
141  return $this->doGetPositionAtTime( $time );
142  }
143 
149  abstract protected function doGetPositionAtTime( $time );
150 
168  final public function getChangeEntries( $start = null, $limit = 0, &$next = null ) {
169  $entries = $this->doGetChangeEntries( $start, $limit ? $limit + 1 : 0 );
170  if ( $limit && count( $entries ) > $limit ) {
171  $last = array_pop( $entries ); // remove the extra entry
172  $next = $last['id']; // update for next call
173  } else {
174  $next = null; // end of list
175  }
176 
177  return $entries;
178  }
179 
186  abstract protected function doGetChangeEntries( $start, $limit );
187 
193  final public function purgeOldLogs() {
194  return $this->doPurgeOldLogs();
195  }
196 
201  abstract protected function doPurgeOldLogs();
202 }
FileJournal\doGetPositionAtTime
doGetPositionAtTime( $time)
FileJournal\doGetChangeEntries
doGetChangeEntries( $start, $limit)
FileJournal\$backend
string $backend
Definition: FileJournal.php:42
$s
$s
Definition: mergeMessageFileList.php:185
$last
$last
Definition: profileinfo.php:419
FileJournal\getPositionAtTime
getPositionAtTime( $time)
Get the position ID of the latest journal entry at some point in time.
Definition: FileJournal.php:140
FileJournal\getCurrentPosition
getCurrentPosition()
Get the position ID of the latest journal entry.
Definition: FileJournal.php:124
FileJournal\doGetCurrentPosition
doGetCurrentPosition()
FileJournal\doPurgeOldLogs
doPurgeOldLogs()
FileJournal
Class for handling file operation journaling.
Definition: FileJournal.php:40
FileJournal\logChangeBatch
logChangeBatch(array $entries, $batchId)
Log changes made by a batch file operation.
Definition: FileJournal.php:102
FileJournal\__construct
__construct(array $config)
Construct a new instance from configuration.
Definition: FileJournal.php:52
FileJournal\getChangeEntries
getChangeEntries( $start=null, $limit=0, &$next=null)
Get an array of file change log entries.
Definition: FileJournal.php:168
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
FileJournal\doLogChangeBatch
doLogChangeBatch(array $entries, $batchId)
FileJournal\$ttlDays
int false $ttlDays
Definition: FileJournal.php:44
FileJournal\purgeOldLogs
purgeOldLogs()
Purge any old log entries.
Definition: FileJournal.php:193
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:79
FileJournal\factory
static factory(array $config, $backend)
Create an appropriate FileJournal object from config.
Definition: FileJournal.php:64