3 require_once __DIR__ .
"/../../../maintenance/dumpTextPass.php";
31 $this->tablesUsed[] =
'page';
32 $this->tablesUsed[] =
'revision';
33 $this->tablesUsed[] =
'ip_changes';
34 $this->tablesUsed[] =
'text';
37 "BackupTextPassTestModel" =>
"BackupTextPassTestModelHandler"
47 "BackupDumperTestP1Text1",
"BackupDumperTestP1Summary1" );
48 $this->pageId1 = $page->getId();
54 "BackupDumperTestP2Text1",
"BackupDumperTestP2Summary1" );
56 "BackupDumperTestP2Text2",
"BackupDumperTestP2Summary2" );
58 "BackupDumperTestP2Text3",
"BackupDumperTestP2Summary3" );
60 "BackupDumperTestP2Text4 some additional Text ",
61 "BackupDumperTestP2Summary4 extra " );
62 $this->pageId2 = $page->getId();
68 "BackupDumperTestP3Text1",
"BackupDumperTestP2Summary1" );
70 "BackupDumperTestP3Text2",
"BackupDumperTestP2Summary2" );
71 $this->pageId3 = $page->getId();
72 $page->doDeleteArticle(
"Testing ;)" );
79 throw new MWException(
"The default wikitext namespace is the talk namespace. "
80 .
" We can't currently deal with that." );
86 "Talk about BackupDumperTestP1 Text1",
87 "Talk BackupDumperTestP1 Summary1",
88 "BackupTextPassTestModel" );
89 $this->pageId4 = $page->getId();
90 }
catch ( Exception
$e ) {
94 $this->exceptionFromAddDBData =
$e;
106 [ $this->pageId2, $this->pageId3, $this->pageId4 ],
107 [ $this->pageId1 + 1, $this->pageId1 + 2, $this->pageId1 + 3 ],
108 "Page ids increasing without holes" );
116 "--output=file:" . $nameFull ] );
117 $dumper->reporting =
false;
118 $dumper->setDB( $this->db );
128 $this->
assertRevision( $this->revId1_1,
"BackupDumperTestP1Summary1",
129 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
130 "BackupDumperTestP1Text1" );
135 $this->
assertRevision( $this->revId2_1,
"BackupDumperTestP2Summary1",
136 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
137 "BackupDumperTestP2Text1" );
138 $this->
assertRevision( $this->revId2_2,
"BackupDumperTestP2Summary2",
139 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
140 "BackupDumperTestP2Text2", $this->revId2_1 );
141 $this->
assertRevision( $this->revId2_3,
"BackupDumperTestP2Summary3",
142 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
143 "BackupDumperTestP2Text3", $this->revId2_2 );
144 $this->
assertRevision( $this->revId2_4,
"BackupDumperTestP2Summary4 extra",
145 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
146 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
154 $this->
assertRevision( $this->revId4_1,
"Talk BackupDumperTestP1 Summary1",
155 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
156 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
158 "BackupTextPassTestModel",
173 $prefetchMock = $this->getMockBuilder(
'BaseDump' )
174 ->setMethods( [
'prefetch' ] )
175 ->disableOriginalConstructor()
177 $prefetchMock->expects( $this->exactly( 6 ) )
178 ->method(
'prefetch' )
179 ->will( $this->returnValueMap( $prefetchMap ) );
186 "--output=file:" . $nameFull ] );
188 $dumper->prefetch = $prefetchMock;
189 $dumper->reporting =
false;
190 $dumper->setDB( $this->db );
202 $this->
assertRevision( $this->revId1_1,
"BackupDumperTestP1Summary1",
203 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
204 "Prefetch_________1Text1" );
209 $this->
assertRevision( $this->revId2_1,
"BackupDumperTestP2Summary1",
210 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
211 "BackupDumperTestP2Text1" );
212 $this->
assertRevision( $this->revId2_2,
"BackupDumperTestP2Summary2",
213 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
214 "BackupDumperTestP2Text2", $this->revId2_1 );
217 $this->
assertRevision( $this->revId2_3,
"BackupDumperTestP2Summary3",
218 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
219 "Prefetch_________2Text3", $this->revId2_2 );
220 $this->
assertRevision( $this->revId2_4,
"BackupDumperTestP2Summary4 extra",
221 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
222 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
230 $this->
assertRevision( $this->revId4_1,
"Talk BackupDumperTestP1 Summary1",
231 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
232 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
234 "BackupTextPassTestModel",
253 $stderr = fopen(
'php://output',
'a' );
254 if ( $stderr ===
false ) {
255 $this->fail(
"Could not open stream for stderr" );
263 $checkpointAfter = 0.5;
268 while ( $lastDuration < $minDuration ) {
272 "Creating temporary output directory " );
273 $this->
setUpStub( $nameStub, $iterations );
275 $dumper->loadWithArgv( [
"--stub=file:" . $nameStub,
276 "--output=" . $checkpointFormat .
":" . $nameOutputDir .
"/full",
278 "--buffersize=32768",
279 "--checkpointfile=checkpoint-%s-%s.xml.gz" ] );
280 $dumper->setDB( $this->db );
281 $dumper->maxTimeAllowed = $checkpointAfter;
282 $dumper->stderr = $stderr;
285 $ts_before = microtime(
true );
287 $ts_after = microtime(
true );
288 $lastDuration = $ts_after - $ts_before;
291 if ( $lastDuration < $minDuration ) {
292 $old_iterations = $iterations;
293 if ( $lastDuration > 0.2 ) {
295 $factor = ( $minDuration + 0.5 ) / $lastDuration;
296 if ( ( $factor > 1.1 ) && ( $factor < 100 ) ) {
298 $iterations = (int)( $iterations * $factor );
302 if ( $old_iterations == $iterations ) {
307 $this->assertLessThan( 50000, $iterations,
308 "Emergency stop against infinitely increasing iteration "
309 .
"count ( last duration: $lastDuration )" );
317 $files = scandir( $nameOutputDir );
318 $this->assertTrue( asort( $files ),
"Sorting files in temporary directory" );
321 $checkpointFiles = 0;
325 for ( $i = 0; $i < $iterations; ) {
328 if ( !$fileOpened ) {
329 $this->assertNotEmpty( $files,
"No more existing dump files, "
330 .
"but not yet all pages found" );
331 $fname = array_shift( $files );
333 $this->assertNotEmpty( $files,
"No more existing dump"
334 .
" files, but not yet all pages found" );
335 $fname = array_shift( $files );
337 if ( $checkpointFormat ==
"gzip" ) {
346 switch ( $lookingForPage ) {
350 "BackupDumperTestP1" );
351 $this->
assertRevision( $this->revId1_1 + $i * self::$numOfRevs,
"BackupDumperTestP1Summary1",
352 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
353 "BackupDumperTestP1Text1" );
362 "BackupDumperTestP2" );
363 $this->
assertRevision( $this->revId2_1 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary1",
364 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
365 "BackupDumperTestP2Text1" );
366 $this->
assertRevision( $this->revId2_2 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary2",
367 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
368 "BackupDumperTestP2Text2", $this->revId2_1 + $i * self::$numOfRevs );
369 $this->
assertRevision( $this->revId2_3 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary3",
370 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
371 "BackupDumperTestP2Text3", $this->revId2_2 + $i * self::$numOfRevs );
373 "BackupDumperTestP2Summary4 extra",
374 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
375 "BackupDumperTestP2Text4 some additional Text",
376 $this->revId2_3 + $i * self::$numOfRevs );
385 "Talk:BackupDumperTestP1" );
387 "Talk BackupDumperTestP1 Summary1",
388 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
389 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
391 "BackupTextPassTestModel",
402 $this->fail(
"Bad setting for lookingForPage ($lookingForPage)" );
406 if ( $this->xml->nodeType == XMLReader::END_ELEMENT
407 && $this->xml->name ==
"mediawiki"
415 $this->assertFalse( $fileOpened,
"Currently read file still open?" );
416 $this->assertEmpty( $files,
"Remaining unchecked files" );
419 $this->assertGreaterThan(
422 "expected more than 1 checkpoint to have been created. "
423 .
"Checkpoint interval is $checkpointAfter seconds, maybe your computer is too fast?"
476 $header =
'<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" '
477 .
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
478 .
'xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ '
479 .
'http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
481 <sitename>wikisvn</sitename>
482 <base>http://localhost/wiki-svn/index.php/Main_Page</base>
483 <generator>MediaWiki 1.21alpha</generator>
484 <case>first-letter</case>
486 <namespace key="-2" case="first-letter">Media</namespace>
487 <namespace key="-1" case="first-letter">Special</namespace>
488 <namespace key="0" case="first-letter" />
489 <namespace key="1" case="first-letter">Talk</namespace>
490 <namespace key="2" case="first-letter">User</namespace>
491 <namespace key="3" case="first-letter">User talk</namespace>
492 <namespace key="4" case="first-letter">Wikisvn</namespace>
493 <namespace key="5" case="first-letter">Wikisvn talk</namespace>
494 <namespace key="6" case="first-letter">File</namespace>
495 <namespace key="7" case="first-letter">File talk</namespace>
496 <namespace key="8" case="first-letter">MediaWiki</namespace>
497 <namespace key="9" case="first-letter">MediaWiki talk</namespace>
498 <namespace key="10" case="first-letter">Template</namespace>
499 <namespace key="11" case="first-letter">Template talk</namespace>
500 <namespace key="12" case="first-letter">Help</namespace>
501 <namespace key="13" case="first-letter">Help talk</namespace>
502 <namespace key="14" case="first-letter">Category</namespace>
503 <namespace key="15" case="first-letter">Category talk</namespace>
507 $tail =
'</mediawiki>
511 $iterations = intval( $iterations );
512 for ( $i = 0; $i < $iterations; $i++ ) {
514 <title>BackupDumperTestP1</title>
518 <id>' . ( $this->revId1_1 + $i * self::$numOfRevs ) .
'</id>
519 <timestamp>2012-04-01T16:46:05Z</timestamp>
523 <comment>BackupDumperTestP1Summary1</comment>
524 <model>wikitext</model>
525 <format>text/x-wiki</format>
526 <text id="' . $this->textId1_1 .
'" bytes="23" />
527 <sha1>0bolhl6ol7i6x0e7yq91gxgaan39j87</sha1>
532 <title>BackupDumperTestP2</title>
536 <id>' . ( $this->revId2_1 + $i * self::$numOfRevs ) .
'</id>
537 <timestamp>2012-04-01T16:46:05Z</timestamp>
541 <comment>BackupDumperTestP2Summary1</comment>
542 <model>wikitext</model>
543 <format>text/x-wiki</format>
544 <text id="' . $this->textId2_1 .
'" bytes="23" />
545 <sha1>jprywrymfhysqllua29tj3sc7z39dl2</sha1>
549 <parentid>' . ( $this->revId2_1 + $i * self::$numOfRevs ) .
'</parentid>
550 <timestamp>2012-04-01T16:46:05Z</timestamp>
554 <comment>BackupDumperTestP2Summary2</comment>
555 <model>wikitext</model>
556 <format>text/x-wiki</format>
557 <text id="' . $this->textId2_2 .
'" bytes="23" />
558 <sha1>b7vj5ks32po5m1z1t1br4o7scdwwy95</sha1>
562 <parentid>' . ( $this->revId2_2 + $i * self::$numOfRevs ) .
'</parentid>
563 <timestamp>2012-04-01T16:46:05Z</timestamp>
567 <comment>BackupDumperTestP2Summary3</comment>
568 <model>wikitext</model>
569 <format>text/x-wiki</format>
570 <text id="' . $this->textId2_3 .
'" bytes="23" />
571 <sha1>jfunqmh1ssfb8rs43r19w98k28gg56r</sha1>
575 <parentid>' . ( $this->revId2_3 + $i * self::$numOfRevs ) .
'</parentid>
576 <timestamp>2012-04-01T16:46:05Z</timestamp>
580 <comment>BackupDumperTestP2Summary4 extra</comment>
581 <model>wikitext</model>
582 <format>text/x-wiki</format>
583 <text id="' . $this->textId2_4 .
'" bytes="44" />
584 <sha1>6o1ciaxa6pybnqprmungwofc4lv00wv</sha1>
591 <title>Talk:BackupDumperTestP1</title>
595 <id>' . ( $this->revId4_1 + $i * self::$numOfRevs ) .
'</id>
596 <timestamp>2012-04-01T16:46:05Z</timestamp>
600 <comment>Talk BackupDumperTestP1 Summary1</comment>
601 <model>BackupTextPassTestModel</model>
602 <format>text/plain</format>
603 <text id="' . $this->textId4_1 .
'" bytes="35" />
604 <sha1>nktofwzd0tl192k3zfepmlzxoax1lpe</sha1>
608 $content .= $page1 . $page2 . $page4;
611 $this->assertEquals( strlen( $content ), file_put_contents(
612 $fname, $content ),
"Length of prepared stub" );
621 parent::__construct(
'BackupTextPassTestModel' );
625 return strtoupper( $text );
647 $dumper->loadWithArgv( [
"--buffersize=" . $size ] );
649 $this->assertEquals( $expected, $dumper->getBufferSize(), $msg );
660 [ 512 * 1024, 512 * 1024,
"Setting 512KB is not effective" ],
661 [ 8192, 8192,
"Setting 8KB is not effective" ],
662 [ 4096, 2048,
"Could set buffer size below lower bound" ]