Fz-29 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/360916 )

Change subject: Fixed : Populate hierarchy fields in Cargo Tables
......................................................................

Fixed : Populate hierarchy fields in Cargo Tables

Hierarchy fields were not being populated.
This patch fixes the above issue.

Change-Id: I958d9c246d621b484f5acee3d6271a8ef4d3b86a
---
M CargoFieldDescription.php
M CargoUtils.php
2 files changed, 23 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/16/360916/1

diff --git a/CargoFieldDescription.php b/CargoFieldDescription.php
index 727136c..296904e 100644
--- a/CargoFieldDescription.php
+++ b/CargoFieldDescription.php
@@ -15,6 +15,7 @@
        public $mAllowedValues = null;
        public $mIsHidden = false;
        public $mIsHierarchy = false;
+       public $mHierarchyStructure = null;
        public $mOtherParams = array();
 
        /**
@@ -68,12 +69,29 @@
                                                // already used to separate
                                                // "extra parameters", so just
                                                // hardcode it to a semicolon.
+                                               if( 
$fieldDescription->mIsHierarchy == true ) {
+                                                       // $paramValue contains 
"*" hierarchy structure
+                                                       
$fieldDescription->mHierarchyStructure = trim( $paramValue );
+                                                       // now make the allowed 
values param similar to the syntax
+                                                       // used by other fields
+                                                       $hierarchyNodesArray = 
explode( "\n", $paramValue );
+                                                       $allowedValuesArray = 
array();
+                                                       foreach ( 
$hierarchyNodesArray as $node ) {
+                                                               $node = trim( 
$node );
+                                                               // Remove 
prefix of multiple "*"
+                                                               $node = 
preg_replace( '/^[*]*/', '', $node );
+                                                               $node = trim( 
$node );
+
+                                                               
$allowedValuesArray[] = $node;
+                                                       }
+                                                       $paramValue = implode( 
',', $allowedValuesArray );
+                                               }
                                                $delimiter = ',';
                                                $allowedValuesStr = 
str_replace( "\\$delimiter", "\a", $paramValue );
                                                $allowedValuesArray = explode( 
$delimiter, $allowedValuesStr );
                                                foreach ( $allowedValuesArray 
as $i => $value ) {
                                                        if ( $value == '' ) 
continue;
-                                                       // Replace beep back 
with comma, trim.
+                                                       // Replace beep back 
with delimiter, trim.
                                                        $value = str_replace( 
"\a", $delimiter, trim( $value ) );
                                                        
$fieldDescription->mAllowedValues[] = $value;
                                                }
@@ -114,6 +132,8 @@
                                $fieldDescription->mIsHidden = true;
                        } elseif ( $param == 'hierarchy' ) {
                                $fieldDescription->mIsHierarchy = true;
+                       } elseif ( $param == 'hierarchyStructure' ) {
+                               $fieldDescription->mHierarchyStructure = $value;
                        }
                }
                return $fieldDescription;
@@ -152,6 +172,7 @@
                }
                if ( $this->mIsHierarchy ) {
                        $descriptionData['hierarchy'] = true;
+                       $descriptionData['hierarchyStructure'] = 
$this->mHierarchyStructure;
                }
                foreach ( $this->mOtherParams as $otherParam => $value ) {
                        $descriptionData[$otherParam] = $value;
diff --git a/CargoUtils.php b/CargoUtils.php
index eeb860b..2feb712 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -731,7 +731,7 @@
                                $cdb->query( $createIndexSQL );
                                $fieldTableNames[] = $fieldTableName;
                                //Insert Hierarchy Structure
-                               $allowedValuesWikitext = 
$fieldDescription->mAllowedValues[0];
+                               $allowedValuesWikitext = 
$fieldDescription->mHierarchyStructure;
                                $hierarchyTree = 
CargoHierarchy::newFromWikiText( $allowedValuesWikitext );
                                $hierarchyStructureData = 
$hierarchyTree->generateHierarchyStructureTableData();
                                foreach( $hierarchyStructureData as $entry ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I958d9c246d621b484f5acee3d6271a8ef4d3b86a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 <f29ah...@gmail.com>

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

Reply via email to