@@ -24,22 +24,22 @@ |
||
24 | 24 | */ |
25 | 25 | private const NULL_PROPERTY_ID = 'P2147483647'; |
26 | 26 | |
27 | - public function __construct( ContextCursor $contextCursor ) { |
|
27 | + public function __construct(ContextCursor $contextCursor) { |
|
28 | 28 | $constraint = new Constraint( |
29 | 29 | 'null', |
30 | - new PropertyId( self::NULL_PROPERTY_ID ), |
|
30 | + new PropertyId(self::NULL_PROPERTY_ID), |
|
31 | 31 | 'none', |
32 | 32 | [] |
33 | 33 | ); |
34 | - parent::__construct( $contextCursor, $constraint ); |
|
34 | + parent::__construct($contextCursor, $constraint); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function getConstraint() { |
38 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
38 | + throw new DomainException('NullResult holds no constraint'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public function getConstraintId() { |
42 | - throw new DomainException( 'NullResult holds no constraint' ); |
|
42 | + throw new DomainException('NullResult holds no constraint'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | } |
@@ -20,35 +20,35 @@ |
||
20 | 20 | public const PROPERTY_DATA_TYPE_LOOKUP = 'WBQC_PropertyDataTypeLookup'; |
21 | 21 | public const ENTITY_LOOKUP_WITHOUT_CACHE = 'WBQC_EntityLookupWithoutCache'; |
22 | 22 | |
23 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
24 | - if ( $services === null ) { |
|
23 | + private static function getService(?MediaWikiServices $services, $name) { |
|
24 | + if ($services === null) { |
|
25 | 25 | $services = MediaWikiServices::getInstance(); |
26 | 26 | } |
27 | - return $services->getService( $name ); |
|
27 | + return $services->getService($name); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @param MediaWikiServices|null $services |
32 | 32 | * @return EntityLookup |
33 | 33 | */ |
34 | - public static function getEntityLookup( MediaWikiServices $services = null ) { |
|
35 | - return self::getService( $services, self::ENTITY_LOOKUP ); |
|
34 | + public static function getEntityLookup(MediaWikiServices $services = null) { |
|
35 | + return self::getService($services, self::ENTITY_LOOKUP); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @param MediaWikiServices|null $services |
40 | 40 | * @return PropertyDataTypeLookup |
41 | 41 | */ |
42 | - public static function getPropertyDataTypeLookup( MediaWikiServices $services = null ) { |
|
43 | - return self::getService( $services, self::PROPERTY_DATA_TYPE_LOOKUP ); |
|
42 | + public static function getPropertyDataTypeLookup(MediaWikiServices $services = null) { |
|
43 | + return self::getService($services, self::PROPERTY_DATA_TYPE_LOOKUP); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param MediaWikiServices|null $services |
48 | 48 | * @return EntityLookup |
49 | 49 | */ |
50 | - public static function getEntityLookupWithoutCache( MediaWikiServices $services = null ) { |
|
51 | - return self::getService( $services, self::ENTITY_LOOKUP_WITHOUT_CACHE ); |
|
50 | + public static function getEntityLookupWithoutCache(MediaWikiServices $services = null) { |
|
51 | + return self::getService($services, self::ENTITY_LOOKUP_WITHOUT_CACHE); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | * @param ViolationMessage $violationMessage |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - public function render( ViolationMessage $violationMessage ) { |
|
58 | - if ( !array_key_exists( $violationMessage->getMessageKey(), $this->alternativeMessageKeys ) ) { |
|
59 | - return parent::render( $violationMessage ); |
|
57 | + public function render(ViolationMessage $violationMessage) { |
|
58 | + if (!array_key_exists($violationMessage->getMessageKey(), $this->alternativeMessageKeys)) { |
|
59 | + return parent::render($violationMessage); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $arguments = $violationMessage->getArguments(); |
63 | - $multilingualTextArgument = array_pop( $arguments ); |
|
63 | + $multilingualTextArgument = array_pop($arguments); |
|
64 | 64 | $multilingualTextParams = $this->renderMultilingualText( |
65 | 65 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable TODO Ensure this is not an actual issue |
66 | 66 | $multilingualTextArgument['value'], |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | $multilingualTextArgument['role'] |
69 | 69 | ); |
70 | 70 | |
71 | - $paramsLists = [ [] ]; |
|
72 | - foreach ( $arguments as $argument ) { |
|
73 | - $paramsLists[] = $this->renderArgument( $argument ); |
|
71 | + $paramsLists = [[]]; |
|
72 | + foreach ($arguments as $argument) { |
|
73 | + $paramsLists[] = $this->renderArgument($argument); |
|
74 | 74 | } |
75 | - $regularParams = call_user_func_array( 'array_merge', $paramsLists ); |
|
75 | + $regularParams = call_user_func_array('array_merge', $paramsLists); |
|
76 | 76 | |
77 | - if ( $multilingualTextParams === null ) { |
|
77 | + if ($multilingualTextParams === null) { |
|
78 | 78 | return $this->messageLocalizer |
79 | - ->msg( $this->alternativeMessageKeys[$violationMessage->getMessageKey()] ) |
|
80 | - ->params( $regularParams ) |
|
79 | + ->msg($this->alternativeMessageKeys[$violationMessage->getMessageKey()]) |
|
80 | + ->params($regularParams) |
|
81 | 81 | ->escaped(); |
82 | 82 | } else { |
83 | 83 | return $this->messageLocalizer |
84 | - ->msg( $violationMessage->getMessageKey() ) |
|
85 | - ->params( $regularParams ) |
|
86 | - ->params( $multilingualTextParams ) |
|
84 | + ->msg($violationMessage->getMessageKey()) |
|
85 | + ->params($regularParams) |
|
86 | + ->params($multilingualTextParams) |
|
87 | 87 | ->escaped(); |
88 | 88 | } |
89 | 89 | } |
@@ -94,18 +94,18 @@ discard block |
||
94 | 94 | * @return array[]|null list of parameters as accepted by Message::params(), |
95 | 95 | * or null if the text is not available in the user’s language |
96 | 96 | */ |
97 | - protected function renderMultilingualText( MultilingualTextValue $text, $role ) { |
|
97 | + protected function renderMultilingualText(MultilingualTextValue $text, $role) { |
|
98 | 98 | global $wgLang; |
99 | 99 | $languageCodes = $wgLang->getFallbackLanguages(); |
100 | - array_unshift( $languageCodes, $wgLang->getCode() ); |
|
100 | + array_unshift($languageCodes, $wgLang->getCode()); |
|
101 | 101 | |
102 | 102 | $texts = $text->getTexts(); |
103 | - foreach ( $languageCodes as $languageCode ) { |
|
104 | - if ( array_key_exists( $languageCode, $texts ) ) { |
|
105 | - return [ Message::rawParam( $this->addRole( |
|
106 | - htmlspecialchars( $texts[$languageCode]->getText() ), |
|
103 | + foreach ($languageCodes as $languageCode) { |
|
104 | + if (array_key_exists($languageCode, $texts)) { |
|
105 | + return [Message::rawParam($this->addRole( |
|
106 | + htmlspecialchars($texts[$languageCode]->getText()), |
|
107 | 107 | $role |
108 | - ) ) ]; |
|
108 | + ))]; |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param WANObjectCache $cache |
37 | 37 | * @param string $formatVersion The version of the API response format. |
38 | 38 | */ |
39 | - public function __construct( WANObjectCache $cache, $formatVersion ) { |
|
39 | + public function __construct(WANObjectCache $cache, $formatVersion) { |
|
40 | 40 | $this->cache = $cache; |
41 | 41 | $this->formatVersion = $formatVersion; |
42 | 42 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param EntityId $entityId |
46 | 46 | * @return string cache key |
47 | 47 | */ |
48 | - public function makeKey( EntityId $entityId ) { |
|
48 | + public function makeKey(EntityId $entityId) { |
|
49 | 49 | return $this->cache->makeKey( |
50 | 50 | 'WikibaseQualityConstraints', // extension |
51 | 51 | 'checkConstraints', // action |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param mixed|null &$info |
62 | 62 | * @return mixed |
63 | 63 | */ |
64 | - public function get( EntityId $key, &$curTTL = null, array $checkKeys = [], &$info = null ) { |
|
65 | - return $this->cache->get( $this->makeKey( $key ), $curTTL, $checkKeys, $info ); |
|
64 | + public function get(EntityId $key, &$curTTL = null, array $checkKeys = [], &$info = null) { |
|
65 | + return $this->cache->get($this->makeKey($key), $curTTL, $checkKeys, $info); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -72,16 +72,16 @@ discard block |
||
72 | 72 | * @param array $opts |
73 | 73 | * @return bool |
74 | 74 | */ |
75 | - public function set( EntityId $key, $value, $ttl = 0, array $opts = [] ) { |
|
76 | - return $this->cache->set( $this->makeKey( $key ), $value, $ttl, $opts ); |
|
75 | + public function set(EntityId $key, $value, $ttl = 0, array $opts = []) { |
|
76 | + return $this->cache->set($this->makeKey($key), $value, $ttl, $opts); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @param EntityId $key |
81 | 81 | * @return bool |
82 | 82 | */ |
83 | - public function delete( EntityId $key ) { |
|
84 | - return $this->cache->delete( $this->makeKey( $key ) ); |
|
83 | + public function delete(EntityId $key) { |
|
84 | + return $this->cache->delete($this->makeKey($key)); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | } |
@@ -28,27 +28,27 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param DatabaseUpdater $updater |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
32 | - $dir = dirname( __DIR__ ) . '/sql/'; |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | + $dir = dirname(__DIR__).'/sql/'; |
|
33 | 33 | |
34 | 34 | $updater->addExtensionTable( |
35 | 35 | 'wbqc_constraints', |
36 | - $dir . "/{$updater->getDB()->getType()}/tables-generated.sql" |
|
36 | + $dir."/{$updater->getDB()->getType()}/tables-generated.sql" |
|
37 | 37 | ); |
38 | 38 | $updater->addExtensionField( |
39 | 39 | 'wbqc_constraints', |
40 | 40 | 'constraint_id', |
41 | - $dir . '/patch-wbqc_constraints-constraint_id.sql' |
|
41 | + $dir.'/patch-wbqc_constraints-constraint_id.sql' |
|
42 | 42 | ); |
43 | 43 | $updater->addExtensionIndex( |
44 | 44 | 'wbqc_constraints', |
45 | 45 | 'wbqc_constraints_guid_uniq', |
46 | - $dir . '/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
46 | + $dir.'/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
50 | - public static function onWikibaseChange( Change $change ) { |
|
51 | - if ( !( $change instanceof EntityChange ) ) { |
|
50 | + public static function onWikibaseChange(Change $change) { |
|
51 | + if (!($change instanceof EntityChange)) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
@@ -57,48 +57,48 @@ discard block |
||
57 | 57 | |
58 | 58 | // If jobs are enabled and the results would be stored in some way run a job. |
59 | 59 | if ( |
60 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
61 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
60 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
61 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
62 | 62 | self::isSelectedForJobRunBasedOnPercentage() |
63 | 63 | ) { |
64 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
64 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
65 | 65 | JobQueueGroup::singleton()->lazyPush( |
66 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
66 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
70 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
71 | - self::isConstraintStatementsChange( $config, $change ) |
|
70 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
71 | + self::isConstraintStatementsChange($config, $change) |
|
72 | 72 | ) { |
73 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
73 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
74 | 74 | $metadata = $change->getMetadata(); |
75 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
75 | + if (array_key_exists('rev_id', $metadata)) { |
|
76 | 76 | $params['revisionId'] = $metadata['rev_id']; |
77 | 77 | } |
78 | 78 | JobQueueGroup::singleton()->push( |
79 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
79 | + new JobSpecification('constraintsTableUpdate', $params) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | 84 | private static function isSelectedForJobRunBasedOnPercentage() { |
85 | 85 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
86 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
86 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
87 | 87 | |
88 | - return mt_rand( 1, 100 ) <= $percentage; |
|
88 | + return mt_rand(1, 100) <= $percentage; |
|
89 | 89 | } |
90 | 90 | |
91 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
92 | - if ( !( $change instanceof EntityChange ) || |
|
91 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
92 | + if (!($change instanceof EntityChange) || |
|
93 | 93 | $change->getAction() !== EntityChange::UPDATE || |
94 | - !( $change->getEntityId() instanceof PropertyId ) |
|
94 | + !($change->getEntityId() instanceof PropertyId) |
|
95 | 95 | ) { |
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | 99 | $info = $change->getInfo(); |
100 | 100 | |
101 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
101 | + if (!array_key_exists('compactDiff', $info)) { |
|
102 | 102 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
103 | 103 | // so we only know that the change *might* affect the constraint statements |
104 | 104 | return true; |
@@ -107,43 +107,43 @@ discard block |
||
107 | 107 | /** @var EntityDiffChangedAspects $aspects */ |
108 | 108 | $aspects = $info['compactDiff']; |
109 | 109 | |
110 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
111 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
110 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
111 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
112 | 112 | } |
113 | 113 | |
114 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
114 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
115 | 115 | $entityContentFactory = WikibaseRepo::getEntityContentFactory(); |
116 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
116 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
117 | 117 | $entityIdLookup = WikibaseRepo::getEntityIdLookup(); |
118 | - $entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
119 | - if ( $entityId !== null ) { |
|
118 | + $entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle()); |
|
119 | + if ($entityId !== null) { |
|
120 | 120 | $resultsCache = ResultsCache::getDefaultInstance(); |
121 | - $resultsCache->delete( $entityId ); |
|
121 | + $resultsCache->delete($entityId); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
126 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
127 | 127 | $lookup = WikibaseRepo::getEntityNamespaceLookup(); |
128 | 128 | $title = $out->getTitle(); |
129 | - if ( $title === null ) { |
|
129 | + if ($title === null) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
133 | + if (!$lookup->isNamespaceWithEntities($title->getNamespace())) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
136 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | |
140 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
140 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
141 | 141 | |
142 | - if ( !$out->getUser()->isRegistered() ) { |
|
142 | + if (!$out->getUser()->isRegistered()) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | 145 | |
146 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
146 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | } |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | use Wikibase\Repo\WikibaseRepo; |
18 | 18 | |
19 | 19 | // @codeCoverageIgnoreStart |
20 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
21 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
20 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
21 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
22 | 22 | |
23 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
23 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
24 | 24 | // @codeCoverageIgnoreEnd |
25 | 25 | |
26 | 26 | /** |
@@ -59,20 +59,20 @@ discard block |
||
59 | 59 | parent::__construct(); |
60 | 60 | |
61 | 61 | $this->addDescription( |
62 | - 'Import entities needed for constraint checks ' . |
|
62 | + 'Import entities needed for constraint checks '. |
|
63 | 63 | 'from Wikidata into the local repository.' |
64 | 64 | ); |
65 | 65 | $this->addOption( |
66 | 66 | 'config-format', |
67 | - 'The format in which the resulting configuration will be omitted: ' . |
|
68 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
67 | + 'The format in which the resulting configuration will be omitted: '. |
|
68 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
69 | 69 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
70 | 70 | ); |
71 | 71 | $this->addOption( |
72 | 72 | 'dry-run', |
73 | 73 | 'Don’t actually import entities, just print which ones would be imported.' |
74 | 74 | ); |
75 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
75 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | */ |
81 | 81 | private function setupServices() { |
82 | 82 | $services = MediaWikiServices::getInstance(); |
83 | - $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer( $services ); |
|
84 | - $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer( $services ); |
|
85 | - $this->entityStore = WikibaseRepo::getEntityStore( $services ); |
|
83 | + $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer($services); |
|
84 | + $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer($services); |
|
85 | + $this->entityStore = WikibaseRepo::getEntityStore($services); |
|
86 | 86 | $this->httpRequestFactory = $services->getHttpRequestFactory(); |
87 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
88 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
87 | + if (!$this->getOption('dry-run', false)) { |
|
88 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -94,21 +94,21 @@ discard block |
||
94 | 94 | |
95 | 95 | $configUpdates = []; |
96 | 96 | |
97 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
98 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
99 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
97 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
98 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
99 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
100 | 100 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
101 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
101 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
102 | 102 | |
103 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
104 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
103 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
104 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
105 | 105 | $configUpdates[$key] = [ |
106 | 106 | 'wikidata' => $wikidataEntityId, |
107 | 107 | 'local' => $localEntityId, |
108 | 108 | ]; |
109 | 109 | } |
110 | 110 | |
111 | - $this->outputConfigUpdates( $configUpdates ); |
|
111 | + $this->outputConfigUpdates($configUpdates); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,18 +116,18 @@ discard block |
||
116 | 116 | * @param Config $wikiConfig |
117 | 117 | * @return string[] |
118 | 118 | */ |
119 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
119 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
120 | 120 | $wikidataEntityIds = []; |
121 | 121 | |
122 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
123 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
122 | + foreach ($extensionJsonConfig as $key => $value) { |
|
123 | + if (!preg_match('/Id$/', $key)) { |
|
124 | 124 | continue; |
125 | 125 | } |
126 | 126 | |
127 | 127 | $wikidataEntityId = $value['value']; |
128 | - $localEntityId = $wikiConfig->get( $key ); |
|
128 | + $localEntityId = $wikiConfig->get($key); |
|
129 | 129 | |
130 | - if ( $localEntityId === $wikidataEntityId ) { |
|
130 | + if ($localEntityId === $wikidataEntityId) { |
|
131 | 131 | $wikidataEntityIds[$key] = $wikidataEntityId; |
132 | 132 | } |
133 | 133 | } |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | * @param string $wikidataEntityId |
140 | 140 | * @return string local entity ID |
141 | 141 | */ |
142 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
142 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
143 | 143 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
144 | - $wikidataEntitiesJson = $this->httpRequestFactory->get( $wikidataEntityUrl, [], __METHOD__ ); |
|
145 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
144 | + $wikidataEntitiesJson = $this->httpRequestFactory->get($wikidataEntityUrl, [], __METHOD__); |
|
145 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -150,24 +150,24 @@ discard block |
||
150 | 150 | * @param string $wikidataEntitiesJson |
151 | 151 | * @return string local entity ID |
152 | 152 | */ |
153 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
153 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
154 | 154 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
155 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
156 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
155 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
156 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
157 | 157 | |
158 | - $wikidataEntity->setId( null ); |
|
158 | + $wikidataEntity->setId(null); |
|
159 | 159 | |
160 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
160 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
161 | 161 | $wikidataEntity->getStatements()->clear(); |
162 | 162 | } |
163 | 163 | |
164 | - if ( $wikidataEntity instanceof Item ) { |
|
165 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
164 | + if ($wikidataEntity instanceof Item) { |
|
165 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
166 | 166 | } |
167 | 167 | |
168 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
169 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
170 | - $this->output( $wikidataEntityJson . "\n" ); |
|
168 | + if ($this->getOption('dry-run', false)) { |
|
169 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
170 | + $this->output($wikidataEntityJson."\n"); |
|
171 | 171 | return "-$wikidataEntityId"; |
172 | 172 | } |
173 | 173 | |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | )->getEntity(); |
181 | 181 | |
182 | 182 | return $localEntity->getId()->getSerialization(); |
183 | - } catch ( StorageException $storageException ) { |
|
184 | - return $this->storageExceptionToEntityId( $storageException ); |
|
183 | + } catch (StorageException $storageException) { |
|
184 | + return $this->storageExceptionToEntityId($storageException); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - private function storageExceptionToEntityId( StorageException $storageException ) { |
|
188 | + private function storageExceptionToEntityId(StorageException $storageException) { |
|
189 | 189 | $message = $storageException->getMessage(); |
190 | 190 | // example messages: |
191 | 191 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -195,25 +195,25 @@ discard block |
||
195 | 195 | // * Property [[Property:P694|P694]] already has label "instance of" |
196 | 196 | // associated with language code en. |
197 | 197 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
198 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
198 | + if (preg_match($pattern, $message, $matches)) { |
|
199 | 199 | return $matches[1]; |
200 | 200 | } else { |
201 | 201 | throw $storageException; |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - private function outputConfigUpdates( array $configUpdates ) { |
|
206 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
207 | - switch ( $configFormat ) { |
|
205 | + private function outputConfigUpdates(array $configUpdates) { |
|
206 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
207 | + switch ($configFormat) { |
|
208 | 208 | case 'globals': |
209 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
209 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
210 | 210 | break; |
211 | 211 | case 'wgConf': |
212 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
212 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
213 | 213 | break; |
214 | 214 | default: |
215 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
216 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
215 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
216 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
217 | 217 | break; |
218 | 218 | } |
219 | 219 | } |
@@ -221,22 +221,22 @@ discard block |
||
221 | 221 | /** |
222 | 222 | * @param array[] $configUpdates |
223 | 223 | */ |
224 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
225 | - foreach ( $configUpdates as $key => $value ) { |
|
226 | - $localValueCode = var_export( $value['local'], true ); |
|
227 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
224 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
225 | + foreach ($configUpdates as $key => $value) { |
|
226 | + $localValueCode = var_export($value['local'], true); |
|
227 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
232 | 232 | * @param array[] $configUpdates |
233 | 233 | */ |
234 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
235 | - foreach ( $configUpdates as $key => $value ) { |
|
236 | - $keyCode = var_export( "wg$key", true ); |
|
237 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
238 | - $localValueCode = var_export( $value['local'], true ); |
|
239 | - $wikiIdCode = var_export( wfWikiID(), true ); |
|
234 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
235 | + foreach ($configUpdates as $key => $value) { |
|
236 | + $keyCode = var_export("wg$key", true); |
|
237 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
238 | + $localValueCode = var_export($value['local'], true); |
|
239 | + $wikiIdCode = var_export(wfWikiID(), true); |
|
240 | 240 | $block = <<< EOF |
241 | 241 | $keyCode => [ |
242 | 242 | 'default' => $wikidataValueCode, |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | |
246 | 246 | |
247 | 247 | EOF; |
248 | - $this->output( $block ); |
|
248 | + $this->output($block); |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @codeCoverageIgnore This method is purely declarative. |
80 | 80 | */ |
81 | 81 | public function getDefaultContextTypes() { |
82 | - return [ Context::TYPE_STATEMENT ]; |
|
82 | + return [Context::TYPE_STATEMENT]; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -91,31 +91,31 @@ discard block |
||
91 | 91 | * @return CheckResult |
92 | 92 | * @throws \ConfigException |
93 | 93 | */ |
94 | - public function checkConstraint( Context $context, Constraint $constraint ) { |
|
95 | - if ( $context->getSnakRank() === Statement::RANK_DEPRECATED ) { |
|
96 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_DEPRECATED ); |
|
94 | + public function checkConstraint(Context $context, Constraint $constraint) { |
|
95 | + if ($context->getSnakRank() === Statement::RANK_DEPRECATED) { |
|
96 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_DEPRECATED); |
|
97 | 97 | } |
98 | 98 | $snak = $context->getSnak(); |
99 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
99 | + if (!$snak instanceof PropertyValueSnak) { |
|
100 | 100 | // nothing to check |
101 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_COMPLIANCE ); |
|
101 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_COMPLIANCE); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $dataValue = $snak->getDataValue(); |
105 | - if ( !$dataValue instanceof EntityIdValue ) { |
|
105 | + if (!$dataValue instanceof EntityIdValue) { |
|
106 | 106 | // wrong data type |
107 | - $message = ( new ViolationMessage( 'wbqc-violation-message-value-needed-of-type' ) ) |
|
108 | - ->withEntityId( new ItemId( $constraint->getConstraintTypeItemId() ), Role::CONSTRAINT_TYPE_ITEM ) |
|
109 | - ->withDataValueType( 'wikibase-entityid' ); |
|
110 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
107 | + $message = (new ViolationMessage('wbqc-violation-message-value-needed-of-type')) |
|
108 | + ->withEntityId(new ItemId($constraint->getConstraintTypeItemId()), Role::CONSTRAINT_TYPE_ITEM) |
|
109 | + ->withDataValueType('wikibase-entityid'); |
|
110 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $objectId = $dataValue->getEntityId(); |
114 | - $objectItem = $this->entityLookup->getEntity( $objectId ); |
|
115 | - if ( !( $objectItem instanceof StatementListProvider ) ) { |
|
114 | + $objectItem = $this->entityLookup->getEntity($objectId); |
|
115 | + if (!($objectItem instanceof StatementListProvider)) { |
|
116 | 116 | // object was deleted/doesn't exist |
117 | - $message = new ViolationMessage( 'wbqc-violation-message-value-entity-must-exist' ); |
|
118 | - return new CheckResult( $context, $constraint, [], CheckResult::STATUS_VIOLATION, $message ); |
|
117 | + $message = new ViolationMessage('wbqc-violation-message-value-entity-must-exist'); |
|
118 | + return new CheckResult($context, $constraint, [], CheckResult::STATUS_VIOLATION, $message); |
|
119 | 119 | } |
120 | 120 | /** @var Statement[] $objectStatements */ |
121 | 121 | $objectStatements = $objectItem->getStatements()->toArray(); |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | $subjectId = $context->getEntity()->getId(); |
124 | 124 | $subjectStatements = $context->getEntity()->getStatements()->toArray(); |
125 | 125 | /** @var String[] $startPropertyIds */ |
126 | - $startPropertyIds = $this->config->get( self::CONFIG_VARIABLE_START_PROPERTY_IDS ); |
|
126 | + $startPropertyIds = $this->config->get(self::CONFIG_VARIABLE_START_PROPERTY_IDS); |
|
127 | 127 | /** @var String[] $endPropertyIds */ |
128 | - $endPropertyIds = $this->config->get( self::CONFIG_VARIABLE_END_PROPERTY_IDS ); |
|
128 | + $endPropertyIds = $this->config->get(self::CONFIG_VARIABLE_END_PROPERTY_IDS); |
|
129 | 129 | $subjectStartValue = $this->getExtremeValue( |
130 | 130 | $startPropertyIds, |
131 | 131 | $subjectStatements, |
@@ -147,15 +147,15 @@ discard block |
||
147 | 147 | 'end' |
148 | 148 | ); |
149 | 149 | if ( |
150 | - $this->rangeCheckerHelper->getComparison( $subjectStartValue, $subjectEndValue ) <= 0 && |
|
151 | - $this->rangeCheckerHelper->getComparison( $objectStartValue, $objectEndValue ) <= 0 && ( |
|
152 | - $this->rangeCheckerHelper->getComparison( $subjectEndValue, $objectStartValue ) < 0 || |
|
153 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectStartValue ) < 0 |
|
150 | + $this->rangeCheckerHelper->getComparison($subjectStartValue, $subjectEndValue) <= 0 && |
|
151 | + $this->rangeCheckerHelper->getComparison($objectStartValue, $objectEndValue) <= 0 && ( |
|
152 | + $this->rangeCheckerHelper->getComparison($subjectEndValue, $objectStartValue) < 0 || |
|
153 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectStartValue) < 0 |
|
154 | 154 | ) |
155 | 155 | ) { |
156 | 156 | if ( |
157 | 157 | $subjectEndValue == null || |
158 | - $this->rangeCheckerHelper->getComparison( $objectEndValue, $subjectEndValue ) < 0 |
|
158 | + $this->rangeCheckerHelper->getComparison($objectEndValue, $subjectEndValue) < 0 |
|
159 | 159 | ) { |
160 | 160 | $earlierEntityId = $objectId; |
161 | 161 | $minEndValue = $objectEndValue; |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $message = null; |
179 | 179 | $status = CheckResult::STATUS_COMPLIANCE; |
180 | 180 | } |
181 | - return new CheckResult( $context, $constraint, [], $status, $message ); |
|
181 | + return new CheckResult($context, $constraint, [], $status, $message); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -188,19 +188,19 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @return DataValue|null |
190 | 190 | */ |
191 | - private function getExtremeValue( $extremePropertyIds, $statements, $startOrEnd ) { |
|
192 | - if ( $startOrEnd !== 'start' && $startOrEnd !== 'end' ) { |
|
193 | - throw new \InvalidArgumentException( '$startOrEnd must be \'start\' or \'end\'.' ); |
|
191 | + private function getExtremeValue($extremePropertyIds, $statements, $startOrEnd) { |
|
192 | + if ($startOrEnd !== 'start' && $startOrEnd !== 'end') { |
|
193 | + throw new \InvalidArgumentException('$startOrEnd must be \'start\' or \'end\'.'); |
|
194 | 194 | } |
195 | 195 | $extremeValue = null; |
196 | - foreach ( $extremePropertyIds as $extremePropertyId ) { |
|
197 | - $statementList = new StatementList( ...$statements ); |
|
198 | - $extremeStatements = $statementList->getByPropertyId( new PropertyId( $extremePropertyId ) ); |
|
196 | + foreach ($extremePropertyIds as $extremePropertyId) { |
|
197 | + $statementList = new StatementList(...$statements); |
|
198 | + $extremeStatements = $statementList->getByPropertyId(new PropertyId($extremePropertyId)); |
|
199 | 199 | /** @var Statement $extremeStatement */ |
200 | - foreach ( $extremeStatements as $extremeStatement ) { |
|
201 | - if ( $extremeStatement->getRank() !== Statement::RANK_DEPRECATED ) { |
|
200 | + foreach ($extremeStatements as $extremeStatement) { |
|
201 | + if ($extremeStatement->getRank() !== Statement::RANK_DEPRECATED) { |
|
202 | 202 | $snak = $extremeStatement->getMainSnak(); |
203 | - if ( !$snak instanceof PropertyValueSnak ) { |
|
203 | + if (!$snak instanceof PropertyValueSnak) { |
|
204 | 204 | return null; |
205 | 205 | } else { |
206 | 206 | $comparison = $this->rangeCheckerHelper->getComparison( |
@@ -209,8 +209,8 @@ discard block |
||
209 | 209 | ); |
210 | 210 | if ( |
211 | 211 | $extremeValue === null || |
212 | - ( $startOrEnd === 'start' && $comparison < 0 ) || |
|
213 | - ( $startOrEnd === 'end' && $comparison > 0 ) |
|
212 | + ($startOrEnd === 'start' && $comparison < 0) || |
|
213 | + ($startOrEnd === 'end' && $comparison > 0) |
|
214 | 214 | ) { |
215 | 215 | $extremeValue = $snak->getDataValue(); |
216 | 216 | } |
@@ -240,17 +240,16 @@ discard block |
||
240 | 240 | DataValue $maxStartValue |
241 | 241 | ) { |
242 | 242 | $messageKey = $earlierEntityId === $subjectId ? |
243 | - 'wbqc-violation-message-contemporary-subject-earlier' : |
|
244 | - 'wbqc-violation-message-contemporary-value-earlier'; |
|
245 | - return ( new ViolationMessage( $messageKey ) ) |
|
246 | - ->withEntityId( $subjectId, Role::SUBJECT ) |
|
247 | - ->withEntityId( $propertyId, Role::PREDICATE ) |
|
248 | - ->withEntityId( $objectId, Role::OBJECT ) |
|
249 | - ->withDataValue( $minEndValue, Role::OBJECT ) |
|
250 | - ->withDataValue( $maxStartValue, Role::OBJECT ); |
|
243 | + 'wbqc-violation-message-contemporary-subject-earlier' : 'wbqc-violation-message-contemporary-value-earlier'; |
|
244 | + return (new ViolationMessage($messageKey)) |
|
245 | + ->withEntityId($subjectId, Role::SUBJECT) |
|
246 | + ->withEntityId($propertyId, Role::PREDICATE) |
|
247 | + ->withEntityId($objectId, Role::OBJECT) |
|
248 | + ->withDataValue($minEndValue, Role::OBJECT) |
|
249 | + ->withDataValue($maxStartValue, Role::OBJECT); |
|
251 | 250 | } |
252 | 251 | |
253 | - public function checkConstraintParameters( Constraint $constraint ) { |
|
252 | + public function checkConstraintParameters(Constraint $constraint) { |
|
254 | 253 | // no parameters |
255 | 254 | return []; |
256 | 255 | } |
@@ -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_MASTER ); |
|
169 | - $connection->endAtomic( __CLASS__ ); |
|
170 | - if ( !$connection->explicitTrxActive() ) { |
|
168 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_MASTER); |
|
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_MASTER ); |
|
200 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_MASTER); |
|
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 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\Api; |
6 | 6 | |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | $this->violationMessageRendererFactory = $violationMessageRendererFactory; |
34 | 34 | } |
35 | 35 | |
36 | - public function getCheckResultsRenderer( Language $language ): CheckResultsRenderer { |
|
36 | + public function getCheckResultsRenderer(Language $language): CheckResultsRenderer { |
|
37 | 37 | return new CheckResultsRenderer( |
38 | 38 | $this->entityTitleLookup, |
39 | 39 | $this->entityIdLabelFormatterFactory |
40 | - ->getEntityIdFormatter( $language ), |
|
40 | + ->getEntityIdFormatter($language), |
|
41 | 41 | $this->violationMessageRendererFactory |
42 | - ->getViolationMessageRenderer( $language ) |
|
42 | + ->getViolationMessageRenderer($language) |
|
43 | 43 | ); |
44 | 44 | } |
45 | 45 |