@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | */ |
39 | 39 | private const BATCH_SIZE = 50; |
40 | 40 | |
41 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
42 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
41 | + public static function newFromGlobalState(Title $title, array $params) { |
|
42 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
43 | 43 | $services = MediaWikiServices::getInstance(); |
44 | 44 | return new UpdateConstraintsTableJob( |
45 | 45 | $title, |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | $services->getMainConfig(), |
50 | 50 | ConstraintsServices::getConstraintStore(), |
51 | 51 | $services->getDBLoadBalancerFactory(), |
52 | - WikibaseRepo::getStore()->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ), |
|
53 | - WikibaseRepo::getBaseDataModelSerializerFactory( $services ) |
|
52 | + WikibaseRepo::getStore()->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED), |
|
53 | + WikibaseRepo::getBaseDataModelSerializerFactory($services) |
|
54 | 54 | ->newSnakSerializer() |
55 | 55 | ); |
56 | 56 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | EntityRevisionLookup $entityRevisionLookup, |
111 | 111 | Serializer $snakSerializer |
112 | 112 | ) { |
113 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
113 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
114 | 114 | |
115 | 115 | $this->propertyId = $propertyId; |
116 | 116 | $this->revisionId = $revisionId; |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | $this->snakSerializer = $snakSerializer; |
122 | 122 | } |
123 | 123 | |
124 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
124 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
125 | 125 | $parameters = []; |
126 | - foreach ( $qualifiers as $qualifier ) { |
|
126 | + foreach ($qualifiers as $qualifier) { |
|
127 | 127 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
128 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
128 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
129 | 129 | $parameters[$qualifierId][] = $paramSerialization; |
130 | 130 | } |
131 | 131 | return $parameters; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | '@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue'; |
143 | 143 | $entityId = $dataValue->getEntityId(); |
144 | 144 | $constraintTypeQid = $entityId->getSerialization(); |
145 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
145 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
146 | 146 | return new Constraint( |
147 | 147 | $constraintId, |
148 | 148 | $propertyId, |
@@ -157,24 +157,24 @@ discard block |
||
157 | 157 | PropertyId $propertyConstraintPropertyId |
158 | 158 | ) { |
159 | 159 | $constraintsStatements = $property->getStatements() |
160 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
161 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
160 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
161 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
162 | 162 | $constraints = []; |
163 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
164 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
165 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
166 | - $constraintStore->insertBatch( $constraints ); |
|
163 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
164 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
165 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
166 | + $constraintStore->insertBatch($constraints); |
|
167 | 167 | // interrupt transaction and wait for replication |
168 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY ); |
|
169 | - $connection->endAtomic( __CLASS__ ); |
|
170 | - if ( !$connection->explicitTrxActive() ) { |
|
168 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY); |
|
169 | + $connection->endAtomic(__CLASS__); |
|
170 | + if (!$connection->explicitTrxActive()) { |
|
171 | 171 | $this->lbFactory->waitForReplication(); |
172 | 172 | } |
173 | - $connection->startAtomic( __CLASS__ ); |
|
173 | + $connection->startAtomic(__CLASS__); |
|
174 | 174 | $constraints = []; |
175 | 175 | } |
176 | 176 | } |
177 | - $constraintStore->insertBatch( $constraints ); |
|
177 | + $constraintStore->insertBatch($constraints); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -185,24 +185,24 @@ discard block |
||
185 | 185 | public function run() { |
186 | 186 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
187 | 187 | |
188 | - $propertyId = new PropertyId( $this->propertyId ); |
|
188 | + $propertyId = new PropertyId($this->propertyId); |
|
189 | 189 | $propertyRevision = $this->entityRevisionLookup->getEntityRevision( |
190 | 190 | $propertyId, |
191 | 191 | 0, // latest |
192 | 192 | LookupConstants::LATEST_FROM_REPLICA |
193 | 193 | ); |
194 | 194 | |
195 | - if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) { |
|
196 | - JobQueueGroup::singleton()->push( $this ); |
|
195 | + if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) { |
|
196 | + JobQueueGroup::singleton()->push($this); |
|
197 | 197 | return true; |
198 | 198 | } |
199 | 199 | |
200 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY ); |
|
200 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY); |
|
201 | 201 | // start transaction (if not started yet) – using __CLASS__, not __METHOD__, |
202 | 202 | // because importConstraintsForProperty() can interrupt the transaction |
203 | - $connection->startAtomic( __CLASS__ ); |
|
203 | + $connection->startAtomic(__CLASS__); |
|
204 | 204 | |
205 | - $this->constraintStore->deleteForProperty( $propertyId ); |
|
205 | + $this->constraintStore->deleteForProperty($propertyId); |
|
206 | 206 | |
207 | 207 | /** @var Property $property */ |
208 | 208 | $property = $propertyRevision->getEntity(); |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | $this->importConstraintsForProperty( |
211 | 211 | $property, |
212 | 212 | $this->constraintStore, |
213 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
213 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
214 | 214 | ); |
215 | 215 | |
216 | - $connection->endAtomic( __CLASS__ ); |
|
216 | + $connection->endAtomic(__CLASS__); |
|
217 | 217 | |
218 | 218 | return true; |
219 | 219 | } |
@@ -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_PRIMARY, [], $this->dbName ); |
|
62 | - return $dbw->insert( 'wbqc_constraints', $accumulator, __METHOD__ ); |
|
61 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_PRIMARY, [], $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_PRIMARY, [], $this->dbName ); |
|
72 | + public function deleteForProperty(PropertyId $propertyId) { |
|
73 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_PRIMARY, [], $this->dbName); |
|
74 | 74 | $dbw->delete( |
75 | 75 | 'wbqc_constraints', |
76 | 76 | [ |