jenkins-bot has submitted this change and it was merged. Change subject: Remove usage of deprecated Entity methods ......................................................................
Remove usage of deprecated Entity methods This includes fixing two of the issues listed here https://gerrit.wikimedia.org/r/#/c/173724/1/lib/includes/store/sql/TermSqlIndex.php Change-Id: I42b15469d765d40c5db21b1fc956141bcb0b0a75 --- M lib/includes/store/TermIndex.php M lib/includes/store/sql/TermSqlIndex.php M lib/tests/phpunit/store/MockTermIndex.php 3 files changed, 42 insertions(+), 23 deletions(-) Approvals: Hoo man: Looks good to me, approved Thiemo Mättig (WMDE): Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/lib/includes/store/TermIndex.php b/lib/includes/store/TermIndex.php index e975e90..a52fa4b 100644 --- a/lib/includes/store/TermIndex.php +++ b/lib/includes/store/TermIndex.php @@ -2,7 +2,7 @@ namespace Wikibase; -use Wikibase\DataModel\Entity\Entity; +use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; use Wikibase\Lib\Store\LabelConflictFinder; @@ -37,11 +37,11 @@ * * @since 0.1 * - * @param Entity $entity + * @param EntityDocument $entity * * @return boolean Success indicator */ - public function saveTermsOfEntity( Entity $entity ); + public function saveTermsOfEntity( EntityDocument $entity ); /** * Deletes the terms of the provided entity from the term cache. diff --git a/lib/includes/store/sql/TermSqlIndex.php b/lib/includes/store/sql/TermSqlIndex.php index ec9e931..2e93be4 100644 --- a/lib/includes/store/sql/TermSqlIndex.php +++ b/lib/includes/store/sql/TermSqlIndex.php @@ -8,9 +8,12 @@ use Iterator; use MWException; use Wikibase\DataModel\Entity\Entity; +use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\LegacyIdInterpreter; +use Wikibase\DataModel\Term\Fingerprint; +use Wikibase\DataModel\Term\FingerprintProvider; /** * Term lookup cache. @@ -88,11 +91,11 @@ * * @since 0.1 * - * @param Entity $entity + * @param EntityDocument $entity * * @return boolean Success indicator */ - public function saveTermsOfEntity( Entity $entity ) { + public function saveTermsOfEntity( EntityDocument $entity ) { wfProfileIn( __METHOD__ ); //First check whether there's anything to update @@ -118,7 +121,12 @@ if ( $ok && $termsToInsert ) { wfDebugLog( __CLASS__, __FUNCTION__ . ": " . count( $termsToInsert ) . " terms to insert." ); - $ok = $dbw->deadlockLoop( array( $this, 'insertTermsInternal' ), $entity, $termsToInsert, $dbw ); + + // TODO: remove silly self hack when we can use PHP 5.4 + $self = $this; + $ok = $dbw->deadlockLoop( function() use ( $self, $entity, $termsToInsert, $dbw ) { + return $self->insertTermsInternal( $entity, $termsToInsert, $dbw ); + } ); } $this->releaseConnection( $dbw ); @@ -135,18 +143,20 @@ * * @since 0.5 * - * @param Entity $entity + * @param EntityDocument $entity * @param Term[] $terms * @param DatabaseBase $dbw * * @return boolean Success indicator */ - public function insertTermsInternal( Entity $entity, $terms, DatabaseBase $dbw ) { + public function insertTermsInternal( EntityDocument $entity, $terms, DatabaseBase $dbw ) { wfProfileIn( __METHOD__ ); $entityIdentifiers = array( + // FIXME: this will fail for IDs that do not have a numeric form 'term_entity_id' => $entity->getId()->getNumericId(), - 'term_entity_type' => $entity->getId()->getEntityType() + + 'term_entity_type' => $entity->getType() ); wfDebugLog( __CLASS__, __FUNCTION__ . ': inserting terms for ' . $entity->getId()->getSerialization() ); @@ -180,17 +190,24 @@ } /** - * TODO: this method belongs in Entity itself. This change can only be made once - * there is a sane Term object in DataModel itself though. - * - * @param Entity $entity + * @param EntityDocument $entity * * @return Term[] */ - public function getEntityTerms( Entity $entity ) { + public function getEntityTerms( EntityDocument $entity ) { + // FIXME: OCP violation. No support for new types of entities can be registered + + if ( $entity instanceof FingerprintProvider ) { + return $this->getFingerprintTerms( $entity->getFingerprint() ); + } + + return array(); + } + + private function getFingerprintTerms( Fingerprint $fingerprint ) { $terms = array(); - foreach ( $entity->getDescriptions() as $languageCode => $description ) { + foreach ( $fingerprint->getDescriptions()->toTextArray() as $languageCode => $description ) { $term = new Term(); $term->setLanguage( $languageCode ); @@ -200,7 +217,7 @@ $terms[] = $term; } - foreach ( $entity->getLabels() as $languageCode => $label ) { + foreach ( $fingerprint->getLabels()->toTextArray() as $languageCode => $label ) { $term = new Term(); $term->setLanguage( $languageCode ); @@ -210,11 +227,11 @@ $terms[] = $term; } - foreach ( $entity->getAllAliases() as $languageCode => $aliases ) { - foreach ( $aliases as $alias ) { + foreach ( $fingerprint->getAliasGroups() as $aliasGroup ) { + foreach ( $aliasGroup->getAliases() as $alias ) { $term = new Term(); - $term->setLanguage( $languageCode ); + $term->setLanguage( $aliasGroup->getLanguageCode() ); $term->setType( Term::TYPE_ALIAS ); $term->setText( $alias ); @@ -290,11 +307,13 @@ * * @since 0.4 * - * @param Entity $entity + * @param EntityDocument $entity * * @return float weight */ - protected function getWeight( Entity $entity ) { + protected function getWeight( EntityDocument $entity ) { + // FIXME: OCP violation. No support for new types of entities can be registered + if ( $entity instanceof Item ) { return $entity->getSiteLinkList()->count() / 1000.0; } diff --git a/lib/tests/phpunit/store/MockTermIndex.php b/lib/tests/phpunit/store/MockTermIndex.php index f92570e..45510df 100644 --- a/lib/tests/phpunit/store/MockTermIndex.php +++ b/lib/tests/phpunit/store/MockTermIndex.php @@ -4,7 +4,7 @@ use Exception; use InvalidArgumentException; -use Wikibase\DataModel\Entity\Entity; +use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; use Wikibase\Term; use Wikibase\TermIndex; @@ -168,7 +168,7 @@ /** * @throws Exception always */ - public function saveTermsOfEntity( Entity $entity ) { + public function saveTermsOfEntity( EntityDocument $entity ) { throw new Exception( 'not implemented by mock class ' ); } -- To view, visit https://gerrit.wikimedia.org/r/173840 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I42b15469d765d40c5db21b1fc956141bcb0b0a75 Gerrit-PatchSet: 10 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <[email protected]> Gerrit-Reviewer: Adrian Lang <[email protected]> Gerrit-Reviewer: Aude <[email protected]> Gerrit-Reviewer: Daniel Kinzler <[email protected]> Gerrit-Reviewer: Hoo man <[email protected]> Gerrit-Reviewer: Jeroen De Dauw <[email protected]> Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
