Merge "Adding sanity check to the LinksUpdate() constructor."
[lhc/web/wiklou.git] / includes / filerepo / backend / filejournal / FileJournal.php
index 99f2887..234788b 100644 (file)
@@ -52,9 +52,10 @@ abstract class FileJournal {
 
        /**
         * Create an appropriate FileJournal object from config
-        * 
+        *
         * @param $config Array
         * @param $backend string A registered file backend name
+        * @throws MWException
         * @return FileJournal
         */
        final public static function factory( array $config, $backend ) {
@@ -109,10 +110,47 @@ abstract class FileJournal {
         */
        abstract protected function doLogChangeBatch( array $entries, $batchId );
 
+       /**
+        * Get an array of file change log entries.
+        * A starting change ID and/or limit can be specified.
+        *
+        * The result as a list of associative arrays, each having:
+        *     id         : unique, monotonic, ID for this change
+        *     batch_uuid : UUID for an operation batch
+        *     backend    : the backend name
+        *     op         : primitive operation (create,update,delete)
+        *     path       : affected storage path
+        *     path_sha1  : base 36 sha1 of the affected storage path
+        *     timestamp  : TS_MW timestamp of the batch change
+
+        * Also, $next is updated to the ID of the next entry.
+        *
+        * @param $start integer Starting change ID or null
+        * @param $limit integer Maximum number of items to return
+        * @param &$next string
+        * @return Array
+        */
+       final public function getChangeEntries( $start = null, $limit = 0, &$next = null ) {
+               $entries = $this->doGetChangeEntries( $start, $limit ? $limit + 1 : 0 );
+               if ( $limit && count( $entries ) > $limit ) {
+                       $last = array_pop( $entries ); // remove the extra entry
+                       $next = $last['id']; // update for next call
+               } else {
+                       $next = null; // end of list
+               }
+               return $entries;
+       }
+
+       /**
+        * @see FileJournal::getChangeEntries()
+        * @return Array
+        */
+       abstract protected function doGetChangeEntries( $start, $limit );
+
        /**
         * Purge any old log entries
-        * 
-        * @return Status 
+        *
+        * @return Status
         */
        final public function purgeOldLogs() {
                return $this->doPurgeOldLogs();
@@ -132,12 +170,22 @@ abstract class FileJournal {
 class NullFileJournal extends FileJournal {
        /**
         * @see FileJournal::logChangeBatch()
-        * @return Status 
+        * @param $entries array
+        * @param $batchId string
+        * @return Status
         */
        protected function doLogChangeBatch( array $entries, $batchId ) {
                return Status::newGood();
        }
 
+       /**
+        * @see FileJournal::doGetChangeEntries()
+        * @return Array
+        */
+       protected function doGetChangeEntries( $start, $limit ) {
+               return array();
+       }
+
        /**
         * @see FileJournal::purgeOldLogs()
         * @return Status