MediaWiki  master
FileJournal.php
Go to the documentation of this file.
00001 <?php
00038 abstract class FileJournal {
00039         protected $backend; // string
00040         protected $ttlDays; // integer
00041 
00049         protected function __construct( array $config ) {
00050                 $this->ttlDays = isset( $config['ttlDays'] ) ? $config['ttlDays'] : false;
00051         }
00052 
00061         final public static function factory( array $config, $backend ) {
00062                 $class = $config['class'];
00063                 $jrn = new $class( $config );
00064                 if ( !$jrn instanceof self ) {
00065                         throw new MWException( "Class given is not an instance of FileJournal." );
00066                 }
00067                 $jrn->backend = $backend;
00068                 return $jrn;
00069         }
00070 
00076         final public function getTimestampedUUID() {
00077                 $s = '';
00078                 for ( $i = 0; $i < 5; $i++ ) {
00079                         $s .= mt_rand( 0, 2147483647 );
00080                 }
00081                 $s = wfBaseConvert( sha1( $s ), 16, 36, 31 );
00082                 return substr( wfBaseConvert( wfTimestamp( TS_MW ), 10, 36, 9 ) . $s, 0, 31 );
00083         }
00084 
00097         final public function logChangeBatch( array $entries, $batchId ) {
00098                 if ( !count( $entries ) ) {
00099                         return Status::newGood();
00100                 }
00101                 return $this->doLogChangeBatch( $entries, $batchId );
00102         }
00103 
00111         abstract protected function doLogChangeBatch( array $entries, $batchId );
00112 
00118         final public function getCurrentPosition() {
00119                 return $this->doGetCurrentPosition();
00120         }
00121 
00126         abstract protected function doGetCurrentPosition();
00127 
00148         final public function getChangeEntries( $start = null, $limit = 0, &$next = null ) {
00149                 $entries = $this->doGetChangeEntries( $start, $limit ? $limit + 1 : 0 );
00150                 if ( $limit && count( $entries ) > $limit ) {
00151                         $last = array_pop( $entries ); // remove the extra entry
00152                         $next = $last['id']; // update for next call
00153                 } else {
00154                         $next = null; // end of list
00155                 }
00156                 return $entries;
00157         }
00158 
00163         abstract protected function doGetChangeEntries( $start, $limit );
00164 
00170         final public function purgeOldLogs() {
00171                 return $this->doPurgeOldLogs();
00172         }
00173 
00178         abstract protected function doPurgeOldLogs();
00179 }
00180 
00185 class NullFileJournal extends FileJournal {
00192         protected function doLogChangeBatch( array $entries, $batchId ) {
00193                 return Status::newGood();
00194         }
00195 
00200         protected function doGetCurrentPosition() {
00201                 return false;
00202         }
00203 
00208         protected function doGetChangeEntries( $start, $limit ) {
00209                 return array();
00210         }
00211 
00216         protected function doPurgeOldLogs() {
00217                 return Status::newGood();
00218         }
00219 }