Skip to content

Commit

Permalink
Merge "Use term type constants in DatabaseSchemaUpdater"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Jan 24, 2025
2 parents 70cbfa0 + cc4c4fa commit a05d29c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions repo/includes/Store/Sql/DatabaseSchemaUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Services\Lookup\LegacyAdapterItemLookup;
use Wikibase\DataModel\Services\Lookup\LegacyAdapterPropertyLookup;
use Wikibase\DataModel\Term\TermTypes;
use Wikibase\Lib\Store\Sql\Terms\TermTypeIds;
use Wikibase\Repo\RangeTraversable;
use Wikibase\Repo\Store\ItemTermsRebuilder;
use Wikibase\Repo\Store\PropertyTermsRebuilder;
Expand Down Expand Up @@ -324,27 +326,26 @@ private function sanitizeTermTypeIds( DatabaseUpdater $updater ): void {
return;
}

$sanitizedTypeIds = [ 'label' => 1, 'description' => 2, 'alias' => 3 ];
$currentTypeIds = $this->getCurrentTermTypeIds( $db );
if ( $currentTypeIds == $sanitizedTypeIds ) {
if ( $currentTypeIds == TermTypeIds::TYPE_IDS ) {
return;
}

$updater->output( "...sanitizing Wikibase term type IDs.\n" );

// setting temporary IDs so that they don't get mixed up
$tmpTypeIds = [ 'label' => 101, 'description' => 102, 'alias' => 103 ];
$tmpTypeIds = [ TermTypes::TYPE_LABEL => 101, TermTypes::TYPE_DESCRIPTION => 102, TermTypes::TYPE_ALIAS => 103 ];
foreach ( $currentTypeIds as $type => $currentId ) {
if ( $currentId !== $sanitizedTypeIds[$type] ) {
if ( $currentId !== TermTypeIds::TYPE_IDS[$type] ) {
$updater->output( "...setting temporary Wikibase $type IDs.\n" );
$this->updateTermTypeId( $db, $currentId, $tmpTypeIds[$type] );
}
}

// update to final type IDs
foreach ( [ 'label', 'description', 'alias' ] as $type ) {
foreach ( array_keys( TermTypeIds::TYPE_IDS ) as $type ) {
$updater->output( "...setting final Wikibase $type IDs.\n" );
$this->updateTermTypeId( $db, $tmpTypeIds[$type], $sanitizedTypeIds[$type] );
$this->updateTermTypeId( $db, $tmpTypeIds[$type], TermTypeIds::TYPE_IDS[$type] );
}
}

Expand Down

0 comments on commit a05d29c

Please sign in to comment.