@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( function_exists( 'wfLoadExtension' ) ) { |
|
4 | - wfLoadExtension( 'WikibaseQualityConstraints', __DIR__ . '/extension.json' ); |
|
3 | +if (function_exists('wfLoadExtension')) { |
|
4 | + wfLoadExtension('WikibaseQualityConstraints', __DIR__.'/extension.json'); |
|
5 | 5 | // Keep i18n globals so mergeMessageFileList.php doesn't break |
6 | - $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__ . '/i18n'; |
|
7 | - $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__ . '/WikibaseQualityConstraints.alias.php'; |
|
6 | + $wgMessagesDirs['WikibaseQualityConstraints'] = __DIR__.'/i18n'; |
|
7 | + $wgExtensionMessagesFiles['WikibaseQualityConstraintsAlias'] = __DIR__.'/WikibaseQualityConstraints.alias.php'; |
|
8 | 8 | /* wfWarn( |
9 | 9 | 'Deprecated PHP entry point used for WikibaseQualityConstraints extension. ' . |
10 | 10 | 'Please use wfLoadExtension instead, ' . |
@@ -12,5 +12,5 @@ discard block |
||
12 | 12 | ); */ |
13 | 13 | return; |
14 | 14 | } else { |
15 | - die( 'This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+' ); |
|
15 | + die('This version of the WikibaseQualityConstraints extension requires MediaWiki 1.25+'); |
|
16 | 16 | } |
@@ -10,5 +10,5 @@ |
||
10 | 10 | |
11 | 11 | /** English (English) */ |
12 | 12 | $specialPageAliases['en'] = [ |
13 | - 'ConstraintReport' => [ 'ConstraintReport', 'Constraint Report' ], |
|
13 | + 'ConstraintReport' => ['ConstraintReport', 'Constraint Report'], |
|
14 | 14 | ]; |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | use WikibaseQuality\ConstraintReport\UpdateConstraintsTableJob; |
9 | 9 | use Wikibase\Repo\WikibaseRepo; |
10 | 10 | |
11 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
12 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
11 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
12 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
13 | 13 | |
14 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
14 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Runs {@link UpdateConstraintsTableJob} once for every property. |
@@ -23,23 +23,23 @@ discard block |
||
23 | 23 | public function __construct() { |
24 | 24 | parent::__construct(); |
25 | 25 | |
26 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
26 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function execute() { |
30 | - if ( !MediaWikiServices::getInstance()->getMainConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
31 | - $this->error( 'Constraint statements are not enabled. Aborting.', 1 ); |
|
30 | + if (!MediaWikiServices::getInstance()->getMainConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
31 | + $this->error('Constraint statements are not enabled. Aborting.', 1); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $propertyInfoLookup = WikibaseRepo::getDefaultInstance()->getStore()->getPropertyInfoLookup(); |
35 | - foreach ( $propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info ) { |
|
36 | - $this->output( sprintf( 'Importing constraint statements for % 6s... ', $propertyIdSerialization ), $propertyIdSerialization ); |
|
37 | - $startTime = microtime( true ); |
|
38 | - $job = UpdateConstraintsTableJob::newFromGlobalState( Title::newMainPage(), [ 'propertyId' => $propertyIdSerialization ] ); |
|
35 | + foreach ($propertyInfoLookup->getAllPropertyInfo() as $propertyIdSerialization => $info) { |
|
36 | + $this->output(sprintf('Importing constraint statements for % 6s... ', $propertyIdSerialization), $propertyIdSerialization); |
|
37 | + $startTime = microtime(true); |
|
38 | + $job = UpdateConstraintsTableJob::newFromGlobalState(Title::newMainPage(), ['propertyId' => $propertyIdSerialization]); |
|
39 | 39 | $job->run(); |
40 | - $endTime = microtime( true ); |
|
41 | - $millis = ( $endTime - $startTime ) * 1000; |
|
42 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
40 | + $endTime = microtime(true); |
|
41 | + $millis = ($endTime - $startTime) * 1000; |
|
42 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 |
@@ -14,6 +14,6 @@ |
||
14 | 14 | * |
15 | 15 | * @return Constraint[] |
16 | 16 | */ |
17 | - public function queryConstraintsForProperty( PropertyId $propertyId ); |
|
17 | + public function queryConstraintsForProperty(PropertyId $propertyId); |
|
18 | 18 | |
19 | 19 | } |
@@ -20,23 +20,23 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return Constraint[] |
22 | 22 | */ |
23 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
24 | - $db = wfGetDB( DB_REPLICA ); |
|
23 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
24 | + $db = wfGetDB(DB_REPLICA); |
|
25 | 25 | |
26 | 26 | $results = $db->select( |
27 | 27 | 'wbqc_constraints', |
28 | 28 | '*', |
29 | - [ 'pid' => $propertyId->getNumericId() ] |
|
29 | + ['pid' => $propertyId->getNumericId()] |
|
30 | 30 | ); |
31 | 31 | |
32 | - return $this->convertToConstraints( $results ); |
|
32 | + return $this->convertToConstraints($results); |
|
33 | 33 | } |
34 | 34 | |
35 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
36 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
35 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
36 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
37 | 37 | |
38 | - if ( strlen( $json ) > 50000 ) { |
|
39 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
38 | + if (strlen($json) > 50000) { |
|
39 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | return $json; |
@@ -48,21 +48,21 @@ discard block |
||
48 | 48 | * @throws DBUnexpectedError |
49 | 49 | * @return bool |
50 | 50 | */ |
51 | - public function insertBatch( array $constraints ) { |
|
51 | + public function insertBatch(array $constraints) { |
|
52 | 52 | $accumulator = array_map( |
53 | - function ( Constraint $constraint ) { |
|
53 | + function(Constraint $constraint) { |
|
54 | 54 | return [ |
55 | 55 | 'constraint_guid' => $constraint->getConstraintId(), |
56 | 56 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
57 | 57 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
58 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
58 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
59 | 59 | ]; |
60 | 60 | }, |
61 | 61 | $constraints |
62 | 62 | ); |
63 | 63 | |
64 | - $db = wfGetDB( DB_MASTER ); |
|
65 | - return $db->insert( 'wbqc_constraints', $accumulator ); |
|
64 | + $db = wfGetDB(DB_MASTER); |
|
65 | + return $db->insert('wbqc_constraints', $accumulator); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return array |
72 | 72 | */ |
73 | - private function uuidPattern( LikeMatch $any ) { |
|
73 | + private function uuidPattern(LikeMatch $any) { |
|
74 | 74 | return array_merge( |
75 | - array_fill( 0, 8, $any ), [ '-' ], |
|
76 | - array_fill( 0, 4, $any ), [ '-' ], |
|
77 | - array_fill( 0, 4, $any ), [ '-' ], |
|
78 | - array_fill( 0, 4, $any ), [ '-' ], |
|
79 | - array_fill( 0, 12, $any ) |
|
75 | + array_fill(0, 8, $any), ['-'], |
|
76 | + array_fill(0, 4, $any), ['-'], |
|
77 | + array_fill(0, 4, $any), ['-'], |
|
78 | + array_fill(0, 4, $any), ['-'], |
|
79 | + array_fill(0, 12, $any) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | * @throws DBUnexpectedError |
88 | 88 | */ |
89 | 89 | public function deleteWhereConstraintIdIsUuid() { |
90 | - $db = wfGetDB( DB_MASTER ); |
|
90 | + $db = wfGetDB(DB_MASTER); |
|
91 | 91 | $db->delete( |
92 | 92 | 'wbqc_constraints', |
93 | 93 | // WHERE constraint_guid LIKE ________-____-____-____-____________ |
94 | - 'constraint_guid ' . $db->buildLike( $this->uuidPattern( $db->anyChar() ) ) |
|
94 | + 'constraint_guid '.$db->buildLike($this->uuidPattern($db->anyChar())) |
|
95 | 95 | ); |
96 | 96 | } |
97 | 97 | |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @throws DBUnexpectedError |
103 | 103 | */ |
104 | - public function deleteForPropertyWhereConstraintIdIsStatementId( PropertyId $propertyId ) { |
|
105 | - $db = wfGetDB( DB_MASTER ); |
|
104 | + public function deleteForPropertyWhereConstraintIdIsStatementId(PropertyId $propertyId) { |
|
105 | + $db = wfGetDB(DB_MASTER); |
|
106 | 106 | $db->delete( |
107 | 107 | 'wbqc_constraints', |
108 | 108 | [ |
109 | 109 | 'pid' => $propertyId->getNumericId(), |
110 | 110 | // AND constraint_guid LIKE %$________-____-____-____-____________ |
111 | - 'constraint_guid ' . $db->buildLike( array_merge( [ $db->anyString(), '$' ], $this->uuidPattern( $db->anyChar() ) ) ) |
|
111 | + 'constraint_guid '.$db->buildLike(array_merge([$db->anyString(), '$'], $this->uuidPattern($db->anyChar()))) |
|
112 | 112 | ] |
113 | 113 | ); |
114 | 114 | } |
@@ -119,20 +119,20 @@ discard block |
||
119 | 119 | * @throws InvalidArgumentException |
120 | 120 | * @throws DBUnexpectedError |
121 | 121 | */ |
122 | - public function deleteAll( $batchSize = 1000 ) { |
|
123 | - if ( !is_int( $batchSize ) ) { |
|
122 | + public function deleteAll($batchSize = 1000) { |
|
123 | + if (!is_int($batchSize)) { |
|
124 | 124 | throw new InvalidArgumentException(); |
125 | 125 | } |
126 | - $db = wfGetDB( DB_MASTER ); |
|
127 | - if ( $db->getType() === 'sqlite' ) { |
|
128 | - $db->delete( 'wbqc_constraints', '*' ); |
|
126 | + $db = wfGetDB(DB_MASTER); |
|
127 | + if ($db->getType() === 'sqlite') { |
|
128 | + $db->delete('wbqc_constraints', '*'); |
|
129 | 129 | } else { |
130 | 130 | do { |
131 | - $db->commit( __METHOD__, 'flush' ); |
|
131 | + $db->commit(__METHOD__, 'flush'); |
|
132 | 132 | wfGetLBFactory()->waitForReplication(); |
133 | - $table = $db->tableName( 'wbqc_constraints' ); |
|
134 | - $db->query( sprintf( 'DELETE FROM %s LIMIT %d', $table, $batchSize ) ); |
|
135 | - } while ( $db->affectedRows() > 0 ); |
|
133 | + $table = $db->tableName('wbqc_constraints'); |
|
134 | + $db->query(sprintf('DELETE FROM %s LIMIT %d', $table, $batchSize)); |
|
135 | + } while ($db->affectedRows() > 0); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -141,26 +141,26 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return Constraint[] |
143 | 143 | */ |
144 | - private function convertToConstraints( ResultWrapper $results ) { |
|
144 | + private function convertToConstraints(ResultWrapper $results) { |
|
145 | 145 | $constraints = []; |
146 | - foreach ( $results as $result ) { |
|
146 | + foreach ($results as $result) { |
|
147 | 147 | $constraintTypeItemId = $result->constraint_type_qid; |
148 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
148 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
149 | 149 | |
150 | - if ( $constraintParameters === null ) { |
|
150 | + if ($constraintParameters === null) { |
|
151 | 151 | // T171295 |
152 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ) |
|
153 | - ->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
152 | + LoggerFactory::getInstance('WikibaseQualityConstraints') |
|
153 | + ->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
154 | 154 | 'method' => __METHOD__, |
155 | 155 | 'constraintId' => $result->constraint_guid, |
156 | 156 | 'constraintParameters' => $result->constraint_parameters, |
157 | - ] ); |
|
158 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
157 | + ]); |
|
158 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | $constraints[] = new Constraint( |
162 | 162 | $result->constraint_guid, |
163 | - PropertyId::newFromNumber( $result->pid ), |
|
163 | + PropertyId::newFromNumber($result->pid), |
|
164 | 164 | $constraintTypeItemId, |
165 | 165 | $constraintParameters |
166 | 166 | ); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @var ConstraintLookup $lookup The lookup to which all queries are delegated. |
28 | 28 | */ |
29 | - public function __construct( ConstraintLookup $lookup ) { |
|
29 | + public function __construct(ConstraintLookup $lookup) { |
|
30 | 30 | $this->lookup = $lookup; |
31 | 31 | } |
32 | 32 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return Constraint[] |
37 | 37 | */ |
38 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
38 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
39 | 39 | $id = $propertyId->getSerialization(); |
40 | - if ( !array_key_exists( $id, $this->cache ) ) { |
|
41 | - $this->cache[$id] = $this->lookup->queryConstraintsForProperty( $propertyId ); |
|
40 | + if (!array_key_exists($id, $this->cache)) { |
|
41 | + $this->cache[$id] = $this->lookup->queryConstraintsForProperty($propertyId); |
|
42 | 42 | } |
43 | 43 | return $this->cache[$id]; |
44 | 44 | } |
@@ -72,7 +72,7 @@ |
||
72 | 72 | * @codeCoverageIgnore |
73 | 73 | */ |
74 | 74 | private function __construct() { |
75 | - throw new LogicException( 'This class should never be instantiated.' ); |
|
75 | + throw new LogicException('This class should never be instantiated.'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | } |
@@ -25,22 +25,22 @@ |
||
25 | 25 | */ |
26 | 26 | const NULL_PROPERTY_ID = 'P2147483647'; |
27 | 27 | |
28 | - public function __construct( Context $context ) { |
|
28 | + public function __construct(Context $context) { |
|
29 | 29 | $constraint = new Constraint( |
30 | 30 | 'null', |
31 | - new PropertyId( self::NULL_PROPERTY_ID ), |
|
31 | + new PropertyId(self::NULL_PROPERTY_ID), |
|
32 | 32 | 'none', |
33 | 33 | [] |
34 | 34 | ); |
35 | - parent::__construct( $context, $constraint ); |
|
35 | + parent::__construct($context, $constraint); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function getConstraint() { |
39 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
39 | + throw new DomainException('NullResult holds no constraint'); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function getConstraintId() { |
43 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
43 | + throw new DomainException('NullResult holds no constraint'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @throws ConstraintParameterException if the constraint parameters are invalid |
23 | 23 | * @throws SparqlHelperException if the checker uses SPARQL and the query times out or some other error occurs |
24 | 24 | */ |
25 | - public function checkConstraint( Context $context, Constraint $constraint ); |
|
25 | + public function checkConstraint(Context $context, Constraint $constraint); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Check if the constraint parameters of $constraint are valid. |
@@ -33,6 +33,6 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return ConstraintParameterException[] |
35 | 35 | */ |
36 | - public function checkConstraintParameters( Constraint $constraint ); |
|
36 | + public function checkConstraintParameters(Constraint $constraint); |
|
37 | 37 | |
38 | 38 | } |