@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param DatabaseUpdater $updater |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | 32 | $updater->addExtensionTable( |
33 | 33 | 'wbqc_constraints', |
34 | - __DIR__ . '/../sql/create_wbqc_constraints.sql' |
|
34 | + __DIR__.'/../sql/create_wbqc_constraints.sql' |
|
35 | 35 | ); |
36 | 36 | $updater->addExtensionField( |
37 | 37 | 'wbqc_constraints', |
38 | 38 | 'constraint_id', |
39 | - __DIR__ . '/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
39 | + __DIR__.'/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
40 | 40 | ); |
41 | 41 | $updater->addExtensionIndex( |
42 | 42 | 'wbqc_constraints', |
43 | 43 | 'wbqc_constraints_guid_uniq', |
44 | - __DIR__ . '/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
44 | + __DIR__.'/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
45 | 45 | ); |
46 | 46 | } |
47 | 47 | |
48 | - public static function onWikibaseChange( Change $change ) { |
|
49 | - if ( !( $change instanceof EntityChange ) ) { |
|
48 | + public static function onWikibaseChange(Change $change) { |
|
49 | + if (!($change instanceof EntityChange)) { |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
@@ -55,48 +55,48 @@ discard block |
||
55 | 55 | |
56 | 56 | // If jobs are enabled and the results would be stored in some way run a job. |
57 | 57 | if ( |
58 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
59 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
58 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
59 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
60 | 60 | self::isSelectedForJobRunBasedOnPercentage() |
61 | 61 | ) { |
62 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
62 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
63 | 63 | JobQueueGroup::singleton()->push( |
64 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
64 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
65 | 65 | ); |
66 | 66 | } |
67 | 67 | |
68 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
69 | - self::isConstraintStatementsChange( $config, $change ) |
|
68 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
69 | + self::isConstraintStatementsChange($config, $change) |
|
70 | 70 | ) { |
71 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
71 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
72 | 72 | $metadata = $change->getMetadata(); |
73 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
73 | + if (array_key_exists('rev_id', $metadata)) { |
|
74 | 74 | $params['revisionId'] = $metadata['rev_id']; |
75 | 75 | } |
76 | 76 | JobQueueGroup::singleton()->push( |
77 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
77 | + new JobSpecification('constraintsTableUpdate', $params) |
|
78 | 78 | ); |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | 82 | private static function isSelectedForJobRunBasedOnPercentage() { |
83 | 83 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
84 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
84 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
85 | 85 | |
86 | - return mt_rand( 1, 100 ) <= $percentage; |
|
86 | + return mt_rand(1, 100) <= $percentage; |
|
87 | 87 | } |
88 | 88 | |
89 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
90 | - if ( !( $change instanceof EntityChange ) || |
|
89 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
90 | + if (!($change instanceof EntityChange) || |
|
91 | 91 | $change->getAction() !== EntityChange::UPDATE || |
92 | - !( $change->getEntityId() instanceof PropertyId ) |
|
92 | + !($change->getEntityId() instanceof PropertyId) |
|
93 | 93 | ) { |
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
97 | 97 | $info = $change->getInfo(); |
98 | 98 | |
99 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
99 | + if (!array_key_exists('compactDiff', $info)) { |
|
100 | 100 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
101 | 101 | // so we only know that the change *might* affect the constraint statements |
102 | 102 | return true; |
@@ -105,46 +105,46 @@ discard block |
||
105 | 105 | /** @var EntityDiffChangedAspects $aspects */ |
106 | 106 | $aspects = $info['compactDiff']; |
107 | 107 | |
108 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
109 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
108 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
109 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
110 | 110 | } |
111 | 111 | |
112 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
112 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
113 | 113 | $repo = WikibaseRepo::getDefaultInstance(); |
114 | 114 | |
115 | 115 | $entityContentFactory = $repo->getEntityContentFactory(); |
116 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
117 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
118 | - if ( $entityId !== null ) { |
|
116 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
117 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
118 | + if ($entityId !== null) { |
|
119 | 119 | $resultsCache = ResultsCache::getDefaultInstance(); |
120 | - $resultsCache->delete( $entityId ); |
|
120 | + $resultsCache->delete($entityId); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
125 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
126 | 126 | $repo = WikibaseRepo::getDefaultInstance(); |
127 | 127 | |
128 | 128 | $lookup = $repo->getEntityNamespaceLookup(); |
129 | 129 | $title = $out->getTitle(); |
130 | - if ( $title === null ) { |
|
130 | + if ($title === null) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | - if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) { |
|
134 | + if (!$lookup->isEntityNamespace($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()->isLoggedIn() ) { |
|
143 | + if (!$out->getUser()->isLoggedIn()) { |
|
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 | } |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | |
29 | 29 | const BATCH_SIZE = 10; |
30 | 30 | |
31 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
32 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
31 | + public static function newFromGlobalState(Title $title, array $params) { |
|
32 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
33 | 33 | $repo = WikibaseRepo::getDefaultInstance(); |
34 | 34 | return new UpdateConstraintsTableJob( |
35 | 35 | $title, |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $params['revisionId'] ?? null, |
39 | 39 | MediaWikiServices::getInstance()->getMainConfig(), |
40 | 40 | ConstraintsServices::getConstraintRepository(), |
41 | - $repo->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ), |
|
41 | + $repo->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED), |
|
42 | 42 | $repo->getBaseDataModelSerializerFactory()->newSnakSerializer() |
43 | 43 | ); |
44 | 44 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | EntityRevisionLookup $entityRevisionLookup, |
94 | 94 | Serializer $snakSerializer |
95 | 95 | ) { |
96 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
96 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
97 | 97 | |
98 | 98 | $this->propertyId = $propertyId; |
99 | 99 | $this->revisionId = $revisionId; |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | $this->snakSerializer = $snakSerializer; |
104 | 104 | } |
105 | 105 | |
106 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
106 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
107 | 107 | $parameters = []; |
108 | - foreach ( $qualifiers as $qualifier ) { |
|
108 | + foreach ($qualifiers as $qualifier) { |
|
109 | 109 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
110 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
110 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
111 | 111 | $parameters[$qualifierId][] = $paramSerialization; |
112 | 112 | } |
113 | 113 | return $parameters; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | ) { |
120 | 120 | $constraintId = $constraintStatement->getGuid(); |
121 | 121 | $constraintTypeQid = $constraintStatement->getMainSnak()->getDataValue()->getEntityId()->getSerialization(); |
122 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
122 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
123 | 123 | return new Constraint( |
124 | 124 | $constraintId, |
125 | 125 | $propertyId, |
@@ -134,17 +134,17 @@ discard block |
||
134 | 134 | PropertyId $propertyConstraintPropertyId |
135 | 135 | ) { |
136 | 136 | $constraintsStatements = $property->getStatements() |
137 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
138 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
137 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
138 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
139 | 139 | $constraints = []; |
140 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
141 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
142 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
143 | - $constraintRepo->insertBatch( $constraints ); |
|
140 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
141 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
142 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
143 | + $constraintRepo->insertBatch($constraints); |
|
144 | 144 | $constraints = []; |
145 | 145 | } |
146 | 146 | } |
147 | - $constraintRepo->insertBatch( $constraints ); |
|
147 | + $constraintRepo->insertBatch($constraints); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -155,26 +155,26 @@ discard block |
||
155 | 155 | public function run() { |
156 | 156 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
157 | 157 | |
158 | - $propertyId = new PropertyId( $this->propertyId ); |
|
158 | + $propertyId = new PropertyId($this->propertyId); |
|
159 | 159 | $propertyRevision = $this->entityRevisionLookup->getEntityRevision( |
160 | 160 | $propertyId, |
161 | 161 | 0, // latest |
162 | 162 | EntityRevisionLookup::LATEST_FROM_REPLICA |
163 | 163 | ); |
164 | 164 | |
165 | - if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) { |
|
166 | - JobQueueGroup::singleton()->push( $this ); |
|
165 | + if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) { |
|
166 | + JobQueueGroup::singleton()->push($this); |
|
167 | 167 | return true; |
168 | 168 | } |
169 | 169 | |
170 | - $this->constraintRepo->deleteForPropertyWhereConstraintIdIsStatementId( $propertyId ); |
|
170 | + $this->constraintRepo->deleteForPropertyWhereConstraintIdIsStatementId($propertyId); |
|
171 | 171 | |
172 | 172 | /** @var Property $property */ |
173 | 173 | $property = $propertyRevision->getEntity(); |
174 | 174 | $this->importConstraintsForProperty( |
175 | 175 | $property, |
176 | 176 | $this->constraintRepo, |
177 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
177 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
178 | 178 | ); |
179 | 179 | |
180 | 180 | return true; |