Magento:问题类别名称在保存时自动重命名

i am importing the products with advance data flow profile and facing the weird problem while saving the category as i am passing the category name to my function as

Parent Category/Child category

The / sign between categories automatically create and assign the product to child category it is working as expected but in my case the Parent Category name is renaming somehow i have checked that i am passing the right name to the function... e.g. Semipreciuos gem stone beads/Stone type is saving as Semipreciuos gem stone bead/Stone type

The last s word is missing from the name

protected function _addCategories($categories,$desc='',$discountable,$store) {
    $rootId = $store->getRootCategoryId ();
    if (! $rootId) {
        return array();
    }
    $rootPath = '1/' . $rootId;
    if (empty ( $this->_categoryCache [$store->getId ()] )) {
        $collection = Mage::getModel ( 'catalog/category' )->getCollection ()->setStore($store)->addAttributeToSelect ( 'name' );
        $collection->getSelect ()->where ( "path like '" . $rootPath . "/%'" );

        foreach ( $collection as $cat ) {
            $pathArr = explode ( '/', $cat->getPath () );
            $namePath = '';
            for($i = 2, $l = sizeof ( $pathArr ); $i < $l; $i ++) {
                $name = $collection->getItemById ( $pathArr [$i] )->getName ();
                $namePath .= (empty ( $namePath ) ? '' : '/') . trim ( $name );
            }
            $cat->setNamePath ( $namePath );
        }

        $cache = array();
        foreach ( $collection as $cat ) {
            $cache [strtolower ( $cat->getNamePath () )] = $cat;
            $cat->unsNamePath ();
        }
        $this->_categoryCache [$store->getId ()] = $cache;
    }
    $cache = & $this->_categoryCache [$store->getId ()];

    $catIds = array();
    foreach ( explode ( ',', $categories ) as $categoryPathStr ) {
        $categoryPathStr = preg_replace ( '#s*/s*#', '/', trim ( $categoryPathStr ) );
        if (! empty ( $cache [$categoryPathStr] )) {
            $catIds [] = $cache [$categoryPathStr]->getId ();
            continue;
        }
        $path = $rootPath;
        $namePath = '';
        foreach ( explode ( '/', $categoryPathStr ) as $catName ) {
            $namePath .= (empty ( $namePath ) ? '' : '/') . strtolower ( $catName );
            if (empty ( $cache [$namePath] )) {
                $cat = Mage::getModel('catalog/category')->setStoreId($store->getId())->setPath ( $path )->setName ( $catName )->// comment out the following line if new categories should stay inactive
                setIsActive(1)->setDescription($desc)->setData('discountable',$discountable)->save();
                $cache [$namePath] = $cat;
            }
            $catId = $cache [$namePath]->getId ();
            $path .= '/' . $catId;
        }

        ##Assigning product to child category
        /*$parentId = null;
        $currentcat = Mage::getModel("catalog/category")->load($catId);
        $parentId = $currentcat->getParentId();
        if($parentId){
            $catIds[] = $parentId;
        }
        */
        if ($catId) {
            $catIds [] = $catId;
        }
    }
    return join ( ',', $catIds );
}

Above is my category function for creating categories... any one has any idea what is going on..

It is not related to Magento, but rather to PHP & regular expression.

$categoryPathStr = preg_replace ( '#s*/s*#', '/', trim ( $categoryPathStr ) );

That line replaces "s*/s*" with "/", which is why you have your last s removed. I see no real reason for that preg_replace (?), so just remove that line, or replace it with

$categoryPathStr = trim ( $categoryPathStr );

so that leading/ending white spaces get removed.