SDImportApi   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 89
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 35 5
A getAllowedParams() 0 36 1
A getDescription() 0 5 1
A getParamDescription() 0 5 1
A getVersion() 0 3 1
1
<?php
2
class SDImportApi extends ApiBase {
3
4
	public function execute() {
5
6
		$params = $this->extractRequestParams();
7
8
		$jsonmodel = false;
9
		
10
		if ( array_key_exists( "model", $params ) ) {
11
		
12
			if ( $params["model"] === "json" ) {
13
				$jsonmodel = true;
14
			}
15
					
16
		}
17
18
		//wfDebugLog( "sdimport", json_encode( $params ) );
19
20
		if ( $jsonmodel ) {
21
			//wfDebugLog( "sdimport", "Batch: ".$params['model'] );
22
			if ( $params["batch"] === true ) {
23
				$status = SDImportData::importJSONBatch( $params['text'], $params['title'], $params['overwrite'] );
24
			}
25
			else {
26
				// wfDebugLog( "sdimport", "Hereeeee" );
27
				$status = SDImportData::importJSON( $params['text'], $params['title'], $params['overwrite'] );
28
			}
29
		}
30
		else {
31
			$status = SDImportData::importWikiText( $params['text'], $params['title'], $params['separator'], $params['delimiter'], $params['num'] );
32
		}
33
		
34
		$this->getResult()->addValue( null, $this->getModuleName(), array ( 'status' => $status ) );
35
36
		return true;
37
38
	}
39
	public function getAllowedParams() {
40
		return array(
41
			'text' => array(
42
				ApiBase::PARAM_TYPE => 'string',
43
				ApiBase::PARAM_REQUIRED => true
44
			),
45
			'title' => array(
46
				ApiBase::PARAM_TYPE => 'string',
47
				ApiBase::PARAM_REQUIRED => false
48
			),
49
			'separator' => array(
50
				ApiBase::PARAM_TYPE => 'string',
51
				ApiBase::PARAM_REQUIRED => false
52
			),
53
			'delimiter' => array(
54
				ApiBase::PARAM_TYPE => 'string',
55
				ApiBase::PARAM_REQUIRED => false
56
			),
57
			'num' => array(
58
				ApiBase::PARAM_TYPE => 'integer',
59
				ApiBase::PARAM_REQUIRED => false
60
			),
61
			'model' => array(
62
				ApiBase::PARAM_TYPE => 'string',
63
				ApiBase::PARAM_REQUIRED => false
64
			),
65
			'overwrite' => array(
66
				ApiBase::PARAM_TYPE => 'boolean',
67
				ApiBase::PARAM_REQUIRED => false
68
			),
69
			'batch' => array(
70
				ApiBase::PARAM_TYPE => 'boolean',
71
				ApiBase::PARAM_REQUIRED => false
72
			)
73
		);
74
	}
75
76
	public function getDescription() {
77
		return array(
78
			'API for importing data into smwdata page'
79
		);
80
	}
81
	public function getParamDescription() {
82
		return array(
83
			'text' => 'Content to be processed'
84
		);
85
	}
86
87
	public function getVersion() {
88
		return __CLASS__ . ': 1.1';
89
	}
90
}
91