|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Queryr\Replicator\Cli\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Queryr\Replicator\Cli\Import\PagesImporterCli; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
use Wikibase\JsonDumpReader\JsonDumpFactory; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @licence GNU GPL v2+ |
|
14
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
15
|
|
|
*/ |
|
16
|
|
|
class Bz2JsonImportCommand extends ImportCommandBase { |
|
17
|
|
|
|
|
18
|
2 |
|
protected function configure() { |
|
19
|
2 |
|
$this->setName( 'import:bz2' ); |
|
20
|
2 |
|
$this->setDescription( 'Imports entities from a bzip2 compressed JSON dump' ); |
|
21
|
|
|
|
|
22
|
2 |
|
$this->addArgument( |
|
23
|
2 |
|
'file', |
|
24
|
2 |
|
InputArgument::REQUIRED, |
|
25
|
2 |
|
'Full path of the bz2 JSON dump file' |
|
26
|
|
|
); |
|
27
|
|
|
|
|
28
|
2 |
|
$this->addOption( |
|
29
|
2 |
|
'max', |
|
30
|
2 |
|
'm', |
|
31
|
2 |
|
InputOption::VALUE_OPTIONAL, |
|
32
|
2 |
|
'The maximum number of entities to import' |
|
33
|
|
|
); |
|
34
|
2 |
|
} |
|
35
|
|
|
|
|
36
|
2 |
|
protected function executeCommand( InputInterface $input, OutputInterface $output ) { |
|
37
|
2 |
|
$importer = new PagesImporterCli( |
|
38
|
2 |
|
$input, |
|
39
|
2 |
|
$output, |
|
40
|
2 |
|
$this->factory, |
|
|
|
|
|
|
41
|
2 |
|
function() use ( $output ) { |
|
42
|
|
|
$output->writeln( "\n" ); |
|
43
|
|
|
$output->writeln( "<info>Import process aborted</info>" ); |
|
44
|
2 |
|
} |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
2 |
|
$dumpReader = ( new JsonDumpFactory() )->newBz2DumpReader( $input->getArgument( 'file' ) ); |
|
48
|
2 |
|
$iterator = $this->factory->newJsonEntityPageIterator( $dumpReader ); |
|
49
|
|
|
|
|
50
|
2 |
|
if ( is_numeric( $input->getOption( 'max' ) ) ) { |
|
51
|
1 |
|
$iterator = new \LimitIterator( $iterator, 0, (int)$input->getOption( 'max' ) ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
2 |
|
$importer->runImport( $iterator ); |
|
55
|
2 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: