jenkins-bot has submitted this change and it was merged.

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/Setup.php
M includes/dataitems/SMW_DI_Property.php
A includes/exceptions/PredefinedPropertyException.php
M includes/storage/SQLStore/SMW_SQLStore3_Queries.php
A tests/phpunit/includes/storage/sqlstore/DIHandlerWikiPageTest.php
6 files changed, 207 insertions(+), 7 deletions(-)

Approvals:
  Mwjames: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index 23d9629..b1cc520 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -299,6 +299,7 @@
                        'storage/Store',
 
                        'storage/sqlstore/PropertyStatisticsTable',
+                       'storage/sqlstore/DIHandlerWikiPage'
                );
 
                foreach ( $testFiles as $file ) {
diff --git a/includes/Setup.php b/includes/Setup.php
index 880d931..fb53ae4 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -153,8 +153,9 @@
        $wgAutoloadClasses['SMW\CacheHandler']           = $incDir . 
'/handlers/CacheHandler.php';
 
        // Exceptions
-       $wgAutoloadClasses['SMW\StoreInstanceException']    = $incDir . 
'/exceptions/StoreInstanceException.php';
-       $wgAutoloadClasses['SMW\SettingsArgumentException'] = $incDir . 
'/exceptions/SettingsArgumentException.php';
+       $wgAutoloadClasses['SMW\StoreInstanceException']      = $incDir . 
'/exceptions/StoreInstanceException.php';
+       $wgAutoloadClasses['SMW\SettingsArgumentException']   = $incDir . 
'/exceptions/SettingsArgumentException.php';
+       $wgAutoloadClasses['SMW\PredefinedPropertyException'] = $incDir . 
'/exceptions/PredefinedPropertyException.php';
 
        // Article pages
        $apDir = $smwgIP . 'includes/articlepages/';
diff --git a/includes/dataitems/SMW_DI_Property.php 
b/includes/dataitems/SMW_DI_Property.php
index 47f5337..98ac13b 100644
--- a/includes/dataitems/SMW_DI_Property.php
+++ b/includes/dataitems/SMW_DI_Property.php
@@ -106,7 +106,7 @@
                if ( $key{0} == '_' ) {
                        SMWDIProperty::initPropertyRegistration();
                        if ( !array_key_exists( $key, 
SMWDIProperty::$m_prop_types ) ) {
-                               throw new SMWDataItemException( "There is no 
predefined property with \"$key\"." );
+                               throw new \SMW\PredefinedPropertyException( 
"There is no predefined property with \"$key\"." );
                        }
                }
 
diff --git a/includes/exceptions/PredefinedPropertyException.php 
b/includes/exceptions/PredefinedPropertyException.php
new file mode 100644
index 0000000..97f3474
--- /dev/null
+++ b/includes/exceptions/PredefinedPropertyException.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace SMW;
+
+use SMWDataItemException;
+
+/**
+ * Exception for an invalid predefined property
+ *
+ * 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 Exception
+ *
+ * @author mwjames
+ */
+
+/**
+ * Exception for an invalid predefined property
+ *
+ * @ingroup Exception
+ * @codeCoverageIgnore
+ */
+class PredefinedPropertyException extends SMWDataItemException {}
\ No newline at end of file
diff --git a/includes/storage/SQLStore/SMW_SQLStore3_Queries.php 
b/includes/storage/SQLStore/SMW_SQLStore3_Queries.php
index 33f7d7e..478ddde 100644
--- a/includes/storage/SQLStore/SMW_SQLStore3_Queries.php
+++ b/includes/storage/SQLStore/SMW_SQLStore3_Queries.php
@@ -440,17 +440,28 @@
                $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(
+
+                               // Catch exception for non-existing predefined 
properties that
+                               // still registered within non-updated pages 
(@see bug 48711)
+                               try {
+                                       $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 );
+                               } catch ( \SMW\PredefinedPropertyException $e ) 
{
+                                       wfDebugLog( __CLASS__, __METHOD__ . ': 
' . $e->getMessage() );
+                               }
+
+                               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/includes/storage/sqlstore/DIHandlerWikiPageTest.php 
b/tests/phpunit/includes/storage/sqlstore/DIHandlerWikiPageTest.php
new file mode 100644
index 0000000..623c350
--- /dev/null
+++ b/tests/phpunit/includes/storage/sqlstore/DIHandlerWikiPageTest.php
@@ -0,0 +1,148 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\PredefinedPropertyException;
+use SMW\StoreFactory;
+
+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( StoreFactory::getStore() );
+       }
+
+       /**
+        * @test SMWDIHandlerWikiPage::__construct
+        *
+        * @since 1.9
+        */
+       public function testConstructor() {
+               $this->assertInstanceOf( $this->getClass(), 
$this->getInstance() );
+       }
+
+       /**
+        * @test SMWDIHandlerWikiPage::dataItemFromDBKeys
+        *
+        * @since 1.9
+        *
+        * @throws SMWDataItemException
+        */
+       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
+        *
+        * @param $dbKeys
+        * @param $expected
+        *
+        * @throws PredefinedPropertyException
+        */
+       public function testDataItemFromDBKeys( $dbKeys, $expected ) {
+
+               $instance = $this->getInstance();
+
+               try {
+                       $result = $instance->dataItemFromDBKeys( $dbKeys );
+                       $this->assertInstanceOf( $expected, $result );
+                       return;
+               } catch ( PredefinedPropertyException $e ) {
+                       $this->assertEquals( $expected, 
'PredefinedPropertyException' );
+                       return;
+               }
+
+               $this->fail( 'An expected exception has not been raised.' );
+       }
+
+       /**
+        * 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 (see bug 
48711)
+                       array(
+                               array( '_Foo', SMW_NS_PROPERTY, '', '', '' ), 
'PredefinedPropertyException'
+                       ),
+               );
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/64938
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibfb2ceb33d0260c281b4d72a79deacdf14ac60d8
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Mwjames <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to