jenkins-bot has submitted this change and it was merged. ( 
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, 22 insertions(+), 6 deletions(-)

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



diff --git a/CargoFieldDescription.php b/CargoFieldDescription.php
index 727136c..8c22c58 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,25 @@
                                                // 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 ) {
+                                                               // Remove 
prefix of multiple "*"
+                                                               
$allowedValuesArray[] = preg_replace( '/^[*]*/', '', $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 +128,8 @@
                                $fieldDescription->mIsHidden = true;
                        } elseif ( $param == 'hierarchy' ) {
                                $fieldDescription->mIsHierarchy = true;
+                       } elseif ( $param == 'hierarchyStructure' ) {
+                               $fieldDescription->mHierarchyStructure = $value;
                        }
                }
                return $fieldDescription;
@@ -152,6 +168,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..50ecac6 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -730,11 +730,10 @@
                                $createIndexSQL .= $cdb->addIdentifierQuotes( 
'_right' ) . ')';
                                $cdb->query( $createIndexSQL );
                                $fieldTableNames[] = $fieldTableName;
-                               //Insert Hierarchy Structure
-                               $allowedValuesWikitext = 
$fieldDescription->mAllowedValues[0];
-                               $hierarchyTree = 
CargoHierarchy::newFromWikiText( $allowedValuesWikitext );
-                               $hierarchyStructureData = 
$hierarchyTree->generateHierarchyStructureTableData();
-                               foreach( $hierarchyStructureData as $entry ) {
+                               // Insert hierarchy information in the 
__hierarchy table
+                               $hierarchyTree = 
CargoHierarchy::newFromWikiText( $fieldDescription->mHierarchyStructure );
+                               $hierarchyStructureTableData = 
$hierarchyTree->generateHierarchyStructureTableData();
+                               foreach( $hierarchyStructureTableData as $entry 
) {
                                        $cdb->insert( $fieldTableName, $entry );
                                }
                        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I958d9c246d621b484f5acee3d6271a8ef4d3b86a
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 <f29ah...@gmail.com>
Gerrit-Reviewer: Yaron Koren <yaro...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to