jenkins-bot has submitted this change and it was merged. Change subject: Create PropertyInfoBuilder ......................................................................
Create PropertyInfoBuilder This allows us to centralize the information about what data is added to the property info table. Bug: T95285 Change-Id: I77c15d63e1dd4be8c3bfa90ecd719723bb22776b --- A repo/includes/PropertyInfoBuilder.php M repo/includes/content/PropertyHandler.php M repo/includes/store/sql/PropertyInfoTableBuilder.php A repo/tests/phpunit/includes/PropertyInfoBuilderTest.php 4 files changed, 62 insertions(+), 8 deletions(-) Approvals: Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified diff --git a/repo/includes/PropertyInfoBuilder.php b/repo/includes/PropertyInfoBuilder.php new file mode 100644 index 0000000..e939050 --- /dev/null +++ b/repo/includes/PropertyInfoBuilder.php @@ -0,0 +1,28 @@ +<?php + + +namespace Wikibase; + +use Wikibase\DataModel\Entity\Property; + +/** + * Class to build the information about a property. + * + * @since 0.5 + * + * @licence GNU GPL v2+ + * @author Bene* < benestar.wikime...@gmail.com > + */ +class PropertyInfoBuilder { + + /** + * @param Property $property + * @return array + */ + public function buildPropertyInfo( Property $property ) { + return array( + PropertyInfoStore::KEY_DATA_TYPE => $property->getDataTypeId() + ); + } + +} diff --git a/repo/includes/content/PropertyHandler.php b/repo/includes/content/PropertyHandler.php index 41a59e5..0644bff 100644 --- a/repo/includes/content/PropertyHandler.php +++ b/repo/includes/content/PropertyHandler.php @@ -13,6 +13,7 @@ use Wikibase\EntityContent; use Wikibase\Lib\Store\EntityContentDataCodec; use Wikibase\PropertyContent; +use Wikibase\PropertyInfoBuilder; use Wikibase\PropertyInfoStore; use Wikibase\Repo\Store\EntityPerPage; use Wikibase\Repo\Validators\EntityConstraintProvider; @@ -172,11 +173,8 @@ /** @var PropertyContent $content */ $updates = array(); - //XXX: Where to encode the knowledge about how to extract an info array from a Property object? - // Should we have a PropertyInfo class? Or can we put this into the Property class? - $info = array( - PropertyInfoStore::KEY_DATA_TYPE => $content->getProperty()->getDataTypeId() - ); + $propertyInfoBuilder = new PropertyInfoBuilder(); + $info = $propertyInfoBuilder->buildPropertyInfo( $content->getProperty() ); $updates[] = new DataUpdateAdapter( array( $this->infoStore, 'setPropertyInfo' ), diff --git a/repo/includes/store/sql/PropertyInfoTableBuilder.php b/repo/includes/store/sql/PropertyInfoTableBuilder.php index 014eed2..dba23d0 100644 --- a/repo/includes/store/sql/PropertyInfoTableBuilder.php +++ b/repo/includes/store/sql/PropertyInfoTableBuilder.php @@ -29,6 +29,11 @@ private $entityLookup; /** + * @var PropertyInfoBuilder + */ + private $propertyInfoBuilder; + + /** * @var MessageReporter|null */ private $reporter = null; @@ -74,6 +79,7 @@ $this->propertyInfoTable = $propertyInfoTable; $this->entityLookup = $entityLookup; $this->useRedirectTargetColumn = $useRedirectTargetColumn; + $this->propertyInfoBuilder = new PropertyInfoBuilder(); } /** @@ -250,9 +256,7 @@ } //FIXME: Needs to be in sync with what PropertyHandler::getEntityModificationUpdates does! - $info = array( - PropertyInfoStore::KEY_DATA_TYPE => $property->getDataTypeId() - ); + $info = $this->propertyInfoBuilder->buildPropertyInfo( $property ); $this->propertyInfoTable->setPropertyInfo( $property->getId(), diff --git a/repo/tests/phpunit/includes/PropertyInfoBuilderTest.php b/repo/tests/phpunit/includes/PropertyInfoBuilderTest.php new file mode 100644 index 0000000..8c2d60b --- /dev/null +++ b/repo/tests/phpunit/includes/PropertyInfoBuilderTest.php @@ -0,0 +1,24 @@ +<?php + + +namespace Wikibase\Test; + +use Wikibase\DataModel\Entity\Property; +use Wikibase\PropertyInfoBuilder; + +/** + * @covers Wikibase\Repo\PropertyInfoBuilder + * + * @licence GNU GPL v2+ + * @author Bene* < benestar.wikime...@gmail.com > + */ +class PropertyInfoBuilderTest extends \PHPUnit_Framework_TestCase { + + public function testBuildPropertyInfo() { + $property = Property::newFromType( 'foo' ); + $propertyInfoBuilder = new PropertyInfoBuilder(); + + $this->assertEquals( array( 'type' => 'foo' ), $propertyInfoBuilder->buildPropertyInfo( $property ) ); + } + +} -- To view, visit https://gerrit.wikimedia.org/r/235533 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I77c15d63e1dd4be8c3bfa90ecd719723bb22776b Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Bene <benestar.wikime...@gmail.com> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits