3 require_once __DIR__ .
"/../../../maintenance/dumpTextPass.php";
31 $this->tablesUsed[] =
'page';
32 $this->tablesUsed[] =
'revision';
33 $this->tablesUsed[] =
'text';
36 "BackupTextPassTestModel" =>
"BackupTextPassTestModelHandler"
46 "BackupDumperTestP1Text1",
"BackupDumperTestP1Summary1" );
47 $this->pageId1 =
$page->getId();
53 "BackupDumperTestP2Text1",
"BackupDumperTestP2Summary1" );
55 "BackupDumperTestP2Text2",
"BackupDumperTestP2Summary2" );
57 "BackupDumperTestP2Text3",
"BackupDumperTestP2Summary3" );
59 "BackupDumperTestP2Text4 some additional Text ",
60 "BackupDumperTestP2Summary4 extra " );
61 $this->pageId2 =
$page->getId();
67 "BackupDumperTestP3Text1",
"BackupDumperTestP2Summary1" );
69 "BackupDumperTestP3Text2",
"BackupDumperTestP2Summary2" );
70 $this->pageId3 =
$page->getId();
71 $page->doDeleteArticle(
"Testing ;)" );
78 throw new MWException(
"The default wikitext namespace is the talk namespace. "
79 .
" We can't currently deal with that." );
85 "Talk about BackupDumperTestP1 Text1",
86 "Talk BackupDumperTestP1 Summary1",
87 "BackupTextPassTestModel" );
88 $this->pageId4 =
$page->getId();
89 }
catch ( Exception
$e ) {
93 $this->exceptionFromAddDBData =
$e;
105 [ $this->pageId2, $this->pageId3, $this->pageId4 ],
106 [ $this->pageId1 + 1, $this->pageId2 + 1, $this->pageId3 + 1 ],
107 "Page ids increasing without holes" );
115 "--output=file:" . $nameFull ] );
116 $dumper->reporting =
false;
117 $dumper->setDB( $this->db );
127 $this->
assertRevision( $this->revId1_1,
"BackupDumperTestP1Summary1",
128 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
129 "BackupDumperTestP1Text1" );
134 $this->
assertRevision( $this->revId2_1,
"BackupDumperTestP2Summary1",
135 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
136 "BackupDumperTestP2Text1" );
137 $this->
assertRevision( $this->revId2_2,
"BackupDumperTestP2Summary2",
138 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
139 "BackupDumperTestP2Text2", $this->revId2_1 );
140 $this->
assertRevision( $this->revId2_3,
"BackupDumperTestP2Summary3",
141 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
142 "BackupDumperTestP2Text3", $this->revId2_2 );
143 $this->
assertRevision( $this->revId2_4,
"BackupDumperTestP2Summary4 extra",
144 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
145 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
153 $this->
assertRevision( $this->revId4_1,
"Talk BackupDumperTestP1 Summary1",
154 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
155 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
157 "BackupTextPassTestModel",
172 $prefetchMock = $this->getMockBuilder(
'BaseDump' )
173 ->setMethods( [
'prefetch' ] )
174 ->disableOriginalConstructor()
176 $prefetchMock->expects( $this->exactly( 6 ) )
177 ->method(
'prefetch' )
178 ->will( $this->returnValueMap( $prefetchMap ) );
185 "--output=file:" . $nameFull ] );
187 $dumper->prefetch = $prefetchMock;
188 $dumper->reporting =
false;
189 $dumper->setDB( $this->db );
201 $this->
assertRevision( $this->revId1_1,
"BackupDumperTestP1Summary1",
202 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
203 "Prefetch_________1Text1" );
208 $this->
assertRevision( $this->revId2_1,
"BackupDumperTestP2Summary1",
209 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
210 "BackupDumperTestP2Text1" );
211 $this->
assertRevision( $this->revId2_2,
"BackupDumperTestP2Summary2",
212 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
213 "BackupDumperTestP2Text2", $this->revId2_1 );
216 $this->
assertRevision( $this->revId2_3,
"BackupDumperTestP2Summary3",
217 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
218 "Prefetch_________2Text3", $this->revId2_2 );
219 $this->
assertRevision( $this->revId2_4,
"BackupDumperTestP2Summary4 extra",
220 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
221 "BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
229 $this->
assertRevision( $this->revId4_1,
"Talk BackupDumperTestP1 Summary1",
230 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
231 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
233 "BackupTextPassTestModel",
252 $stderr = fopen(
'php://output',
'a' );
253 if ( $stderr ===
false ) {
254 $this->fail(
"Could not open stream for stderr" );
262 $checkpointAfter = 0.5;
267 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; ) {
329 if ( !$fileOpened ) {
330 $this->assertNotEmpty( $files,
"No more existing dump files, "
331 .
"but not yet all pages found" );
332 $fname = array_shift( $files );
334 $this->assertNotEmpty( $files,
"No more existing dump"
335 .
" files, but not yet all pages found" );
336 $fname = array_shift( $files );
338 if ( $checkpointFormat ==
"gzip" ) {
347 switch ( $lookingForPage ) {
351 "BackupDumperTestP1" );
352 $this->
assertRevision( $this->revId1_1 + $i * self::$numOfRevs,
"BackupDumperTestP1Summary1",
353 $this->textId1_1,
false,
"0bolhl6ol7i6x0e7yq91gxgaan39j87",
354 "BackupDumperTestP1Text1" );
363 "BackupDumperTestP2" );
364 $this->
assertRevision( $this->revId2_1 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary1",
365 $this->textId2_1,
false,
"jprywrymfhysqllua29tj3sc7z39dl2",
366 "BackupDumperTestP2Text1" );
367 $this->
assertRevision( $this->revId2_2 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary2",
368 $this->textId2_2,
false,
"b7vj5ks32po5m1z1t1br4o7scdwwy95",
369 "BackupDumperTestP2Text2", $this->revId2_1 + $i * self::$numOfRevs );
370 $this->
assertRevision( $this->revId2_3 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary3",
371 $this->textId2_3,
false,
"jfunqmh1ssfb8rs43r19w98k28gg56r",
372 "BackupDumperTestP2Text3", $this->revId2_2 + $i * self::$numOfRevs );
374 "BackupDumperTestP2Summary4 extra",
375 $this->textId2_4,
false,
"6o1ciaxa6pybnqprmungwofc4lv00wv",
376 "BackupDumperTestP2Text4 some additional Text",
377 $this->revId2_3 + $i * self::$numOfRevs );
386 "Talk:BackupDumperTestP1" );
388 "Talk BackupDumperTestP1 Summary1",
389 $this->textId4_1,
false,
"nktofwzd0tl192k3zfepmlzxoax1lpe",
390 "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
392 "BackupTextPassTestModel",
403 $this->fail(
"Bad setting for lookingForPage ($lookingForPage)" );
407 if ( $this->xml->nodeType == XMLReader::END_ELEMENT
408 && $this->xml->name ==
"mediawiki"
416 $this->assertFalse( $fileOpened,
"Currently read file still open?" );
417 $this->assertEmpty( $files,
"Remaining unchecked files" );
420 $this->assertGreaterThan(
423 "expected more than 1 checkpoint to have been created. "
424 .
"Checkpoint interval is $checkpointAfter seconds, maybe your computer is too fast?"
477 $header =
'<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" '
478 .
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
479 .
'xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ '
480 .
'http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
482 <sitename>wikisvn</sitename>
483 <base>http://localhost/wiki-svn/index.php/Main_Page</base>
484 <generator>MediaWiki 1.21alpha</generator>
485 <case>first-letter</case>
487 <namespace key="-2" case="first-letter">Media</namespace>
488 <namespace key="-1" case="first-letter">Special</namespace>
489 <namespace key="0" case="first-letter" />
490 <namespace key="1" case="first-letter">Talk</namespace>
491 <namespace key="2" case="first-letter">User</namespace>
492 <namespace key="3" case="first-letter">User talk</namespace>
493 <namespace key="4" case="first-letter">Wikisvn</namespace>
494 <namespace key="5" case="first-letter">Wikisvn talk</namespace>
495 <namespace key="6" case="first-letter">File</namespace>
496 <namespace key="7" case="first-letter">File talk</namespace>
497 <namespace key="8" case="first-letter">MediaWiki</namespace>
498 <namespace key="9" case="first-letter">MediaWiki talk</namespace>
499 <namespace key="10" case="first-letter">Template</namespace>
500 <namespace key="11" case="first-letter">Template talk</namespace>
501 <namespace key="12" case="first-letter">Help</namespace>
502 <namespace key="13" case="first-letter">Help talk</namespace>
503 <namespace key="14" case="first-letter">Category</namespace>
504 <namespace key="15" case="first-letter">Category talk</namespace>
508 $tail =
'</mediawiki>
512 $iterations = intval( $iterations );
513 for ( $i = 0; $i < $iterations; $i++ ) {
516 <title>BackupDumperTestP1</title>
520 <id>' . ( $this->revId1_1 + $i * self::$numOfRevs ) .
'</id>
521 <timestamp>2012-04-01T16:46:05Z</timestamp>
525 <comment>BackupDumperTestP1Summary1</comment>
526 <model>wikitext</model>
527 <format>text/x-wiki</format>
528 <text id="' . $this->textId1_1 .
'" bytes="23" />
529 <sha1>0bolhl6ol7i6x0e7yq91gxgaan39j87</sha1>
534 <title>BackupDumperTestP2</title>
538 <id>' . ( $this->revId2_1 + $i * self::$numOfRevs ) .
'</id>
539 <timestamp>2012-04-01T16:46:05Z</timestamp>
543 <comment>BackupDumperTestP2Summary1</comment>
544 <model>wikitext</model>
545 <format>text/x-wiki</format>
546 <text id="' . $this->textId2_1 .
'" bytes="23" />
547 <sha1>jprywrymfhysqllua29tj3sc7z39dl2</sha1>
551 <parentid>' . ( $this->revId2_1 + $i * self::$numOfRevs ) .
'</parentid>
552 <timestamp>2012-04-01T16:46:05Z</timestamp>
556 <comment>BackupDumperTestP2Summary2</comment>
557 <model>wikitext</model>
558 <format>text/x-wiki</format>
559 <text id="' . $this->textId2_2 .
'" bytes="23" />
560 <sha1>b7vj5ks32po5m1z1t1br4o7scdwwy95</sha1>
564 <parentid>' . ( $this->revId2_2 + $i * self::$numOfRevs ) .
'</parentid>
565 <timestamp>2012-04-01T16:46:05Z</timestamp>
569 <comment>BackupDumperTestP2Summary3</comment>
570 <model>wikitext</model>
571 <format>text/x-wiki</format>
572 <text id="' . $this->textId2_3 .
'" bytes="23" />
573 <sha1>jfunqmh1ssfb8rs43r19w98k28gg56r</sha1>
577 <parentid>' . ( $this->revId2_3 + $i * self::$numOfRevs ) .
'</parentid>
578 <timestamp>2012-04-01T16:46:05Z</timestamp>
582 <comment>BackupDumperTestP2Summary4 extra</comment>
583 <model>wikitext</model>
584 <format>text/x-wiki</format>
585 <text id="' . $this->textId2_4 .
'" bytes="44" />
586 <sha1>6o1ciaxa6pybnqprmungwofc4lv00wv</sha1>
593 <title>Talk:BackupDumperTestP1</title>
597 <id>' . ( $this->revId4_1 + $i * self::$numOfRevs ) .
'</id>
598 <timestamp>2012-04-01T16:46:05Z</timestamp>
602 <comment>Talk BackupDumperTestP1 Summary1</comment>
603 <model>BackupTextPassTestModel</model>
604 <format>text/plain</format>
605 <text id="' . $this->textId4_1 .
'" bytes="35" />
606 <sha1>nktofwzd0tl192k3zfepmlzxoax1lpe</sha1>
610 $content .= $page1 . $page2 . $page4;
613 $this->assertEquals( strlen(
$content ), file_put_contents(
623 parent::__construct(
'BackupTextPassTestModel' );
627 return strtoupper( $text );
649 $dumper->loadWithArgv( [
"--buffersize=" . $size ] );
651 $this->assertEquals( $expected, $dumper->getBufferSize(), $msg );
662 [ 512 * 1024, 512 * 1024,
"Setting 512KB is not effective" ],
663 [ 8192, 8192,
"Setting 8KB is not effective" ],
664 [ 4096, 2048,
"Could set buffer size below lower bound" ]