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
|
|
|
protected function configure() { |
19
|
|
|
$this->setName( 'import:bz2' ); |
20
|
|
|
$this->setDescription( 'Imports entities from a bzip2 compressed JSON dump' ); |
21
|
|
|
|
22
|
|
|
$this->addArgument( |
23
|
|
|
'file', |
24
|
|
|
InputArgument::REQUIRED, |
25
|
|
|
'Full path of the bz2 JSON dump file' |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
$this->addOption( |
29
|
|
|
'max', |
30
|
|
|
'm', |
31
|
|
|
InputOption::VALUE_OPTIONAL, |
32
|
|
|
'The maximum number of entities to import' |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function executeCommand( InputInterface $input, OutputInterface $output ) { |
37
|
|
|
$importer = new PagesImporterCli( |
38
|
|
|
$input, |
39
|
|
|
$output, |
40
|
|
|
$this->factory, |
|
|
|
|
41
|
|
|
function() use ( $output ) { |
42
|
|
|
$output->writeln( "\n" ); |
43
|
|
|
$output->writeln( "<info>Import process aborted</info>" ); |
44
|
|
|
} |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$dumpReader = ( new JsonDumpFactory() )->newBz2DumpReader( $input->getArgument( 'file' ) ); |
48
|
|
|
$iterator = $this->factory->newJsonEntityPageIterator( $dumpReader ); |
49
|
|
|
|
50
|
|
|
if ( is_numeric( $input->getOption( 'max' ) ) ) { |
51
|
|
|
$iterator = new \LimitIterator( $iterator, 0, (int)$input->getOption( 'max' ) ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$importer->runImport( $iterator ); |
55
|
|
|
} |
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: