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
|
|
|
use Wikibase\JsonDumpReader\SeekableDumpReader; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @licence GNU GPL v2+ |
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
16
|
|
|
*/ |
17
|
|
|
class GzJsonImportCommand extends ImportCommandBase { |
18
|
|
|
|
19
|
4 |
|
protected function configure() { |
20
|
4 |
|
$this->setName( 'import:gz' ); |
21
|
4 |
|
$this->setDescription( 'Imports entities from a gzip compressed JSON dump' ); |
22
|
|
|
|
23
|
4 |
|
$this->addArgument( |
24
|
4 |
|
'file', |
25
|
4 |
|
InputArgument::REQUIRED, |
26
|
4 |
|
'Full path of the gz JSON dump file' |
27
|
|
|
); |
28
|
|
|
|
29
|
4 |
|
$this->addOption( |
30
|
4 |
|
'continue', |
31
|
4 |
|
'c', |
32
|
4 |
|
InputOption::VALUE_OPTIONAL, |
33
|
4 |
|
'The position to resume import from' |
34
|
|
|
); |
35
|
|
|
|
36
|
4 |
|
$this->addOption( |
37
|
4 |
|
'max', |
38
|
4 |
|
'm', |
39
|
4 |
|
InputOption::VALUE_OPTIONAL, |
40
|
4 |
|
'The maximum number of entities to import' |
41
|
|
|
); |
42
|
4 |
|
} |
43
|
|
|
|
44
|
4 |
|
protected function executeCommand( InputInterface $input, OutputInterface $output ) { |
45
|
4 |
|
$dumpReader = ( new JsonDumpFactory() )->newGzDumpReader( |
46
|
4 |
|
$input->getArgument( 'file' ), |
|
|
|
|
47
|
4 |
|
is_numeric( $input->getOption( 'continue' ) ) ? (int)$input->getOption( 'continue' ) : 0 |
48
|
|
|
); |
49
|
|
|
|
50
|
4 |
|
$importer = new PagesImporterCli( |
51
|
4 |
|
$input, |
52
|
4 |
|
$output, |
53
|
4 |
|
$this->factory, |
|
|
|
|
54
|
4 |
|
function() use ( $output, $dumpReader ) { |
55
|
|
|
$output->writeln( "\n" ); |
56
|
|
|
$output->writeln( "<info>Import process aborted</info>" ); |
57
|
|
|
$output->writeln( "<comment>To resume, run with</comment> --continue=" . $dumpReader->getPosition() ); |
58
|
4 |
|
} |
59
|
|
|
); |
60
|
|
|
|
61
|
4 |
|
$iterator = $this->factory->newJsonEntityPageIterator( $dumpReader ); |
62
|
|
|
|
63
|
4 |
|
if ( is_numeric( $input->getOption( 'max' ) ) ) { |
64
|
2 |
|
$iterator = new \LimitIterator( $iterator, 0, (int)$input->getOption( 'max' ) ); |
65
|
|
|
} |
66
|
|
|
|
67
|
4 |
|
$importer->runImport( $iterator ); |
68
|
|
|
|
69
|
4 |
|
$this->outputMaxContinuation( $input, $output, $dumpReader ); |
70
|
4 |
|
} |
71
|
|
|
|
72
|
4 |
|
private function outputMaxContinuation( InputInterface $input, OutputInterface $output, SeekableDumpReader $reader ) { |
73
|
4 |
|
if ( is_numeric( $input->getOption( 'max' ) ) ) { |
74
|
2 |
|
$output->writeln( |
75
|
2 |
|
"\n<comment>To continue from current position, run with</comment> --continue=" . $reader->getPosition() |
76
|
|
|
); |
77
|
|
|
} |
78
|
4 |
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.