Scandal
Well-known member
I have been building an importer for own use (I want to import a batch of forums via a CSV).
I'm doing something like:
	
	
	
		
But I receive the error: please_select_valid_parent, which is on XF\Behavior\TreeStructured:
	
	
	
		
Any idea to fix this error?
				
			I'm doing something like:
		PHP:
	
	$node = \XF::em()->create('XF:Node');
$node->title = 'something';
$node->node_type_id = 'Forum';
// i have the $parent_node_id from a node which created previously on the same script // I'm sure it is was saved and exists on the db
$node->parent_node_id = intval($parent_node_id);
$node->preSave();
                            
if ($node->getErrors())
{
    $returned_errors[] = implode('<br />', $node->getErrors());
}
else
{
    $node->save();
}But I receive the error: please_select_valid_parent, which is on XF\Behavior\TreeStructured:
		PHP:
	
	    public function preSave()
    {
        $entity = $this->entity;
        if ($entity->isInsert() || $entity->isChanged($this->config['parentField']))
        {
            $parentId = $entity->getValue($this->config['parentField']);
            if ($parentId)
            {
                $newParent = $entity->em()->find($entity->structure()->shortName, $parentId);
                if (!$newParent || ($newParent->lft >= $entity->lft && $newParent->rgt <= $entity->rgt))
                {
                    $entity->error(\XF::phrase('please_select_valid_parent'), $this->config['parentField']);
                }
            }
        }
    }Any idea to fix this error?
 
 
		 
 
		