Merge "mediawiki.special.preferences: Use standard IIFE"
[lhc/web/wiklou.git] / maintenance / purgeChangedPages.php
index e1c6ab6..56e22c4 100644 (file)
@@ -2,7 +2,6 @@
 /**
  * Send purge requests for pages edited in date range to squid/varnish.
  *
- * @section LICENSE
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -41,6 +40,7 @@ class PurgeChangedPages extends Maintenance {
                $this->addOption( 'starttime', 'Starting timestamp', true, true );
                $this->addOption( 'endtime', 'Ending timestamp', true, true );
                $this->addOption( 'htcp-dest', 'HTCP announcement destination (IP:port)', false, true );
+               $this->addOption( 'sleep-per-batch', 'Milliseconds to sleep between batches', false, true );
                $this->addOption( 'dry-run', 'Do not send purge requests' );
                $this->addOption( 'verbose', 'Show more output', false, false, 'v' );
                $this->setBatchSize( 100 );
@@ -135,8 +135,13 @@ class PurgeChangedPages extends Maintenance {
                        }
 
                        // Send batch of purge requests out to squids
-                       $squid = new SquidUpdate( $urls );
+                       $squid = new SquidUpdate( $urls, count( $urls ) );
                        $squid->doUpdate();
+
+                       if ( $this->hasOption( 'sleep-per-batch' ) ) {
+                               // sleep-per-batch is milliseconds, usleep wants micro seconds.
+                               usleep( 1000 * (int)$this->getOption( 'sleep-per-batch' ) );
+                       }
                }
 
                $this->output( "Done!\n" );
@@ -154,10 +159,11 @@ class PurgeChangedPages extends Maintenance {
         * If this returns an empty array for a non-empty query result, then all the rows
         * had the same column value and the query should be repeated with a higher LIMIT.
         *
-        * @TODO: move this elsewhere
+        * @todo move this elsewhere
         *
         * @param ResultWrapper $res Query result sorted by $column (ascending)
         * @param string $column
+        * @param int $limit
         * @return array (array of rows, string column value)
         */
        protected function pageableSortedRows( ResultWrapper $res, $column, $limit ) {
@@ -177,6 +183,7 @@ class PurgeChangedPages extends Maintenance {
                        }
                }
                $lastValueLeft = count( $rows ) ? $rows[count( $rows ) - 1]->$column : null;
+
                return array( $rows, $lastValueLeft );
        }
 }