ImportIncrementalXmlDumpCommand::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3.009

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 23
ccs 18
cts 20
cp 0.9
rs 9.0856
cc 3
eloc 16
nc 3
nop 2
crap 3.009
1
<?php
2
3
namespace Wikibase\EntityStore\Console;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Logger\ConsoleLogger;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Wikibase\DataModel\Deserializers\EntityIdDeserializer;
11
use Wikibase\DataModel\Entity\BasicEntityIdParser;
12
use Wikibase\EntityStore\Config\EntityStoreFromConfigurationBuilder;
13
use Wikibase\EntityStore\DataModel\Deserializers\SerializedEntityDeserializer;
14
use Wikibase\EntityStore\Internal\IncrementalXmlDumpReader;
15
16
/**
17
 * @licence GPLv2+
18
 * @author Thomas Pellissier Tanon
19
 */
20
class ImportIncrementalXmlDumpCommand extends Command {
21
22 1
	protected function configure() {
23 1
		$this->setName( 'import-incremental-xml-dump' )
24 1
			->setDescription( 'Import an incremental XML dump of Wikidata in an entity store' )
25 1
			->addArgument( 'file', InputArgument::REQUIRED, 'incremental XML dump file' )
26 1
			->addArgument( 'configuration', InputArgument::REQUIRED, 'Configuration file' );
27 1
	}
28
29 1
	protected function execute( InputInterface $input, OutputInterface $output ) {
30 1
		$configurationBuilder = new EntityStoreFromConfigurationBuilder();
31 1
		$store = $configurationBuilder->buildEntityStore( $input->getArgument( 'configuration' ) );
32
33 1
		$output->writeln( 'Import data.' );
34 1
		$entitySaver = $store->getEntityDocumentSaver();
35
36 1
		$dumpReader = new IncrementalXmlDumpReader(
37 1
			$input->getArgument( 'file' ),
38 1
			new SerializedEntityDeserializer( new EntityIdDeserializer( new BasicEntityIdParser() ) ),
39 1
			new ConsoleLogger( $output )
40 1
		);
41 1
		$count = 0;
42 1
		foreach( $dumpReader as $entity ) {
43 1
			$entitySaver->saveEntityDocument( $entity );
44 1
			$count++;
45
46 1
			if($count % 1000 === 0 ) {
47
				$output->write( '.' );
48
			}
49 1
		}
50 1
		$output->writeln( 'Importation done.' );
51 1
	}
52
}
53