Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ChunkBuilder | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
132 | |
0.00% |
0 / 1 |
build | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
132 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Maintenance; |
4 | |
5 | /** |
6 | * Splits maintenance scripts into chunks and prints out the commands to run |
7 | * the chunks. |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License along |
20 | * with this program; if not, write to the Free Software Foundation, Inc., |
21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
22 | * http://www.gnu.org/copyleft/gpl.html |
23 | */ |
24 | class ChunkBuilder { |
25 | /** |
26 | * @param string $self Name of maintenance script |
27 | * @param array $options |
28 | * @param string|int $buildChunks If specified as a number then chunks no |
29 | * larger than that size are spat out. If specified as a number followed |
30 | * by the word "total" without a space between them then that many chunks |
31 | * will be spat out sized to cover the entire wiki. |
32 | * @param int $fromPageId |
33 | * @param int $toPageId |
34 | */ |
35 | public function build( $self, array $options, $buildChunks, $fromPageId, $toPageId ) { |
36 | $fixedChunkSize = strpos( $buildChunks, 'total' ) === false; |
37 | $buildChunks = intval( $buildChunks ); |
38 | if ( $fixedChunkSize ) { |
39 | $chunkSize = $buildChunks; |
40 | } else { |
41 | $chunkSize = max( 1, ceil( ( $toPageId - $fromPageId ) / $buildChunks ) ); |
42 | } |
43 | for ( $pageId = $fromPageId; $pageId < $toPageId; $pageId += $chunkSize ) { |
44 | $chunkToId = min( $toPageId, $pageId + $chunkSize ); |
45 | print "php $self"; |
46 | foreach ( $options as $optName => $optVal ) { |
47 | if ( $optVal === null || $optVal === false || $optName === 'fromId' || |
48 | $optName === 'toId' || $optName === 'buildChunks' || |
49 | ( $optName === 'memory-limit' && $optVal === 'max' ) |
50 | ) { |
51 | continue; |
52 | } |
53 | print " --$optName $optVal"; |
54 | } |
55 | print " --fromId $pageId --toId $chunkToId\n"; |
56 | } |
57 | } |
58 | } |