@@ -27,27 +27,27 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * @param DatabaseUpdater $updater |
29 | 29 | */ |
30 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
31 | - $dir = dirname( __DIR__ ) . '/sql/'; |
|
30 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
31 | + $dir = dirname(__DIR__).'/sql/'; |
|
32 | 32 | |
33 | 33 | $updater->addExtensionTable( |
34 | 34 | 'wbqc_constraints', |
35 | - $dir . "/{$updater->getDB()->getType()}/tables-generated.sql" |
|
35 | + $dir."/{$updater->getDB()->getType()}/tables-generated.sql" |
|
36 | 36 | ); |
37 | 37 | $updater->addExtensionField( |
38 | 38 | 'wbqc_constraints', |
39 | 39 | 'constraint_id', |
40 | - $dir . '/patch-wbqc_constraints-constraint_id.sql' |
|
40 | + $dir.'/patch-wbqc_constraints-constraint_id.sql' |
|
41 | 41 | ); |
42 | 42 | $updater->addExtensionIndex( |
43 | 43 | 'wbqc_constraints', |
44 | 44 | 'wbqc_constraints_guid_uniq', |
45 | - $dir . '/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
45 | + $dir.'/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
46 | 46 | ); |
47 | 47 | } |
48 | 48 | |
49 | - public static function onWikibaseChange( Change $change ) { |
|
50 | - if ( !( $change instanceof EntityChange ) ) { |
|
49 | + public static function onWikibaseChange(Change $change) { |
|
50 | + if (!($change instanceof EntityChange)) { |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | /** @var EntityChange $change */ |
@@ -58,48 +58,48 @@ discard block |
||
58 | 58 | |
59 | 59 | // If jobs are enabled and the results would be stored in some way run a job. |
60 | 60 | if ( |
61 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
62 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
61 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
62 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
63 | 63 | self::isSelectedForJobRunBasedOnPercentage() |
64 | 64 | ) { |
65 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
65 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
66 | 66 | $jobQueueGroup->lazyPush( |
67 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
67 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
68 | 68 | ); |
69 | 69 | } |
70 | 70 | |
71 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
72 | - self::isConstraintStatementsChange( $config, $change ) |
|
71 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
72 | + self::isConstraintStatementsChange($config, $change) |
|
73 | 73 | ) { |
74 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
74 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
75 | 75 | $metadata = $change->getMetadata(); |
76 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
76 | + if (array_key_exists('rev_id', $metadata)) { |
|
77 | 77 | $params['revisionId'] = $metadata['rev_id']; |
78 | 78 | } |
79 | 79 | $jobQueueGroup->push( |
80 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
80 | + new JobSpecification('constraintsTableUpdate', $params) |
|
81 | 81 | ); |
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | 85 | private static function isSelectedForJobRunBasedOnPercentage() { |
86 | 86 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
87 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
87 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
88 | 88 | |
89 | - return mt_rand( 1, 100 ) <= $percentage; |
|
89 | + return mt_rand(1, 100) <= $percentage; |
|
90 | 90 | } |
91 | 91 | |
92 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
93 | - if ( !( $change instanceof EntityChange ) || |
|
92 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
93 | + if (!($change instanceof EntityChange) || |
|
94 | 94 | $change->getAction() !== EntityChange::UPDATE || |
95 | - !( $change->getEntityId() instanceof NumericPropertyId ) |
|
95 | + !($change->getEntityId() instanceof NumericPropertyId) |
|
96 | 96 | ) { |
97 | 97 | return false; |
98 | 98 | } |
99 | 99 | |
100 | 100 | $info = $change->getInfo(); |
101 | 101 | |
102 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
102 | + if (!array_key_exists('compactDiff', $info)) { |
|
103 | 103 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
104 | 104 | // so we only know that the change *might* affect the constraint statements |
105 | 105 | return true; |
@@ -108,43 +108,43 @@ discard block |
||
108 | 108 | /** @var EntityDiffChangedAspects $aspects */ |
109 | 109 | $aspects = $info['compactDiff']; |
110 | 110 | |
111 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
112 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
111 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
112 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
113 | 113 | } |
114 | 114 | |
115 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
115 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
116 | 116 | $entityContentFactory = WikibaseRepo::getEntityContentFactory(); |
117 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
117 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
118 | 118 | $entityIdLookup = WikibaseRepo::getEntityIdLookup(); |
119 | - $entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
120 | - if ( $entityId !== null ) { |
|
119 | + $entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle()); |
|
120 | + if ($entityId !== null) { |
|
121 | 121 | $resultsCache = ResultsCache::getDefaultInstance(); |
122 | - $resultsCache->delete( $entityId ); |
|
122 | + $resultsCache->delete($entityId); |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
127 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
128 | 128 | $lookup = WikibaseRepo::getEntityNamespaceLookup(); |
129 | 129 | $title = $out->getTitle(); |
130 | - if ( $title === null ) { |
|
130 | + if ($title === null) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
134 | + if (!$lookup->isNamespaceWithEntities($title->getNamespace())) { |
|
135 | 135 | return; |
136 | 136 | } |
137 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
137 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | 140 | |
141 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
141 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
142 | 142 | |
143 | - if ( !$out->getUser()->isRegistered() ) { |
|
143 | + if (!$out->getUser()->isRegistered()) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | |
147 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
147 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | } |
@@ -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 | $services->getJobQueueGroup() |
56 | 56 | ); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | Serializer $snakSerializer, |
119 | 119 | JobQueueGroup $jobQueueGroup |
120 | 120 | ) { |
121 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
121 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
122 | 122 | |
123 | 123 | $this->propertyId = $propertyId; |
124 | 124 | $this->revisionId = $revisionId; |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | $this->jobQueueGroup = $jobQueueGroup; |
131 | 131 | } |
132 | 132 | |
133 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
133 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
134 | 134 | $parameters = []; |
135 | - foreach ( $qualifiers as $qualifier ) { |
|
135 | + foreach ($qualifiers as $qualifier) { |
|
136 | 136 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
137 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
137 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
138 | 138 | $parameters[$qualifierId][] = $paramSerialization; |
139 | 139 | } |
140 | 140 | return $parameters; |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | '@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue'; |
152 | 152 | $entityId = $dataValue->getEntityId(); |
153 | 153 | $constraintTypeQid = $entityId->getSerialization(); |
154 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
154 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
155 | 155 | return new Constraint( |
156 | 156 | $constraintId, |
157 | 157 | $propertyId, |
@@ -166,25 +166,25 @@ discard block |
||
166 | 166 | NumericPropertyId $propertyConstraintPropertyId |
167 | 167 | ) { |
168 | 168 | $constraintsStatements = $property->getStatements() |
169 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
170 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
169 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
170 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
171 | 171 | $constraints = []; |
172 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
172 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
173 | 173 | // @phan-suppress-next-line PhanTypeMismatchArgumentSuperType |
174 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
175 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
176 | - $constraintStore->insertBatch( $constraints ); |
|
174 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
175 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
176 | + $constraintStore->insertBatch($constraints); |
|
177 | 177 | // interrupt transaction and wait for replication |
178 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY ); |
|
179 | - $connection->endAtomic( __CLASS__ ); |
|
180 | - if ( !$connection->explicitTrxActive() ) { |
|
178 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY); |
|
179 | + $connection->endAtomic(__CLASS__); |
|
180 | + if (!$connection->explicitTrxActive()) { |
|
181 | 181 | $this->lbFactory->waitForReplication(); |
182 | 182 | } |
183 | - $connection->startAtomic( __CLASS__ ); |
|
183 | + $connection->startAtomic(__CLASS__); |
|
184 | 184 | $constraints = []; |
185 | 185 | } |
186 | 186 | } |
187 | - $constraintStore->insertBatch( $constraints ); |
|
187 | + $constraintStore->insertBatch($constraints); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -195,24 +195,24 @@ discard block |
||
195 | 195 | public function run() { |
196 | 196 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
197 | 197 | |
198 | - $propertyId = new NumericPropertyId( $this->propertyId ); |
|
198 | + $propertyId = new NumericPropertyId($this->propertyId); |
|
199 | 199 | $propertyRevision = $this->entityRevisionLookup->getEntityRevision( |
200 | 200 | $propertyId, |
201 | 201 | 0, // latest |
202 | 202 | LookupConstants::LATEST_FROM_REPLICA |
203 | 203 | ); |
204 | 204 | |
205 | - if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) { |
|
206 | - $this->jobQueueGroup->push( $this ); |
|
205 | + if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) { |
|
206 | + $this->jobQueueGroup->push($this); |
|
207 | 207 | return true; |
208 | 208 | } |
209 | 209 | |
210 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_PRIMARY ); |
|
210 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_PRIMARY); |
|
211 | 211 | // start transaction (if not started yet) – using __CLASS__, not __METHOD__, |
212 | 212 | // because importConstraintsForProperty() can interrupt the transaction |
213 | - $connection->startAtomic( __CLASS__ ); |
|
213 | + $connection->startAtomic(__CLASS__); |
|
214 | 214 | |
215 | - $this->constraintStore->deleteForProperty( $propertyId ); |
|
215 | + $this->constraintStore->deleteForProperty($propertyId); |
|
216 | 216 | |
217 | 217 | /** @var Property $property */ |
218 | 218 | $property = $propertyRevision->getEntity(); |
@@ -220,10 +220,10 @@ discard block |
||
220 | 220 | $this->importConstraintsForProperty( |
221 | 221 | $property, |
222 | 222 | $this->constraintStore, |
223 | - new NumericPropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
223 | + new NumericPropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
224 | 224 | ); |
225 | 225 | |
226 | - $connection->endAtomic( __CLASS__ ); |
|
226 | + $connection->endAtomic(__CLASS__); |
|
227 | 227 | |
228 | 228 | return true; |
229 | 229 | } |