Mwjames has uploaded a new change for review.
https://gerrit.wikimedia.org/r/64938
Change subject: Fix fatal when predefined properties are no longer exists
......................................................................
Fix fatal when predefined properties are no longer exists
Bug: 48711
Change-Id: Ibfb2ceb33d0260c281b4d72a79deacdf14ac60d8
---
M SemanticMediaWiki.hooks.php
M includes/storage/SQLStore/SMW_DIHandler_WikiPage.php
M includes/storage/SQLStore/SMW_SQLStore3_Queries.php
M tests/phpunit/SemanticMediaWikiTestCase.php
A tests/phpunit/includes/storage/sqlstore/DIHandlerWikiPageTest.php
5 files changed, 163 insertions(+), 4 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki
refs/changes/38/64938/1
diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index 7be5ac8..77e1108 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -295,6 +295,7 @@
'storage/Store',
'storage/sqlstore/PropertyStatisticsTable',
+ 'storage/sqlstore/DIHandlerWikiPage'
);
foreach ( $testFiles as $file ) {
diff --git a/includes/storage/SQLStore/SMW_DIHandler_WikiPage.php
b/includes/storage/SQLStore/SMW_DIHandler_WikiPage.php
index 18faafb..88f37b5 100644
--- a/includes/storage/SQLStore/SMW_DIHandler_WikiPage.php
+++ b/includes/storage/SQLStore/SMW_DIHandler_WikiPage.php
@@ -112,6 +112,14 @@
if ( $namespace == SMW_NS_PROPERTY && $dbkeys[0] != ''
&&
$dbkeys[0]{0} == '_' && $dbkeys[2] == '' ) {
// Correctly interpret internal property keys
+
+ // Check id before invocation to avoid
exception for non-existing
+ // but yet still residing as special properties
in non-updated pages
+ // @see bug 48711
+ if (
SMWDIProperty::getPredefinedPropertyTypeId( $dbkeys[0] ) === '' ) {
+ return null;
+ }
+
$property = new SMWDIProperty( $dbkeys[0] );
$wikipage = $property->getDiWikiPage(
$dbkeys[4] );
if ( !is_null( $wikipage ) ) {
diff --git a/includes/storage/SQLStore/SMW_SQLStore3_Queries.php
b/includes/storage/SQLStore/SMW_SQLStore3_Queries.php
index 33f7d7e..1d03ff2 100644
--- a/includes/storage/SQLStore/SMW_SQLStore3_Queries.php
+++ b/includes/storage/SQLStore/SMW_SQLStore3_Queries.php
@@ -440,17 +440,21 @@
$diHandler = $this->m_store->getDataItemHandlerForDIType(
SMWDataItem::TYPE_WIKIPAGE );
while ( ( $count < $query->getLimit() ) && ( $row =
$this->m_dbs->fetchObject( $res ) ) ) {
- $count++;
if ( $row->iw === '' || $row->iw{0} != ':' ) {
- $qr[] = $diHandler->dataItemFromDBKeys( array(
+ $dataItem = $diHandler->dataItemFromDBKeys(
array(
$row->t,
intval( $row->ns ),
$row->iw,
'',
$row->so
) );
- // These IDs are usually needed for displaying
the page (esp. if more property values are displayed):
- $this->m_store->smwIds->setCache( $row->t,
$row->ns, $row->iw, $row->so, $row->id, $row->sortkey );
+
+ if ( $dataItem instanceof SMWDIWikiPage ) {
+ $count++;
+ $qr[] = $dataItem;
+ // These IDs are usually needed for
displaying the page (esp. if more property values are displayed):
+ $this->m_store->smwIds->setCache(
$row->t, $row->ns, $row->iw, $row->so, $row->id, $row->sortkey );
+ }
}
}
diff --git a/tests/phpunit/SemanticMediaWikiTestCase.php
b/tests/phpunit/SemanticMediaWikiTestCase.php
index 76d9351..cdd93b7 100644
--- a/tests/phpunit/SemanticMediaWikiTestCase.php
+++ b/tests/phpunit/SemanticMediaWikiTestCase.php
@@ -109,6 +109,20 @@
}
/**
+ * Helper method that returns a Store object
+ *
+ * @since 1.9
+ *
+ * @param string $id
+ *
+ * @return Store
+ */
+ protected function getStore( $id = null ) {
+ // FIXME Use StoreFactory here
+ return smwfGetStore();
+ }
+
+ /**
* Helper method that returns a random string
*
* @since 1.9
diff --git a/tests/phpunit/includes/storage/sqlstore/DIHandlerWikiPageTest.php
b/tests/phpunit/includes/storage/sqlstore/DIHandlerWikiPageTest.php
new file mode 100644
index 0000000..b16b52e
--- /dev/null
+++ b/tests/phpunit/includes/storage/sqlstore/DIHandlerWikiPageTest.php
@@ -0,0 +1,132 @@
+<?php
+
+namespace SMW\Test;
+
+use SMWDIHandlerWikiPage;
+use SMWDIProperty;
+
+/**
+ * Tests for the SMWDIHandlerWikiPage class
+ *
+ * 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 1.9
+ *
+ * @file
+ * @ingroup Test
+ *
+ * @licence GNU GPL v2+
+ * @author mwjames
+ */
+
+/**
+ * Tests for the SMWDIHandlerWikiPage class
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ */
+class DIHandlerWikiPageTest extends SemanticMediaWikiTestCase {
+
+ /**
+ * Returns the name of the class to be tested
+ *
+ * @return string
+ */
+ public function getClass() {
+ return 'SMWDIHandlerWikiPage';
+ }
+
+ /**
+ * Helper method that returns a SMWDIHandlerWikiPage object
+ *
+ * @since 1.9
+ *
+ * @return SMWDIHandlerWikiPage
+ */
+ private function getInstance() {
+ return new SMWDIHandlerWikiPage( $this->getStore() );
+ }
+
+ /**
+ * @test SMWDIHandlerWikiPage::__construct
+ *
+ * @since 1.9
+ */
+ public function testConstructor() {
+ $this->assertInstanceOf( $this->getClass(),
$this->getInstance() );
+ }
+
+ /**
+ * @test SMWDIHandlerWikiPage::dataItemFromDBKeys
+ *
+ * @since 1.9
+ */
+ public function testDataItemFromDBKeysException() {
+ $this->setExpectedException( 'SMWDataItemException' );
+
+ $instance = $this->getInstance();
+ $result = $instance->dataItemFromDBKeys( array() );
+
+ $this->assertInstanceOf( 'SMWDIWikiPage', $result );
+ }
+
+ /**
+ * @test SMWDIHandlerWikiPage::dataItemFromDBKeys
+ * @dataProvider getDBKeys
+ * @see bug 48711
+ *
+ * @since 1.9
+ */
+ public function testDataItemFromDBKeys( $dbKeys, $expected ) {
+ $instance = $this->getInstance();
+ $result = $instance->dataItemFromDBKeys( $dbKeys );
+
+ if ( $expected === null ) {
+ $this->assertEmpty( $result );
+ } else {
+ $this->assertInstanceOf( $expected, $result );
+ }
+ }
+
+ /**
+ * Provides dbKeys sample
+ *
+ * @return array
+ */
+ public function getDBKeys() {
+ return array(
+
+ // #0 SMW_NS_PROPERTY, user defined property
+ array(
+ array( 'Foo', SMW_NS_PROPERTY, 'bar', '', '' ),
'SMWDIWikiPage'
+ ),
+
+ // #1 SMW_NS_PROPERTY, pre-defined property
+ array(
+ array( '_Foo', SMW_NS_PROPERTY, 'bar', '', ''
), 'SMWDIWikiPage'
+ ),
+
+ // #2 SMW_NS_PROPERTY, pre-defined property
+ // bug 48711
+ array(
+ array( '_Foo', SMW_NS_PROPERTY, '', '', '' ),
null
+ ),
+ );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/64938
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibfb2ceb33d0260c281b4d72a79deacdf14ac60d8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits