@@ -38,90 +38,90 @@ |
||
38 | 38 | const RESULTS_SOURCE = 'WBQC_ResultsSource'; |
39 | 39 | const EXPIRY_LOCK = 'WBQC_ExpiryLock'; |
40 | 40 | |
41 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
42 | - if ( $services === null ) { |
|
41 | + private static function getService(?MediaWikiServices $services, $name) { |
|
42 | + if ($services === null) { |
|
43 | 43 | $services = MediaWikiServices::getInstance(); |
44 | 44 | } |
45 | - return $services->getService( $name ); |
|
45 | + return $services->getService($name); |
|
46 | 46 | } |
47 | 47 | |
48 | - public static function getLoggingHelper( MediaWikiServices $services = null ): LoggingHelper { |
|
49 | - return self::getService( $services, self::LOGGING_HELPER ); |
|
48 | + public static function getLoggingHelper(MediaWikiServices $services = null): LoggingHelper { |
|
49 | + return self::getService($services, self::LOGGING_HELPER); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public static function getConstraintStore( |
53 | 53 | MediaWikiServices $services = null |
54 | 54 | ): ConstraintStore { |
55 | - return self::getService( $services, self::CONSTRAINT_STORE ); |
|
55 | + return self::getService($services, self::CONSTRAINT_STORE); |
|
56 | 56 | } |
57 | 57 | |
58 | - public static function getConstraintLookup( MediaWikiServices $services = null ): ConstraintLookup { |
|
59 | - return self::getService( $services, self::CONSTRAINT_LOOKUP ); |
|
58 | + public static function getConstraintLookup(MediaWikiServices $services = null): ConstraintLookup { |
|
59 | + return self::getService($services, self::CONSTRAINT_LOOKUP); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | public static function getCheckResultSerializer( |
63 | 63 | MediaWikiServices $services = null |
64 | 64 | ): CheckResultSerializer { |
65 | - return self::getService( $services, self::CHECK_RESULT_SERIALIZER ); |
|
65 | + return self::getService($services, self::CHECK_RESULT_SERIALIZER); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | public static function getCheckResultDeserializer( |
69 | 69 | MediaWikiServices $services = null |
70 | 70 | ): CheckResultDeserializer { |
71 | - return self::getService( $services, self::CHECK_RESULT_DESERIALIZER ); |
|
71 | + return self::getService($services, self::CHECK_RESULT_DESERIALIZER); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | public static function getViolationMessageSerializer( |
75 | 75 | MediaWikiServices $services = null |
76 | 76 | ): ViolationMessageSerializer { |
77 | - return self::getService( $services, self::VIOLATION_MESSAGE_SERIALIZER ); |
|
77 | + return self::getService($services, self::VIOLATION_MESSAGE_SERIALIZER); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | public static function getViolationMessageDeserializer( |
81 | 81 | MediaWikiServices $services = null |
82 | 82 | ): ViolationMessageDeserializer { |
83 | - return self::getService( $services, self::VIOLATION_MESSAGE_DESERIALIZER ); |
|
83 | + return self::getService($services, self::VIOLATION_MESSAGE_DESERIALIZER); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | public static function getConstraintParameterParser( |
87 | 87 | MediaWikiServices $services = null |
88 | 88 | ): ConstraintParameterParser { |
89 | - return self::getService( $services, self::CONSTRAINT_PARAMETER_PARSER ); |
|
89 | + return self::getService($services, self::CONSTRAINT_PARAMETER_PARSER); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | public static function getConnectionCheckerHelper( |
93 | 93 | MediaWikiServices $services = null |
94 | 94 | ): ConnectionCheckerHelper { |
95 | - return self::getService( $services, self::CONNECTION_CHECKER_HELPER ); |
|
95 | + return self::getService($services, self::CONNECTION_CHECKER_HELPER); |
|
96 | 96 | } |
97 | 97 | |
98 | - public static function getRangeCheckerHelper( MediaWikiServices $services = null ): RangeCheckerHelper { |
|
99 | - return self::getService( $services, self::RANGE_CHECKER_HELPER ); |
|
98 | + public static function getRangeCheckerHelper(MediaWikiServices $services = null): RangeCheckerHelper { |
|
99 | + return self::getService($services, self::RANGE_CHECKER_HELPER); |
|
100 | 100 | } |
101 | 101 | |
102 | - public static function getSparqlHelper( MediaWikiServices $services = null ): SparqlHelper { |
|
103 | - return self::getService( $services, self::SPARQL_HELPER ); |
|
102 | + public static function getSparqlHelper(MediaWikiServices $services = null): SparqlHelper { |
|
103 | + return self::getService($services, self::SPARQL_HELPER); |
|
104 | 104 | } |
105 | 105 | |
106 | - public static function getTypeCheckerHelper( MediaWikiServices $services = null ): TypeCheckerHelper { |
|
107 | - return self::getService( $services, self::TYPE_CHECKER_HELPER ); |
|
106 | + public static function getTypeCheckerHelper(MediaWikiServices $services = null): TypeCheckerHelper { |
|
107 | + return self::getService($services, self::TYPE_CHECKER_HELPER); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | public static function getDelegatingConstraintChecker( |
111 | 111 | MediaWikiServices $services = null |
112 | 112 | ): DelegatingConstraintChecker { |
113 | - return self::getService( $services, self::DELEGATING_CONSTRAINT_CHECKER ); |
|
113 | + return self::getService($services, self::DELEGATING_CONSTRAINT_CHECKER); |
|
114 | 114 | } |
115 | 115 | |
116 | - public static function getResultsSource( MediaWikiServices $services = null ): ResultsSource { |
|
117 | - return self::getService( $services, self::RESULTS_SOURCE ); |
|
116 | + public static function getResultsSource(MediaWikiServices $services = null): ResultsSource { |
|
117 | + return self::getService($services, self::RESULTS_SOURCE); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @return ExpiryLock |
122 | 122 | */ |
123 | - public static function getExpiryLock( MediaWikiServices $services = null ) { |
|
124 | - return self::getService( $services, self::EXPIRY_LOCK ); |
|
123 | + public static function getExpiryLock(MediaWikiServices $services = null) { |
|
124 | + return self::getService($services, self::EXPIRY_LOCK); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @return bool |
17 | 17 | * @throws DBUnexpectedError |
18 | 18 | */ |
19 | - public function insertBatch( array $constraints ); |
|
19 | + public function insertBatch(array $constraints); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Delete all constraints for the property ID. |
@@ -25,6 +25,6 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @throws DBUnexpectedError |
27 | 27 | */ |
28 | - public function deleteForProperty( PropertyId $propertyId ); |
|
28 | + public function deleteForProperty(PropertyId $propertyId); |
|
29 | 29 | |
30 | 30 | } |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | ) { |
144 | 144 | $results = []; |
145 | 145 | $metadatas = []; |
146 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
146 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
147 | 147 | $storedEntityIds = []; |
148 | - foreach ( $entityIds as $entityId ) { |
|
149 | - $storedResults = $this->getStoredResults( $entityId ); |
|
150 | - if ( $storedResults !== null ) { |
|
151 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
152 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
153 | - if ( $this->statusSelected( $statuses, $checkResult ) ) { |
|
148 | + foreach ($entityIds as $entityId) { |
|
149 | + $storedResults = $this->getStoredResults($entityId); |
|
150 | + if ($storedResults !== null) { |
|
151 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
152 | + foreach ($storedResults->getArray() as $checkResult) { |
|
153 | + if ($this->statusSelected($statuses, $checkResult)) { |
|
154 | 154 | $results[] = $checkResult; |
155 | 155 | } |
156 | 156 | } |
@@ -158,19 +158,19 @@ discard block |
||
158 | 158 | $storedEntityIds[] = $entityId; |
159 | 159 | } |
160 | 160 | } |
161 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
161 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
162 | 162 | } |
163 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
164 | - if ( $entityIds !== [] ) { |
|
165 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
163 | + if ($entityIds !== [] || $claimIds !== []) { |
|
164 | + if ($entityIds !== []) { |
|
165 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
166 | 166 | } |
167 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
168 | - $results = array_merge( $results, $response->getArray() ); |
|
167 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
168 | + $results = array_merge($results, $response->getArray()); |
|
169 | 169 | $metadatas[] = $response->getMetadata(); |
170 | 170 | } |
171 | 171 | return new CachedCheckResults( |
172 | 172 | $results, |
173 | - Metadata::merge( $metadatas ) |
|
173 | + Metadata::merge($metadatas) |
|
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | ?array $constraintIds, |
194 | 194 | array $statuses |
195 | 195 | ) { |
196 | - if ( $claimIds !== [] ) { |
|
196 | + if ($claimIds !== []) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | - if ( $constraintIds !== null ) { |
|
199 | + if ($constraintIds !== null) { |
|
200 | 200 | return false; |
201 | 201 | } |
202 | - if ( array_diff( $statuses, self::CACHED_STATUSES ) !== [] ) { |
|
202 | + if (array_diff($statuses, self::CACHED_STATUSES) !== []) { |
|
203 | 203 | return false; |
204 | 204 | } |
205 | 205 | return true; |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @param CheckResult $result |
215 | 215 | * @return bool |
216 | 216 | */ |
217 | - private function statusSelected( array $statuses, CheckResult $result ) { |
|
218 | - return in_array( $result->getStatus(), $statuses, true ) || |
|
217 | + private function statusSelected(array $statuses, CheckResult $result) { |
|
218 | + return in_array($result->getStatus(), $statuses, true) || |
|
219 | 219 | $result instanceof NullResult; |
220 | 220 | } |
221 | 221 | |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | ?array $constraintIds, |
233 | 233 | array $statuses |
234 | 234 | ) { |
235 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
235 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
236 | 236 | |
237 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
238 | - foreach ( $entityIds as $entityId ) { |
|
239 | - $this->storeResults( $entityId, $results ); |
|
237 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
238 | + foreach ($entityIds as $entityId) { |
|
239 | + $this->storeResults($entityId, $results); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | ?array $constraintIds, |
268 | 268 | array $statuses |
269 | 269 | ) { |
270 | - if ( $constraintIds !== null ) { |
|
270 | + if ($constraintIds !== null) { |
|
271 | 271 | return false; |
272 | 272 | } |
273 | - if ( array_diff( self::CACHED_STATUSES, $statuses ) !== [] ) { |
|
273 | + if (array_diff(self::CACHED_STATUSES, $statuses) !== []) { |
|
274 | 274 | return false; |
275 | 275 | } |
276 | 276 | return true; |
@@ -284,21 +284,21 @@ discard block |
||
284 | 284 | * May include check results for other entity IDs as well, |
285 | 285 | * or check results with statuses that we’re not interested in caching. |
286 | 286 | */ |
287 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
287 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
288 | 288 | $latestRevisionIds = $this->getLatestRevisionIds( |
289 | 289 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
290 | 290 | ); |
291 | - if ( $latestRevisionIds === null ) { |
|
291 | + if ($latestRevisionIds === null) { |
|
292 | 292 | return; |
293 | 293 | } |
294 | 294 | |
295 | 295 | $resultSerializations = []; |
296 | - foreach ( $results->getArray() as $checkResult ) { |
|
297 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
296 | + foreach ($results->getArray() as $checkResult) { |
|
297 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
298 | 298 | continue; |
299 | 299 | } |
300 | - if ( $this->statusSelected( self::CACHED_STATUSES, $checkResult ) ) { |
|
301 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
300 | + if ($this->statusSelected(self::CACHED_STATUSES, $checkResult)) { |
|
301 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
@@ -307,11 +307,11 @@ discard block |
||
307 | 307 | 'latestRevisionIds' => $latestRevisionIds, |
308 | 308 | ]; |
309 | 309 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
310 | - if ( $futureTime !== null ) { |
|
310 | + if ($futureTime !== null) { |
|
311 | 311 | $value['futureTime'] = $futureTime->getArrayValue(); |
312 | 312 | } |
313 | 313 | |
314 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
314 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -325,31 +325,30 @@ discard block |
||
325 | 325 | EntityId $entityId, |
326 | 326 | $forRevision = 0 |
327 | 327 | ) { |
328 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
329 | - $now = call_user_func( $this->microtime, true ); |
|
328 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
329 | + $now = call_user_func($this->microtime, true); |
|
330 | 330 | |
331 | - $dependencyMetadata = $this->checkDependencyMetadata( $value, |
|
332 | - [ $entityId->getSerialization() => $forRevision ] ); |
|
333 | - if ( $dependencyMetadata === null ) { |
|
331 | + $dependencyMetadata = $this->checkDependencyMetadata($value, |
|
332 | + [$entityId->getSerialization() => $forRevision]); |
|
333 | + if ($dependencyMetadata === null) { |
|
334 | 334 | return null; |
335 | 335 | } |
336 | 336 | |
337 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
337 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
338 | 338 | $cachingMetadata = $ageInSeconds > 0 ? |
339 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
340 | - CachingMetadata::fresh(); |
|
339 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
341 | 340 | |
342 | 341 | $results = []; |
343 | - foreach ( $value['results'] as $resultSerialization ) { |
|
344 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
342 | + foreach ($value['results'] as $resultSerialization) { |
|
343 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
345 | 344 | } |
346 | 345 | |
347 | 346 | return new CachedCheckResults( |
348 | 347 | $results, |
349 | - Metadata::merge( [ |
|
350 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
351 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
352 | - ] ) |
|
348 | + Metadata::merge([ |
|
349 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
350 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
351 | + ]) |
|
353 | 352 | ); |
354 | 353 | } |
355 | 354 | |
@@ -365,43 +364,43 @@ discard block |
||
365 | 364 | * @return DependencyMetadata|null the dependency metadata, |
366 | 365 | * or null if $value should no longer be used |
367 | 366 | */ |
368 | - private function checkDependencyMetadata( $value, $paramRevs ) { |
|
369 | - if ( $value === false ) { |
|
367 | + private function checkDependencyMetadata($value, $paramRevs) { |
|
368 | + if ($value === false) { |
|
370 | 369 | return null; |
371 | 370 | } |
372 | 371 | |
373 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
374 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
375 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
372 | + if (array_key_exists('futureTime', $value)) { |
|
373 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
374 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
376 | 375 | return null; |
377 | 376 | } |
378 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
377 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
379 | 378 | } else { |
380 | 379 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
381 | 380 | } |
382 | 381 | |
383 | - foreach ( $paramRevs as $id => $revision ) { |
|
384 | - if ( $revision > 0 ) { |
|
385 | - $value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX ); |
|
382 | + foreach ($paramRevs as $id => $revision) { |
|
383 | + if ($revision > 0) { |
|
384 | + $value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX); |
|
386 | 385 | } |
387 | 386 | } |
388 | 387 | |
389 | 388 | $dependedEntityIds = array_map( |
390 | - [ $this->entityIdParser, "parse" ], |
|
391 | - array_keys( $value['latestRevisionIds'] ) |
|
389 | + [$this->entityIdParser, "parse"], |
|
390 | + array_keys($value['latestRevisionIds']) |
|
392 | 391 | ); |
393 | 392 | |
394 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
393 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
395 | 394 | return null; |
396 | 395 | } |
397 | 396 | |
398 | 397 | return array_reduce( |
399 | 398 | $dependedEntityIds, |
400 | - function( DependencyMetadata $metadata, EntityId $entityId ) { |
|
401 | - return DependencyMetadata::merge( [ |
|
399 | + function(DependencyMetadata $metadata, EntityId $entityId) { |
|
400 | + return DependencyMetadata::merge([ |
|
402 | 401 | $metadata, |
403 | - DependencyMetadata::ofEntityId( $entityId ) |
|
404 | - ] ); |
|
402 | + DependencyMetadata::ofEntityId($entityId) |
|
403 | + ]); |
|
405 | 404 | }, |
406 | 405 | $futureTimeDependencyMetadata |
407 | 406 | ); |
@@ -421,13 +420,13 @@ discard block |
||
421 | 420 | array $resultSerialization, |
422 | 421 | CachingMetadata $cachingMetadata |
423 | 422 | ) { |
424 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
425 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
423 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
424 | + if ($this->isPossiblyStaleResult($result)) { |
|
426 | 425 | $result->withMetadata( |
427 | - Metadata::merge( [ |
|
426 | + Metadata::merge([ |
|
428 | 427 | $result->getMetadata(), |
429 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
430 | - ] ) |
|
428 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
429 | + ]) |
|
431 | 430 | ); |
432 | 431 | } |
433 | 432 | return $result; |
@@ -437,8 +436,8 @@ discard block |
||
437 | 436 | * @param CheckResult $result |
438 | 437 | * @return bool |
439 | 438 | */ |
440 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
441 | - if ( $result instanceof NullResult ) { |
|
439 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
440 | + if ($result instanceof NullResult) { |
|
442 | 441 | return false; |
443 | 442 | } |
444 | 443 | |
@@ -453,14 +452,14 @@ discard block |
||
453 | 452 | * @return int[]|null array from entity ID serializations to revision ID, |
454 | 453 | * or null to indicate that not all revision IDs could be loaded |
455 | 454 | */ |
456 | - private function getLatestRevisionIds( array $entityIds ) { |
|
457 | - if ( $entityIds === [] ) { |
|
455 | + private function getLatestRevisionIds(array $entityIds) { |
|
456 | + if ($entityIds === []) { |
|
458 | 457 | $this->loggingHelper->logEmptyDependencyMetadata(); |
459 | 458 | return []; |
460 | 459 | } |
461 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
460 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
462 | 461 | // one of those entities will probably be edited soon, so might as well skip caching |
463 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
462 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
464 | 463 | return null; |
465 | 464 | } |
466 | 465 | |
@@ -468,7 +467,7 @@ discard block |
||
468 | 467 | $entityIds, |
469 | 468 | LookupConstants::LATEST_FROM_REPLICA |
470 | 469 | ); |
471 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
470 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
472 | 471 | return null; |
473 | 472 | } |
474 | 473 | return $latestRevisionIds; |
@@ -478,8 +477,8 @@ discard block |
||
478 | 477 | * @param array $array |
479 | 478 | * @return bool |
480 | 479 | */ |
481 | - private function hasFalseElements( array $array ) { |
|
482 | - return in_array( false, $array, true ); |
|
480 | + private function hasFalseElements(array $array) { |
|
481 | + return in_array(false, $array, true); |
|
483 | 482 | } |
484 | 483 | |
485 | 484 | /** |
@@ -487,7 +486,7 @@ discard block |
||
487 | 486 | * |
488 | 487 | * @param callable $microtime |
489 | 488 | */ |
490 | - public function setMicrotimeFunction( callable $microtime ) { |
|
489 | + public function setMicrotimeFunction(callable $microtime) { |
|
491 | 490 | $this->microtime = $microtime; |
492 | 491 | } |
493 | 492 |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | |
33 | 33 | const BATCH_SIZE = 10; |
34 | 34 | |
35 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
36 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
35 | + public static function newFromGlobalState(Title $title, array $params) { |
|
36 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
37 | 37 | $repo = WikibaseRepo::getDefaultInstance(); |
38 | 38 | return new UpdateConstraintsTableJob( |
39 | 39 | $title, |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $params['revisionId'] ?? null, |
43 | 43 | MediaWikiServices::getInstance()->getMainConfig(), |
44 | 44 | ConstraintsServices::getConstraintStore(), |
45 | - $repo->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ), |
|
45 | + $repo->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED), |
|
46 | 46 | $repo->getBaseDataModelSerializerFactory()->newSnakSerializer() |
47 | 47 | ); |
48 | 48 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | EntityRevisionLookup $entityRevisionLookup, |
98 | 98 | Serializer $snakSerializer |
99 | 99 | ) { |
100 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
100 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
101 | 101 | |
102 | 102 | $this->propertyId = $propertyId; |
103 | 103 | $this->revisionId = $revisionId; |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | $this->snakSerializer = $snakSerializer; |
108 | 108 | } |
109 | 109 | |
110 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
110 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
111 | 111 | $parameters = []; |
112 | - foreach ( $qualifiers as $qualifier ) { |
|
112 | + foreach ($qualifiers as $qualifier) { |
|
113 | 113 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
114 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
114 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
115 | 115 | $parameters[$qualifierId][] = $paramSerialization; |
116 | 116 | } |
117 | 117 | return $parameters; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | '@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue'; |
129 | 129 | $entityId = $dataValue->getEntityId(); |
130 | 130 | $constraintTypeQid = $entityId->getSerialization(); |
131 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
131 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
132 | 132 | return new Constraint( |
133 | 133 | $constraintId, |
134 | 134 | $propertyId, |
@@ -143,17 +143,17 @@ discard block |
||
143 | 143 | PropertyId $propertyConstraintPropertyId |
144 | 144 | ) { |
145 | 145 | $constraintsStatements = $property->getStatements() |
146 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
147 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
146 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
147 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
148 | 148 | $constraints = []; |
149 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
150 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
151 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
152 | - $constraintStore->insertBatch( $constraints ); |
|
149 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
150 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
151 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
152 | + $constraintStore->insertBatch($constraints); |
|
153 | 153 | $constraints = []; |
154 | 154 | } |
155 | 155 | } |
156 | - $constraintStore->insertBatch( $constraints ); |
|
156 | + $constraintStore->insertBatch($constraints); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -164,19 +164,19 @@ discard block |
||
164 | 164 | public function run() { |
165 | 165 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
166 | 166 | |
167 | - $propertyId = new PropertyId( $this->propertyId ); |
|
167 | + $propertyId = new PropertyId($this->propertyId); |
|
168 | 168 | $propertyRevision = $this->entityRevisionLookup->getEntityRevision( |
169 | 169 | $propertyId, |
170 | 170 | 0, // latest |
171 | 171 | LookupConstants::LATEST_FROM_REPLICA |
172 | 172 | ); |
173 | 173 | |
174 | - if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) { |
|
175 | - JobQueueGroup::singleton()->push( $this ); |
|
174 | + if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) { |
|
175 | + JobQueueGroup::singleton()->push($this); |
|
176 | 176 | return true; |
177 | 177 | } |
178 | 178 | |
179 | - $this->constraintStore->deleteForProperty( $propertyId ); |
|
179 | + $this->constraintStore->deleteForProperty($propertyId); |
|
180 | 180 | |
181 | 181 | /** @var Property $property */ |
182 | 182 | $property = $propertyRevision->getEntity(); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $this->importConstraintsForProperty( |
185 | 185 | $property, |
186 | 186 | $this->constraintStore, |
187 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
187 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
188 | 188 | ); |
189 | 189 | |
190 | 190 | return true; |
@@ -24,16 +24,16 @@ discard block |
||
24 | 24 | * then using the main DBLoadBalancer service may be incorrect. |
25 | 25 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
26 | 26 | */ |
27 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
27 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
28 | 28 | $this->lb = $lb; |
29 | 29 | $this->dbName = $dbName; |
30 | 30 | } |
31 | 31 | |
32 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
33 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
32 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
33 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
34 | 34 | |
35 | - if ( strlen( $json ) > 50000 ) { |
|
36 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
35 | + if (strlen($json) > 50000) { |
|
36 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | return $json; |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | * @throws DBUnexpectedError |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - public function insertBatch( array $constraints ) { |
|
48 | + public function insertBatch(array $constraints) { |
|
49 | 49 | $accumulator = array_map( |
50 | - function ( Constraint $constraint ) { |
|
50 | + function(Constraint $constraint) { |
|
51 | 51 | return [ |
52 | 52 | 'constraint_guid' => $constraint->getConstraintId(), |
53 | 53 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
54 | 54 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
55 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
55 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
56 | 56 | ]; |
57 | 57 | }, |
58 | 58 | $constraints |
59 | 59 | ); |
60 | 60 | |
61 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_MASTER, [], $this->dbName ); |
|
62 | - return $dbw->insert( 'wbqc_constraints', $accumulator, __METHOD__ ); |
|
61 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER, [], $this->dbName); |
|
62 | + return $dbw->insert('wbqc_constraints', $accumulator, __METHOD__); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @throws DBUnexpectedError |
71 | 71 | */ |
72 | - public function deleteForProperty( PropertyId $propertyId ) { |
|
73 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_MASTER, [], $this->dbName ); |
|
72 | + public function deleteForProperty(PropertyId $propertyId) { |
|
73 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER, [], $this->dbName); |
|
74 | 74 | $dbw->delete( |
75 | 75 | 'wbqc_constraints', |
76 | 76 | [ |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * then using the main DBLoadBalancer service may be incorrect. |
26 | 26 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
27 | 27 | */ |
28 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
28 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
29 | 29 | $this->lb = $lb; |
30 | 30 | $this->dbName = $dbName; |
31 | 31 | } |
@@ -35,17 +35,17 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return Constraint[] |
37 | 37 | */ |
38 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
39 | - $dbr = $this->lb->getConnectionRef( ILoadBalancer::DB_REPLICA, [], $this->dbName ); |
|
38 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
39 | + $dbr = $this->lb->getConnectionRef(ILoadBalancer::DB_REPLICA, [], $this->dbName); |
|
40 | 40 | |
41 | 41 | $results = $dbr->select( |
42 | 42 | 'wbqc_constraints', |
43 | 43 | '*', |
44 | - [ 'pid' => $propertyId->getNumericId() ], |
|
44 | + ['pid' => $propertyId->getNumericId()], |
|
45 | 45 | __METHOD__ |
46 | 46 | ); |
47 | 47 | |
48 | - return $this->convertToConstraints( $results ); |
|
48 | + return $this->convertToConstraints($results); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -53,26 +53,26 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return Constraint[] |
55 | 55 | */ |
56 | - private function convertToConstraints( IResultWrapper $results ) { |
|
56 | + private function convertToConstraints(IResultWrapper $results) { |
|
57 | 57 | $constraints = []; |
58 | - $logger = LoggerFactory::getInstance( 'WikibaseQualityConstraints' ); |
|
59 | - foreach ( $results as $result ) { |
|
58 | + $logger = LoggerFactory::getInstance('WikibaseQualityConstraints'); |
|
59 | + foreach ($results as $result) { |
|
60 | 60 | $constraintTypeItemId = $result->constraint_type_qid; |
61 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
61 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
62 | 62 | |
63 | - if ( $constraintParameters === null ) { |
|
63 | + if ($constraintParameters === null) { |
|
64 | 64 | // T171295 |
65 | - $logger->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
65 | + $logger->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
66 | 66 | 'method' => __METHOD__, |
67 | 67 | 'constraintId' => $result->constraint_guid, |
68 | 68 | 'constraintParameters' => $result->constraint_parameters, |
69 | - ] ); |
|
70 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
69 | + ]); |
|
70 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | $constraints[] = new Constraint( |
74 | 74 | $result->constraint_guid, |
75 | - PropertyId::newFromNumber( $result->pid ), |
|
75 | + PropertyId::newFromNumber($result->pid), |
|
76 | 76 | $constraintTypeItemId, |
77 | 77 | $constraintParameters |
78 | 78 | ); |