[MediaWiki-commits] [Gerrit] Incorporated Yaron's suggestion to use a separate parameter ... - change (mediawiki...ExternalData)
Jqnatividad has uploaded a new change for review. https://gerrit.wikimedia.org/r/62819 Change subject: Incorporated Yaron's suggestion to use a separate parameter to capture MongoDB Find Query. The new parm, is appropriately named find query. Also changed str_replace with str_ireplace for matching AND LIKE in parsing MongoDB where. .. Incorporated Yaron's suggestion to use a separate parameter to capture MongoDB Find Query. The new parm, is appropriately named find query. Also changed str_replace with str_ireplace for matching AND LIKE in parsing MongoDB where. Change-Id: I9438fa2dc54d9c3d3f1de1eec984b998ee4f3093 --- M ED_ParserFunctions.php M ED_Utils.php 2 files changed, 38 insertions(+), 41 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ExternalData refs/changes/19/62819/1 diff --git a/ED_ParserFunctions.php b/ED_ParserFunctions.php index 93c0f05..44a3919 100644 --- a/ED_ParserFunctions.php +++ b/ED_ParserFunctions.php @@ -248,10 +248,11 @@ } $table = ( array_key_exists( 'from', $args ) ) ? $args['from'] : null; $conds = ( array_key_exists( 'where', $args ) ) ? $args['where'] : null; + $findQuery = ( array_key_exists( 'find query', $args ) ) ? $args['find query'] : null; $limit = ( array_key_exists( 'limit', $args ) ) ? $args['limit'] : null; $orderBy = ( array_key_exists( 'order by', $args ) ) ? $args['order by'] : null; $groupBy = ( array_key_exists( 'group by', $args ) ) ? $args['group by'] : null; - $options = array( 'LIMIT' = $limit, 'ORDER BY' = $orderBy, 'GROUP BY' = $groupBy ); + $options = array( 'LIMIT' = $limit, 'ORDER BY' = $orderBy, 'GROUP BY' = $groupBy, 'FIND QUERY' = $findQuery ); $mappings = EDUtils::paramToArray( $data ); // parse the data arg into mappings $external_values = EDUtils::getDBData( $dbID, $table, array_values( $mappings ), $conds, $options ); diff --git a/ED_Utils.php b/ED_Utils.php index ae90bb1..33845f5 100644 --- a/ED_Utils.php +++ b/ED_Utils.php @@ -291,47 +291,43 @@ $collection = new MongoCollection( $db, $from ); - // Turn the SQL of the where= parameter into the appropriate - // array for MongoDB. - $whereArray = array(); - if ( $where != '' ) { - - // if the string 'PASSTHRU' is used, then just passthrough the - // JSON MongoDB find condition as a JSON string. This is necessary so we don't try + $findArray = array(); + // Was a direct MongoDB find query JSON string provided? + if ( $options['FIND QUERY'] != '' ) { + // if FIND QUERY is used, then just passthrough the + // JSON MongoDB FIND query as a JSON string. This is necessary so we don't try // to create a MongoDB find parser in ExternalData to accomodate all the possible // find scenarios since MongoDB is NotSQL :). Be sure to use spaces between curly - // brackets so as not to trip up the MW parser - if ( substr($where, 0, 10) == 'PASSTHRU' ) { - $whereArray = json_decode (substr($where, 10), true); - } else { - // Hopefully all-caps and all-lowercase are the only - // two variants that people will use - otherwise, - // preg_replace() should be used. - $where = str_replace( ' and ', ' AND ', $where ); - $where = str_replace( ' like ', ' LIKE ', $where ); - $whereElements = explode( ' AND ', $where ); - foreach ( $whereElements as $whereElement ) { - if ( strpos( $whereElement, '=' ) ) { - list( $fieldName, $value ) = explode( '=', $whereElement ); - $whereArray[trim( $fieldName )] = array( '$gte' = trim( $value ) ); - } elseif ( strpos( $whereElement, '' ) ) { - list( $fieldName, $value ) = explode( '', $whereElement ); - $whereArray[trim( $fieldName )] = array( '$gt' = trim( $value ) ); - } elseif ( strpos( $whereElement, '=' ) ) { - list( $fieldName, $value ) = explode( '=', $whereElement ); - $whereArray[trim( $fieldName )] = array( '$lte' = trim(
[MediaWiki-commits] [Gerrit] Incorporated Yaron's suggestion to use a separate parameter ... - change (mediawiki...ExternalData)
Yaron Koren has submitted this change and it was merged. Change subject: Incorporated Yaron's suggestion to use a separate parameter to capture MongoDB Find Query. The new parm, is appropriately named find query. Also changed str_replace with str_ireplace for matching AND LIKE in parsing MongoDB where. .. Incorporated Yaron's suggestion to use a separate parameter to capture MongoDB Find Query. The new parm, is appropriately named find query. Also changed str_replace with str_ireplace for matching AND LIKE in parsing MongoDB where. Change-Id: I9438fa2dc54d9c3d3f1de1eec984b998ee4f3093 --- M ED_ParserFunctions.php M ED_Utils.php 2 files changed, 38 insertions(+), 41 deletions(-) Approvals: Yaron Koren: Verified; Looks good to me, approved diff --git a/ED_ParserFunctions.php b/ED_ParserFunctions.php index 93c0f05..44a3919 100644 --- a/ED_ParserFunctions.php +++ b/ED_ParserFunctions.php @@ -248,10 +248,11 @@ } $table = ( array_key_exists( 'from', $args ) ) ? $args['from'] : null; $conds = ( array_key_exists( 'where', $args ) ) ? $args['where'] : null; + $findQuery = ( array_key_exists( 'find query', $args ) ) ? $args['find query'] : null; $limit = ( array_key_exists( 'limit', $args ) ) ? $args['limit'] : null; $orderBy = ( array_key_exists( 'order by', $args ) ) ? $args['order by'] : null; $groupBy = ( array_key_exists( 'group by', $args ) ) ? $args['group by'] : null; - $options = array( 'LIMIT' = $limit, 'ORDER BY' = $orderBy, 'GROUP BY' = $groupBy ); + $options = array( 'LIMIT' = $limit, 'ORDER BY' = $orderBy, 'GROUP BY' = $groupBy, 'FIND QUERY' = $findQuery ); $mappings = EDUtils::paramToArray( $data ); // parse the data arg into mappings $external_values = EDUtils::getDBData( $dbID, $table, array_values( $mappings ), $conds, $options ); diff --git a/ED_Utils.php b/ED_Utils.php index ae90bb1..33845f5 100644 --- a/ED_Utils.php +++ b/ED_Utils.php @@ -291,47 +291,43 @@ $collection = new MongoCollection( $db, $from ); - // Turn the SQL of the where= parameter into the appropriate - // array for MongoDB. - $whereArray = array(); - if ( $where != '' ) { - - // if the string 'PASSTHRU' is used, then just passthrough the - // JSON MongoDB find condition as a JSON string. This is necessary so we don't try + $findArray = array(); + // Was a direct MongoDB find query JSON string provided? + if ( $options['FIND QUERY'] != '' ) { + // if FIND QUERY is used, then just passthrough the + // JSON MongoDB FIND query as a JSON string. This is necessary so we don't try // to create a MongoDB find parser in ExternalData to accomodate all the possible // find scenarios since MongoDB is NotSQL :). Be sure to use spaces between curly - // brackets so as not to trip up the MW parser - if ( substr($where, 0, 10) == 'PASSTHRU' ) { - $whereArray = json_decode (substr($where, 10), true); - } else { - // Hopefully all-caps and all-lowercase are the only - // two variants that people will use - otherwise, - // preg_replace() should be used. - $where = str_replace( ' and ', ' AND ', $where ); - $where = str_replace( ' like ', ' LIKE ', $where ); - $whereElements = explode( ' AND ', $where ); - foreach ( $whereElements as $whereElement ) { - if ( strpos( $whereElement, '=' ) ) { - list( $fieldName, $value ) = explode( '=', $whereElement ); - $whereArray[trim( $fieldName )] = array( '$gte' = trim( $value ) ); - } elseif ( strpos( $whereElement, '' ) ) { - list( $fieldName, $value ) = explode( '', $whereElement ); - $whereArray[trim( $fieldName )] = array( '$gt' = trim( $value ) ); - } elseif ( strpos( $whereElement, '=' ) ) { - list( $fieldName, $value ) = explode( '=', $whereElement ); - $whereArray[trim( $fieldName )] = array( '$lte' = trim( $value ) ); - } elseif ( strpos(