MediaWiki REL1_35
FileJournal.php
Go to the documentation of this file.
1<?php
29use Wikimedia\ObjectFactory;
30use Wikimedia\Timestamp\ConvertibleTimestamp;
31
41abstract 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 // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
180 $next = $last['id']; // update for next call
181 } else {
182 $next = null; // end of list
183 }
184
185 return $entries;
186 }
187
194 abstract protected function doGetChangeEntries( $start, $limit );
195
201 final public function purgeOldLogs() {
202 return $this->doPurgeOldLogs();
203 }
204
209 abstract protected function doPurgeOldLogs();
210}
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Class for handling file operation journaling.
logChangeBatch(array $entries, $batchId)
Log changes made by a batch file operation.
__construct(array $config)
Construct a new instance from configuration.
getPositionAtTime( $time)
Get the position ID of the latest journal entry at some point in time.
int false $ttlDays
getCurrentPosition()
Get the position ID of the latest journal entry.
doGetCurrentPosition()
purgeOldLogs()
Purge any old log entries.
doGetChangeEntries( $start, $limit)
string $backend
getTimestampedUUID()
Get a statistically unique ID string.
getChangeEntries( $start=null, $limit=0, &$next=null)
Get an array of file change log entries.
static factory(array $config, $backend)
Create an appropriate FileJournal object from config.
doLogChangeBatch(array $entries, $batchId)
doGetPositionAtTime( $time)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...