MediaWiki  master
FileJournal.php
Go to the documentation of this file.
1 <?php
31 
40 abstract class FileJournal {
42  protected $backend;
44  protected $ttlDays;
45 
53  public function __construct( array $config ) {
54  $this->backend = $config['backend'];
55  $this->ttlDays = $config['ttlDays'] ?? false;
56  }
57 
67  final public static function factory( array $config, $backend ) {
68  wfDeprecated( __METHOD__, '1.35' );
69 
70  $jrn = ObjectFactory::getObjectFromSpec(
71  [ 'backend' => $backend ] + $config,
72  [ 'specIsArg' => true, 'assertClass' => __CLASS__ ]
73  );
74 
75  return $jrn;
76  }
77 
83  final public function getTimestampedUUID() {
84  $s = '';
85  for ( $i = 0; $i < 5; $i++ ) {
86  $s .= mt_rand( 0, 2147483647 );
87  }
88  $s = Wikimedia\base_convert( sha1( $s ), 16, 36, 31 );
89 
90  $timestamp = ConvertibleTimestamp::convert( TS_MW, time() );
91 
92  return substr( Wikimedia\base_convert( $timestamp, 10, 36, 9 ) . $s, 0, 31 );
93  }
94 
106  final public function logChangeBatch( array $entries, $batchId ) {
107  if ( $entries === [] ) {
108  return StatusValue::newGood();
109  }
110 
111  return $this->doLogChangeBatch( $entries, $batchId );
112  }
113 
121  abstract protected function doLogChangeBatch( array $entries, $batchId );
122 
128  final public function getCurrentPosition() {
129  return $this->doGetCurrentPosition();
130  }
131 
136  abstract protected function doGetCurrentPosition();
137 
144  final public function getPositionAtTime( $time ) {
145  return $this->doGetPositionAtTime( $time );
146  }
147 
153  abstract protected function doGetPositionAtTime( $time );
154 
173  final public function getChangeEntries( $start = null, $limit = 0, &$next = null ) {
174  $entries = $this->doGetChangeEntries( $start, $limit ? $limit + 1 : 0 );
175  if ( $limit && count( $entries ) > $limit ) {
176  $last = array_pop( $entries ); // remove the extra entry
177  $next = $last['id']; // update for next call
178  } else {
179  $next = null; // end of list
180  }
181 
182  return $entries;
183  }
184 
191  abstract protected function doGetChangeEntries( $start, $limit );
192 
198  final public function purgeOldLogs() {
199  return $this->doPurgeOldLogs();
200  }
201 
206  abstract protected function doPurgeOldLogs();
207 }
string $backend
Definition: FileJournal.php:42
doGetChangeEntries( $start, $limit)
getPositionAtTime( $time)
Get the position ID of the latest journal entry at some point in time.
doGetCurrentPosition()
__construct(array $config)
Construct a new instance from configuration.
Definition: FileJournal.php:53
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
getCurrentPosition()
Get the position ID of the latest journal entry.
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
logChangeBatch(array $entries, $batchId)
Log changes made by a batch file operation.
getChangeEntries( $start=null, $limit=0, &$next=null)
Get an array of file change log entries.
doLogChangeBatch(array $entries, $batchId)
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
int false $ttlDays
Definition: FileJournal.php:44
getTimestampedUUID()
Get a statistically unique ID string.
Definition: FileJournal.php:83
purgeOldLogs()
Purge any old log entries.
doGetPositionAtTime( $time)
static factory(array $config, $backend)
Create an appropriate FileJournal object from config.
Definition: FileJournal.php:67
Class for handling file operation journaling.
Definition: FileJournal.php:40