diff options
author | Mehmet Mert Yıldıran <mehmetmertyildiran@gmail.com> | 2017-05-26 04:54:32 +0300 |
---|---|---|
committer | Mehmet Mert Yıldıran <mehmetmertyildiran@gmail.com> | 2017-06-09 01:01:05 +0300 |
commit | 4951c2b54f429037038cca617eb3e5860c1c271f (patch) | |
tree | 56fb43573c2160a03efdce51266752c93eee6a0d /includes/import/WikiImporter.php | |
parent | f0e12ae951ef9f6cb359c5ecfcd3739e38f4d29a (diff) | |
download | mediawikicore-4951c2b54f429037038cca617eb3e5860c1c271f.tar.gz mediawikicore-4951c2b54f429037038cca617eb3e5860c1c271f.zip |
Add skipping to nth page option/ability for dump importing process
Usage: php importDump.php --skip-to 271500 /path_to/dumpfile.xml.gz
When importing a database dump and the import process crashes
(for random reasons) after a certain number of pages, the
"--skip-to" parameter allows restarting the import process at
a certain page instead of starting the import from scratch.
Change-Id: Ib36063b69d6846fc197800bba44287493b0632c0
Diffstat (limited to 'includes/import/WikiImporter.php')
-rw-r--r-- | includes/import/WikiImporter.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/includes/import/WikiImporter.php b/includes/import/WikiImporter.php index 06b579a7d9f7..2fc9f5e52740 100644 --- a/includes/import/WikiImporter.php +++ b/includes/import/WikiImporter.php @@ -39,6 +39,7 @@ class WikiImporter { private $mNoticeCallback, $mDebug; private $mImportUploads, $mImageBasePath; private $mNoUpdates = false; + private $pageOffset = 0; /** @var Config */ private $config; /** @var ImportTitleFactory */ @@ -147,6 +148,16 @@ class WikiImporter { } /** + * Sets 'pageOffset' value. So it will skip the first n-1 pages + * and start from the nth page. It's 1-based indexing. + * @param int $nthPage + * @since 1.29 + */ + function setPageOffset( $nthPage ) { + $this->pageOffset = $nthPage; + } + + /** * Set a callback that displays notice messages * * @param callable $callback @@ -562,9 +573,19 @@ class WikiImporter { $keepReading = $this->reader->read(); $skip = false; $rethrow = null; + $pageCount = 0; try { while ( $keepReading ) { $tag = $this->reader->localName; + if ( $this->pageOffset ) { + if ( $tag === 'page' ) { + $pageCount++; + } + if ( $pageCount < $this->pageOffset ) { + $keepReading = $this->reader->next(); + continue; + } + } $type = $this->reader->nodeType; if ( !Hooks::run( 'ImportHandleToplevelXMLTag', [ $this ] ) ) { |