Mwjames has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/57064


Change subject: (Bug 46783) Serialization of 'Closure' is not allowed 
translatewiki.net
......................................................................

(Bug 46783) Serialization of 'Closure' is not allowed translatewiki.net

I tried to replicate the error but no matter what I had no luck in rasing
the exception. I suspect that $this->queryProcessor->getParameters()
contained an "Has improper value for Coordinates" object which causes
serialize( $params ) to fail. Since other #ask queries/query
data objects are working as suppose to be and unit test
won't cover this exception, I decided to add the new methods setQueryId()
which does not rely on the return queryProcessor->getParameters() and
rather uses the rawParameters (only contains string values).

Change-Id: Ie63509eca2cc1a5def940dd85f27ebd540f34fd3
---
M includes/parserhooks/AskParserFunction.php
M includes/query/QueryData.php
M tests/phpunit/includes/query/QueryDataTest.php
3 files changed, 58 insertions(+), 9 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki 
refs/changes/64/57064/1

diff --git a/includes/parserhooks/AskParserFunction.php 
b/includes/parserhooks/AskParserFunction.php
index fee66da..d1e830f 100644
--- a/includes/parserhooks/AskParserFunction.php
+++ b/includes/parserhooks/AskParserFunction.php
@@ -103,6 +103,7 @@
                $this->queryProcessor->map( $rawParams );
 
                // Add query data from the query
+               $this->queryData->setQueryId( $rawParams );
                $this->queryData->add(
                        $this->queryProcessor->getQuery(),
                        $this->queryProcessor->getParameters()
diff --git a/includes/query/QueryData.php b/includes/query/QueryData.php
index ef1107d..7350069 100644
--- a/includes/query/QueryData.php
+++ b/includes/query/QueryData.php
@@ -7,6 +7,7 @@
 use SMWDIBlob;
 use SMWQuery;
 use Title;
+use MWException;
 
 /**
  * Handles query meta data collected in #ask / #show
@@ -50,6 +51,11 @@
        protected $subobject;
 
        /**
+        * Represents queryId
+        */
+       protected $queryId = null;
+
+       /**
         * Constructor
         *
         * @since 1.9
@@ -69,6 +75,24 @@
         */
        public function getErrors() {
                return $this->subobject->getErrors();
+       }
+
+       /**
+        * Set QueryId
+        *
+        * Creates an unique id ( e.g. _QUERYbda2acc317b66b564e39f45e3a18fff3)
+        * which normally is based on parameters used in a #ask/#set query
+        *
+        * @since 1.9
+        *
+        * @param array $qualifiers
+        */
+       public function setQueryId( array $qualifiers ) {
+               $this->queryId = str_replace(
+                       '_',
+                       '_QUERY',
+                       $this->subobject->getAnonymousIdentifier( implode( '|', 
$qualifiers ) )
+               );
        }
 
        /**
@@ -101,10 +125,12 @@
         * @return array
         */
        public function add( SMWQuery $query, array $params ) {
+               if ( $this->queryId === null ) {
+                       throw new MWException( '_QUERY Id is not set' );
+               }
 
                // Prepare subobject semantic container
-               $Id = $this->subobject->getAnonymousIdentifier( serialize( 
$params ) );
-               $this->subobject->setSemanticData( str_replace( '_', '_QUERY', 
$Id ) );
+               $this->subobject->setSemanticData( $this->queryId );
 
                $description = $query->getDescription();
 
diff --git a/tests/phpunit/includes/query/QueryDataTest.php 
b/tests/phpunit/includes/query/QueryDataTest.php
index 191ddf9..b002a45 100644
--- a/tests/phpunit/includes/query/QueryDataTest.php
+++ b/tests/phpunit/includes/query/QueryDataTest.php
@@ -12,7 +12,6 @@
 use SMWDataValueFactory;
 use Title;
 
-
 /**
  * Tests for the SMW\QueryData class
  *
@@ -66,7 +65,6 @@
                                        'format=list'
                                ),
                                array(
-                                       'result' => false,
                                        'queryCount' => 4,
                                        'queryKey' => array( '_ASKST', 
'_ASKSI', '_ASKDE', '_ASKFO' ),
                                        'queryValue' => array( 'list', 1, 1, 
'[[Modification date::+]]' )
@@ -88,7 +86,6 @@
                                        'format=list'
                                ),
                                array(
-                                       'result' => false,
                                        'queryCount' => 4,
                                        'queryKey' => array( '_ASKST', 
'_ASKSI', '_ASKDE', '_ASKFO' ),
                                        'queryValue' => array( 'list', 2, 1, 
'[[Modification date::+]] [[Category:Foo]]' )
@@ -112,7 +109,6 @@
                                        'format=bar'
                                ),
                                array(
-                                       'result' => false,
                                        'queryCount' => 4,
                                        'queryKey' => array( '_ASKST', 
'_ASKSI', '_ASKDE', '_ASKFO' ),
                                        'queryValue' => array( 'table', 2, 1, 
'[[Modification date::+]] [[Category:Foo]]' )
@@ -129,6 +125,17 @@
         */
        private function getTitle( $title ){
                return Title::newFromText( $title );
+       }
+
+       /**
+        * Helper method to get queryProcessor object
+        *
+        * @return QueryProcessor
+        */
+       private function getQueryProcessor( array $params ){
+               $queryProcessor = new QueryProcessor( SMW_OUTPUT_WIKI, 
QueryProcessor::INLINE_QUERY, false );
+               $queryProcessor->map( $params );
+               return $queryProcessor;
        }
 
        /**
@@ -177,11 +184,10 @@
         */
        public function testInstantiatedQueryData( $title, array $params, array 
$expected ) {
                $instance = $this->getInstance( $title );
-
-               $queryProcessor = new QueryProcessor( SMW_OUTPUT_WIKI, 
QueryProcessor::INLINE_QUERY, false );
-               $queryProcessor->map( $params );
+               $queryProcessor = $this->getQueryProcessor( $params );
 
                // Add query data from the query
+               $instance->setQueryId( $params );
                $instance->add(
                        $queryProcessor->getQuery(),
                        $queryProcessor->getParameters()
@@ -214,4 +220,20 @@
                        }
                }
        }
+
+       /**
+        * Test QueryId exception
+        *
+        * @dataProvider getDataProvider
+        */
+       public function testQueryIdException( $title, array $params, array 
$expected) {
+               $this->setExpectedException( 'MWException' );
+               $instance = $this->getInstance( $title );
+
+               $queryProcessor = $this->getQueryProcessor( $params );
+               $instance->add(
+                       $queryProcessor->getQuery(),
+                       $queryProcessor->getParameters()
+               );
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie63509eca2cc1a5def940dd85f27ebd540f34fd3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <jamesin.hongkon...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to