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