Exemplo n.º 1
0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @addtogroup SpecialPage
 */
$originalDir = getcwd();
$optionsWithArgs = array('pagelist', 'start', 'end');
require_once 'commandLine.inc';
require_once 'backup.inc';
$dumper = new BackupDumper($argv);
if (isset($options['quiet'])) {
    $dumper->reporting = false;
}
if (isset($options['pagelist'])) {
    $olddir = getcwd();
    chdir($originalDir);
    $pages = file($options['pagelist']);
    chdir($olddir);
    if ($pages === false) {
        wfDie("Unable to open file {$options['pagelist']}\n");
    }
    $pages = array_map('trim', $pages);
    $dumper->pages = array_filter($pages, create_function('$x', 'return $x !== "";'));
}
if (isset($options['start'])) {
 function testXmlDumpsBackupUseCase()
 {
     // xmldumps-backup typically performs a single dump that that writes
     // out three files
     // * gzipped stubs of everything (meta-history)
     // * gzipped stubs of latest revisions of all pages (meta-current)
     // * gzipped stubs of latest revisions of all pages of namespage 0
     //   (articles)
     //
     // We reproduce such a setup with our mini fixture, although we omit
     // chunks, and all the other gimmicks of xmldumps-backup.
     //
     $this->checkHasGzip();
     $fnameMetaHistory = $this->getNewTempFile();
     $fnameMetaCurrent = $this->getNewTempFile();
     $fnameArticles = $this->getNewTempFile();
     $dumper = new BackupDumper(array("--output=gzip:" . $fnameMetaHistory, "--output=gzip:" . $fnameMetaCurrent, "--filter=latest", "--output=gzip:" . $fnameArticles, "--filter=latest", "--filter=notalk", "--filter=namespace:!NS_USER", "--reporting=1000"));
     $dumper->startId = $this->pageId1;
     $dumper->endId = $this->pageId4 + 1;
     $dumper->setDb($this->db);
     // xmldumps-backup uses reporting. We will not check the exact reported
     // message, as they are dependent on the processing power of the used
     // computer. We only check that reporting does not crash the dumping
     // and that something is reported
     $dumper->stderr = fopen('php://output', 'a');
     if ($dumper->stderr === false) {
         $this->fail("Could not open stream for stderr");
     }
     // Performing the dump
     $dumper->dump(WikiExporter::FULL, WikiExporter::STUB);
     $this->assertTrue(fclose($dumper->stderr), "Closing stderr handle");
     // Checking meta-history -------------------------------------------------
     $this->gunzip($fnameMetaHistory);
     $this->assertDumpStart($fnameMetaHistory);
     // Page 1
     $this->assertPageStart($this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText());
     $this->assertRevision($this->revId1_1, "BackupDumperTestP1Summary1", $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87");
     $this->assertPageEnd();
     // Page 2
     $this->assertPageStart($this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText());
     $this->assertRevision($this->revId2_1, "BackupDumperTestP2Summary1", $this->textId2_1, 23, "jprywrymfhysqllua29tj3sc7z39dl2");
     $this->assertRevision($this->revId2_2, "BackupDumperTestP2Summary2", $this->textId2_2, 23, "b7vj5ks32po5m1z1t1br4o7scdwwy95", false, $this->revId2_1);
     $this->assertRevision($this->revId2_3, "BackupDumperTestP2Summary3", $this->textId2_3, 23, "jfunqmh1ssfb8rs43r19w98k28gg56r", false, $this->revId2_2);
     $this->assertRevision($this->revId2_4, "BackupDumperTestP2Summary4 extra", $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3);
     $this->assertPageEnd();
     // Page 3
     // -> Page is marked deleted. Hence not visible
     // Page 4
     $this->assertPageStart($this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText());
     $this->assertRevision($this->revId4_1, "Talk BackupDumperTestP1 Summary1", $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe");
     $this->assertPageEnd();
     $this->assertDumpEnd();
     // Checking meta-current -------------------------------------------------
     $this->gunzip($fnameMetaCurrent);
     $this->assertDumpStart($fnameMetaCurrent);
     // Page 1
     $this->assertPageStart($this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText());
     $this->assertRevision($this->revId1_1, "BackupDumperTestP1Summary1", $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87");
     $this->assertPageEnd();
     // Page 2
     $this->assertPageStart($this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText());
     $this->assertRevision($this->revId2_4, "BackupDumperTestP2Summary4 extra", $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3);
     $this->assertPageEnd();
     // Page 3
     // -> Page is marked deleted. Hence not visible
     // Page 4
     $this->assertPageStart($this->pageId4, $this->talk_namespace, $this->pageTitle4->getPrefixedText());
     $this->assertRevision($this->revId4_1, "Talk BackupDumperTestP1 Summary1", $this->textId4_1, 35, "nktofwzd0tl192k3zfepmlzxoax1lpe");
     $this->assertPageEnd();
     $this->assertDumpEnd();
     // Checking articles -------------------------------------------------
     $this->gunzip($fnameArticles);
     $this->assertDumpStart($fnameArticles);
     // Page 1
     $this->assertPageStart($this->pageId1, $this->namespace, $this->pageTitle1->getPrefixedText());
     $this->assertRevision($this->revId1_1, "BackupDumperTestP1Summary1", $this->textId1_1, 23, "0bolhl6ol7i6x0e7yq91gxgaan39j87");
     $this->assertPageEnd();
     // Page 2
     $this->assertPageStart($this->pageId2, $this->namespace, $this->pageTitle2->getPrefixedText());
     $this->assertRevision($this->revId2_4, "BackupDumperTestP2Summary4 extra", $this->textId2_4, 44, "6o1ciaxa6pybnqprmungwofc4lv00wv", false, $this->revId2_3);
     $this->assertPageEnd();
     // Page 3
     // -> Page is marked deleted. Hence not visible
     // Page 4
     // -> Page is not in $this->namespace. Hence not visible
     $this->assertDumpEnd();
     $this->expectETAOutput();
 }
Exemplo n.º 3
0
 function testXmlDumpsBackupUseCaseLogging()
 {
     global $wgContLang;
     $this->checkHasGzip();
     // Preparing the dump
     $fname = $this->getNewTempFile();
     $dumper = new BackupDumper(array("--output=gzip:" . $fname, "--reporting=2"));
     $dumper->startId = $this->logId1;
     $dumper->endId = $this->logId3 + 1;
     $dumper->setDb($this->db);
     // xmldumps-backup demands reporting, although this is currently not
     // implemented in BackupDumper, when dumping logging data. We
     // nevertheless capture the output of the dump process already now,
     // to be able to alert (once dumping produces reports) that this test
     // needs updates.
     $dumper->stderr = fopen('php://output', 'a');
     if ($dumper->stderr === false) {
         $this->fail("Could not open stream for stderr");
     }
     // Performing the dump
     $dumper->dump(WikiExporter::LOGS, WikiExporter::TEXT);
     $this->assertTrue(fclose($dumper->stderr), "Closing stderr handle");
     // Analyzing the dumped data
     $this->gunzip($fname);
     $this->assertDumpStart($fname);
     $this->assertLogItem($this->logId1, "BackupDumperLogUserA", $this->userId1, null, "type", "subtype", "PageA");
     $this->assertNotNull($wgContLang, "Content language object validation");
     $namespace = $wgContLang->getNsText(NS_TALK);
     $this->assertInternalType('string', $namespace);
     $this->assertGreaterThan(0, strlen($namespace));
     $this->assertLogItem($this->logId2, "BackupDumperLogUserB", $this->userId2, "SomeComment", "supress", "delete", $namespace . ":PageB");
     $this->assertLogItem($this->logId3, "BackupDumperLogUserB", $this->userId2, "SomeOtherComment", "move", "delete", "PageA", array('key1' => 1, 3 => 'value3'));
     $this->assertDumpEnd();
     // Currently, no reporting is implemented. Alert via failure, once
     // this changes.
     // If reporting for log dumps has been implemented, please update
     // the following statement to catch good output
     $this->expectOutputString('');
 }
Exemplo n.º 4
0
 /**
  * Overridden to include prefetch ratio if enabled.
  */
 function showReport()
 {
     if (!$this->prefetch) {
         return parent::showReport();
     }
     if ($this->reporting) {
         $delta = wfTime() - $this->startTime;
         $now = wfTimestamp(TS_DB);
         if ($delta) {
             $rate = $this->pageCount / $delta;
             $revrate = $this->revCount / $delta;
             $portion = $this->revCount / $this->maxCount;
             $eta = $this->startTime + $delta / $portion;
             $etats = wfTimestamp(TS_DB, intval($eta));
             $fetchrate = 100.0 * $this->prefetchCount / $this->fetchCount;
         } else {
             $rate = '-';
             $revrate = '-';
             $etats = '-';
             $fetchrate = '-';
         }
         $this->progress(sprintf("%s: %s %d pages (%0.3f/sec), %d revs (%0.3f/sec), %0.1f%% prefetched, ETA %s [max %d]", $now, wfWikiID(), $this->pageCount, $rate, $this->revCount, $revrate, $fetchrate, $etats, $this->maxCount));
     }
 }
Exemplo n.º 5
0
 function processOptions()
 {
     parent::processOptions();
     // Evaluate options specific to this class
     $this->reporting = !$this->hasOption('quiet');
     if ($this->hasOption('pagelist')) {
         $filename = $this->getOption('pagelist');
         $pages = file($filename);
         if ($pages === false) {
             $this->fatalError("Unable to open file {$filename}\n");
         }
         $pages = array_map('trim', $pages);
         $this->pages = array_filter($pages, function ($x) {
             return $x !== '';
         });
     }
     if ($this->hasOption('start')) {
         $this->startId = intval($this->getOption('start'));
     }
     if ($this->hasOption('end')) {
         $this->endId = intval($this->getOption('end'));
     }
     if ($this->hasOption('revstart')) {
         $this->revStartId = intval($this->getOption('revstart'));
     }
     if ($this->hasOption('revend')) {
         $this->revEndId = intval($this->getOption('revend'));
     }
     $this->skipHeader = $this->hasOption('skip-header');
     $this->skipFooter = $this->hasOption('skip-footer');
     $this->dumpUploads = $this->hasOption('uploads');
     $this->dumpUploadFileContents = $this->hasOption('include-files');
 }
Exemplo n.º 6
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @file
 * @ingroup Dump Maintenance
 */
$originalDir = getcwd();
$optionsWithArgs = array('pagelist', 'start', 'end', 'revstart', 'revend');
require_once __DIR__ . '/commandLine.inc';
require_once __DIR__ . '/backup.inc';
$dumper = new BackupDumper($argv);
if (isset($options['quiet'])) {
    $dumper->reporting = false;
}
if (isset($options['pagelist'])) {
    $olddir = getcwd();
    chdir($originalDir);
    $pages = file($options['pagelist']);
    chdir($olddir);
    if ($pages === false) {
        echo "Unable to open file {$options['pagelist']}\n";
        die(1);
    }
    $pages = array_map('trim', $pages);
    $dumper->pages = array_filter($pages, create_function('$x', 'return $x !== "";'));
}
Exemplo n.º 7
0
 /**
  * Overridden to include prefetch ratio if enabled.
  */
 function showReport()
 {
     if (!$this->prefetch) {
         return parent::showReport();
     }
     if ($this->reporting) {
         $now = wfTimestamp(TS_DB);
         $nowts = wfTime();
         $deltaAll = wfTime() - $this->startTime;
         $deltaPart = wfTime() - $this->lastTime;
         $this->pageCountPart = $this->pageCount - $this->pageCountLast;
         $this->revCountPart = $this->revCount - $this->revCountLast;
         if ($deltaAll) {
             $portion = $this->revCount / $this->maxCount;
             $eta = $this->startTime + $deltaAll / $portion;
             $etats = wfTimestamp(TS_DB, intval($eta));
             if ($this->fetchCount) {
                 $fetchRate = 100.0 * $this->prefetchCount / $this->fetchCount;
             } else {
                 $fetchRate = '-';
             }
             $pageRate = $this->pageCount / $deltaAll;
             $revRate = $this->revCount / $deltaAll;
         } else {
             $pageRate = '-';
             $revRate = '-';
             $etats = '-';
             $fetchRate = '-';
         }
         if ($deltaPart) {
             if ($this->fetchCountLast) {
                 $fetchRatePart = 100.0 * $this->prefetchCountLast / $this->fetchCountLast;
             } else {
                 $fetchRatePart = '-';
             }
             $pageRatePart = $this->pageCountPart / $deltaPart;
             $revRatePart = $this->revCountPart / $deltaPart;
         } else {
             $fetchRatePart = '-';
             $pageRatePart = '-';
             $revRatePart = '-';
         }
         $this->progress(sprintf("%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec all|curr), %d revs (%0.1f|%0.1f/sec all|curr), %0.1f%%|%0.1f%% prefetched (all|curr), ETA %s [max %d]", $now, wfWikiID(), $this->ID, $this->pageCount, $pageRate, $pageRatePart, $this->revCount, $revRate, $revRatePart, $fetchRate, $fetchRatePart, $etats, $this->maxCount));
         $this->lastTime = $nowts;
         $this->revCountLast = $this->revCount;
         $this->prefetchCountLast = $this->prefetchCount;
         $this->fetchCountLast = $this->fetchCount;
     }
 }
 /**
  * Register the filter function with the dump manager
  * @param BackupDumper $dumper
  */
 function register(&$dumper)
 {
     $dumper->registerFilter('abstract', 'AbstractFilter');
     $dumper->registerFilter('noredirect', 'NoredirectFilter');
 }
Exemplo n.º 9
0
 function processOptions()
 {
     parent::processOptions();
     // Evaluate options specific to this class
     $this->reporting = !$this->hasOption('quiet');
     if ($this->hasOption('pagelist')) {
         $olddir = getcwd();
         chdir($originalDir);
         $pages = file($this->getOption('quiet'));
         chdir($olddir);
         if ($pages === false) {
             echo "Unable to open file {$options['pagelist']}\n";
             die(1);
         }
         $pages = array_map('trim', $pages);
         $this->pages = array_filter($pages, create_function('$x', 'return $x !== "";'));
     }
     if ($this->hasOption('start')) {
         $this->startId = intval($this->getOption('start'));
     }
     if ($this->hasOption('end')) {
         $this->endId = intval($this->getOption('end'));
     }
     if ($this->hasOption('revstart')) {
         $this->revStartId = intval($this->getOption('revstart'));
     }
     if ($this->hasOption('revend')) {
         $this->revEndId = intval($this->getOption('revend'));
     }
     $this->skipHeader = $this->hasOption('skip-header');
     $this->skipFooter = $this->hasOption('skip-footer');
     $this->dumpUploads = $this->hasOption('uploads');
     $this->dumpUploadFileContents = $this->hasOption('include-files');
 }
Exemplo n.º 10
0
                $etats = wfTimestamp(TS_DB, intval($eta));
            } else {
                $rate = '-';
                $revrate = '-';
                $etats = '-';
            }
            global $wgDBname;
            $this->progress("{$now}: {$wgDBname} {$this->pageCount}, ETA {$etats} ({$rate} pages/sec {$revrate} revs/sec)");
        }
    }
    function progress($string)
    {
        fwrite($this->stderr, $string . "\n");
    }
}
$dumper = new BackupDumper();
if (isset($options['quiet'])) {
    $dumper->reporting = false;
}
if (isset($options['report'])) {
    $dumper->reportingInterval = IntVal($options['report']);
}
if (isset($options['server'])) {
    $dumper->server = $options['server'];
}
if (isset($options['pagelist'])) {
    $olddir = getcwd();
    chdir($originalDir);
    $pages = file($options['pagelist']);
    chdir($olddir);
    if ($pages === false) {
 /**
  * Register the filter function with the dump manager
  * @param BackupDumper $dumper
  * @static
  */
 function register(&$dumper)
 {
     $dumper->registerFilter('googlecoop', 'GoogleCoopFilter');
     parent::register($dumper);
 }