Forums / Install & configuration / Import Script Problems

Import Script Problems

Author Message

Kenneth Colwell

Wednesday 11 February 2004 1:31:03 pm

Hi,

Thank you for providing these scripts they are a huge help. However, I have two problems after completing my import. After I imported all of my articles I found that a significant amount of those articles and some folders had been duplicated or somehow placed in the root folder. It seems like a lot of the folders have blank description fields in the orginal 2.2.9 database.

Also I found that my images are uploaded and that I can access them via the images folder but they are not appearing in the individual articles.

Any ideas?

Thanks,
Ken Colwell

Kenneth Colwell

Wednesday 11 February 2004 2:21:54 pm

Perhaps the problem is that the importfolder.php script doesn't look for folders that have a smaller id number than the folder that they have been placed inside. For example if you look at our 2.2.9 site we have a folder named baseball: http://www.muc.edu/article/archive/68/ that has been moved into a folder that we created later named men?s teams: http://www.muc.edu/article/archive/339/

Since the script does a simple SELECT * FROM eZArticle_Category ORDER BY ID and the sends the folders to addFolder function. When the script gets to folder 68 its parent folder doesn?t exist yet so it just dumps it into the root folder.

Does this sound like the source of my folder problem or am I just totally off the mark?

Thanks,
Ken Colwell

Kenneth Colwell

Thursday 12 February 2004 7:08:09 am

I guess I will just keep talking to myself and hope that it helps someone in the future. :-)

Changing line 170 of importFolder.php from ORDER BY ID to ORDER BY ParentID seems to semi-fix the problem of sub-folders that have a smaller id number than there parent folder.

However this problem still exists if there are other subfolders within the original subfolder with smaller id numbers than the original parent folder.

Thanks,
Ken C.

Georg Franz

Thursday 12 February 2004 8:07:18 am

Hi Ken,

no, sorting by ParentID won't help. You have to implement a "getTree"-Class.

Do something similar in the importfolder.php:

class mytree
{

	var $data;
	var $table;
	var $ID;
	
	function mytree( $id=-1, $table = 'eZArticle_Category' )
    {
        if ( $id != -1 )
        {
            $this->ID = $id;
            $this->table = $table;
            $this->get( $this->ID, $table );
        }
    }
    
    function get( $id=-1, $table = 'eZArticle_Category')
    {
        if ( $id != "" )
        {
            $db =& eZDB::instance();
		    $db->setIsSQLOutputEnabled( false );
			$data = $db->arrayQuery( "SELECT *
			FROM
			  $table
		    WHERE ID = $id" );
			$this->data = $data;
        }
    }
    
    function id()
    {
    	return $this->ID;	
    }
    
    function getByParent( $parent, $table = "eZArticle_Category" )
    {
        if ( get_class( $parent ) == "mytree" )
        {
            $db =& eZDB::instance();
		    $db->setIsSQLOutputEnabled( false );
			
            $return_array = array();
            $category_array = array();

            $parentID = $parent->id();

            $show_str = "";
            
		    $query = "SELECT ID 
                      FROM $table 
                      WHERE ParentID='$parentID'
                      ORDER BY Name
                            ";

            $category_array = $db->arrayQuery( $query );

            for ( $i=0; $i < count($category_array); $i++ )
            {
                $return_array[$i] = new mytree( $category_array[$i]["ID"], $table );
            }
            return $return_array;
        }
        else
        {
            return 0;
        }
    }

    
	function getTree( $table = "eZArticle_Category", $parentID=0, $level=0   )
	{
	    if ( get_class( $parentID ) == "mytree" )
	        $category = $parentID;
	    else
	        $category = new mytree( $parentID, $table );
	
	    $categoryList = $category->getByParent( $category, $table );
	
	    $tree = array();
	    $level++;
	    foreach ( $categoryList as $category )
	    {
	        array_push( $tree, array( $return_array[] = $category, $level ) );
	
	        if ( $category != 0 )
	        {
	            $tree = array_merge( $tree, mytree::getTree( $table, $category, $level  ) );
	        }
	    }
	    return $tree;
	}
}

(...)

Alter the function "folderList":

function folderList($table = 'eZArticle_Category'  )
{
    $tree = mytree::getTree($table);
    $folderArray = array();
    foreach ($tree as $item)
    {
    	$folderArray[] = $item[0]->data[0];
    }
	return $folderArray;
}

To get the sorted folders:

$articleFolderList =& folderList('eZArticle_Category' );

$imageFolderList =& folderList('eZImageCatalogue_Category' );

(and so on)

Best wishes,
Georg.

--
http://www.schicksal.com Horoskop website which uses eZ Publish since 2004

Kenneth Colwell

Thursday 12 February 2004 9:51:27 am

Thank you, Thank you, Thank you!

I was on the way to your solution to this problem but working from the 2.2.9 tree menu/sitemap script was giving me headaches. Your code worked like a charm.

Many thanks,
Ken Colwell