MediaWiki REL1_34
FileJournal.php
Go to the documentation of this file.
1<?php
29use Wikimedia\ObjectFactory;
30use Wikimedia\Timestamp\ConvertibleTimestamp;
31
40abstract 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}
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...
$last