Jeroen De Dauw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/51165
Change subject: Added base of GeoCoordinateHandler [DO NOT MERGE]
......................................................................
Added base of GeoCoordinateHandler [DO NOT MERGE]
Change-Id: Ibdf6679b3a0e657cef65cc77e525aec883bc047f
---
M repo/includes/Database/FieldDefinition.php
A repo/includes/Query/SQLStore/DVHandlers/GeoCoordinateHandler.php
M repo/includes/Query/SQLStore/DataValueHandler.php
M repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
M repo/tests/phpunit/includes/Database/TableDefinitionTest.php
5 files changed, 120 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/65/51165/1
diff --git a/repo/includes/Database/FieldDefinition.php
b/repo/includes/Database/FieldDefinition.php
index e1d3301..d280e5c 100644
--- a/repo/includes/Database/FieldDefinition.php
+++ b/repo/includes/Database/FieldDefinition.php
@@ -93,15 +93,15 @@
/**
* @param string $name
* @param string $type
+ * @param boolean $null
* @param mixed $default
* @param string|null $attributes
- * @param boolean $null
* @param string|null $index
* @param boolean $autoIncrement
*
* @throws InvalidArgumentException
*/
- public function __construct( $name, $type, $default = null, $attributes
= null, $null = true, $index = null, $autoIncrement = false ) {
+ public function __construct( $name, $type, $null = true, $default =
null, $attributes = null, $index = null, $autoIncrement = false ) {
if ( !is_string( $name ) ) {
throw new InvalidArgumentException( 'The field $name
needs to be a string' );
}
diff --git a/repo/includes/Query/SQLStore/DVHandlers/GeoCoordinateHandler.php
b/repo/includes/Query/SQLStore/DVHandlers/GeoCoordinateHandler.php
new file mode 100644
index 0000000..62c9d98
--- /dev/null
+++ b/repo/includes/Query/SQLStore/DVHandlers/GeoCoordinateHandler.php
@@ -0,0 +1,103 @@
+<?php
+
+namespace Wikibase\Repo\Query\SQLStore\DVHandler;
+
+use Wikibase\Repo\Query\SQLStore\DataValueHandler;
+use Wikibase\Repo\Database\TableDefinition;
+use Wikibase\Repo\Database\FieldDefinition;
+use DataValues\DataValue;
+
+/**
+ * Represents the mapping between DataValues\GeoCoordinateValue and
+ * the corresponding table in the store.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since wd.qe
+ *
+ * @file
+ * @ingroup WikibaseSQLStore
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class GeoCoordinateHandler extends DataValueHandler {
+
+ /**
+ * @see DataValueHandler::getTableDefinition
+ *
+ * @since wd.qe
+ *
+ * @return TableDefinition
+ */
+ public function getTableDefinition() {
+ $fields = array(
+ new FieldDefinition( 'lat',
FieldDefinition::TYPE_FLOAT, false ),
+ new FieldDefinition( 'lon',
FieldDefinition::TYPE_FLOAT, false ),
+ new FieldDefinition( 'alt',
FieldDefinition::TYPE_FLOAT, true ),
+ new FieldDefinition( 'json',
FieldDefinition::TYPE_TEXT, false ),
+ );
+
+ return new TableDefinition( 'geo', $fields );
+ }
+
+ /**
+ * @see DataValueHandler::getValueFieldName
+ *
+ * @since wd.qe
+ *
+ * @return string
+ */
+ public function getValueFieldName() {
+ return 'json';
+ }
+
+ /**
+ * @see DataValueHandler::getSortFieldName
+ *
+ * @since wd.qe
+ *
+ * @return string
+ */
+ public function getSortFieldName() {
+ return 'lat';
+ }
+
+ /**
+ * @see DataValueHandler::newDataValueFromDbValue
+ *
+ * @since wd.qe
+ *
+ * @param $dbValue // TODO: mixed or string?
+ *
+ * @return DataValue
+ */
+ public function newDataValueFromDbValue( $dbValue ) {
+ // TODO
+ }
+
+ /**
+ * @see DataValueHandler::getLabelFieldName
+ *
+ * @since wd.qe
+ *
+ * @return string|null
+ */
+ public function getLabelFieldName() {
+ return null;
+ }
+
+}
\ No newline at end of file
diff --git a/repo/includes/Query/SQLStore/DataValueHandler.php
b/repo/includes/Query/SQLStore/DataValueHandler.php
index a9e30c4..7012370 100644
--- a/repo/includes/Query/SQLStore/DataValueHandler.php
+++ b/repo/includes/Query/SQLStore/DataValueHandler.php
@@ -81,11 +81,11 @@
*/
abstract public function newDataValueFromDbValue( $dbValue );
- /**
+ /**
* Return the label field for this type of DataValue. This should be
* a string column in the database table that can be used for selecting
* values using criteria such as "starts with". The return value can be
- * empty if this is not supported. This is preferred for SMWDataItem
+ * empty if this is not supported. This is preferred for DataValue
* classes that do not have an obvious canonical string writing anyway.
*
* The return value can be a column name or the empty string (if the
diff --git a/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
b/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
index 5566a95..82f9ab6 100644
--- a/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
+++ b/repo/tests/phpunit/includes/Database/FieldDefinitionTest.php
@@ -52,26 +52,26 @@
$instances[] = new FieldDefinition(
'stuffs',
FieldDefinition::TYPE_INTEGER,
+ false,
42,
- FieldDefinition::ATTRIB_UNSIGNED,
- false
+ FieldDefinition::ATTRIB_UNSIGNED
);
$instances[] = new FieldDefinition(
'stuffs',
FieldDefinition::TYPE_INTEGER,
- null,
- null,
- true
- );
-
- $instances[] = new FieldDefinition(
- 'stuffs',
- FieldDefinition::TYPE_INTEGER,
- null,
- null,
true,
null,
+ null
+ );
+
+ $instances[] = new FieldDefinition(
+ 'stuffs',
+ FieldDefinition::TYPE_INTEGER,
+ true,
+ null,
+ null,
+ null,
true
);
diff --git a/repo/tests/phpunit/includes/Database/TableDefinitionTest.php
b/repo/tests/phpunit/includes/Database/TableDefinitionTest.php
index 393a795..9d546ce 100644
--- a/repo/tests/phpunit/includes/Database/TableDefinitionTest.php
+++ b/repo/tests/phpunit/includes/Database/TableDefinitionTest.php
@@ -52,7 +52,7 @@
array(
new FieldDefinition( 'o',
FieldDefinition::TYPE_TEXT ),
new FieldDefinition( 'h',
FieldDefinition::TYPE_TEXT ),
- new FieldDefinition( 'i',
FieldDefinition::TYPE_INTEGER, 42 ),
+ new FieldDefinition( 'i',
FieldDefinition::TYPE_INTEGER, false, 42 ),
)
);
--
To view, visit https://gerrit.wikimedia.org/r/51165
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibdf6679b3a0e657cef65cc77e525aec883bc047f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits