We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Error inserting entries, specific module development

Development and Programming

evasion's avatar
evasion
58 posts
17 years ago
evasion's avatar evasion

Hello,

I’m currently working on some external EE module built with CodeIgniter. One of the thing I need to do is to import some complex XML into a custom weblog with relationships.

I do this in 3 step : - First insert data into exp_weblog_titles - Then insert data into exp_relationships - Then insert data into exp_weblog_data

Here’s my code :

// Insert data into exp_weblog_titles
$title_data[$key] = array(
    'entry_id'                    =>    '',
    'weblog_id'                 =>     $weblog_id,
    'author_id'                    =>    $author_id,
    'site_id'                    =>  $site_id,                
    'ip_address'                   =>  $ip_adress,
    'title'                        =>    $title,
    'url_title'                    =>    $url_title,
    'entry_date'                    =>    $date,
    'dst_enabled'                =>    'n',
    'edit_date'                    =>    date("YmdHis"),    
    'versioning_enabled'        =>    'n',
    'year'                      =>     date('Y'),
    'month'                     =>     date('m'),
    'day'                       =>    date('d'),
    'expiration_date'             =>     $expire,
    'comment_expiration_date'    =>     0,
    'sticky'                    =>     'n',
    'status'                    =>     $status,
    'allow_comments'            =>     'n',
    'allow_trackbacks'          =>     'n',
    'forum_topic_id'            =>     0                                        
);

$this->db->insert('_weblog_titles', $title_data[$key]); 
$title_entry_id = $this->db->insert_id();  

// Insert data into exp_relationships
$relation_data[$key] = array(
    'rel_id'        =>    '',
    'rel_parent_id'    =>    $title_entry_id,
    'rel_child_id'    =>    $child,
    'rel_type'        =>    'blog'
);

$this->db->insert('_relationships', $relation_data[$key]); 
$relation_entry_id = $this->db->insert_id();

// Insert custom data
$custom_data[$key] = array (
    'entry_id'    => $title_entry_id, 
    'site_id'    => $site_id,
    'weblog_id' => $weblog_id
);

// Set child field
$custom_data[$key]['field_id_32'] = $child; 
$this->db->insert('_weblog_data', $custom_data[$key]);

Everything work well, data stored in the database seems good (I’ve looked at some var dump). But For a few entry, the relation doesn’t appear correct in the edit panel : relation selected option isn’t the good one !

When editing I change it from the edit panel to the good one, it still don’t work. But when I change to another one, then save, then edit and change it again but to the good one, it works !

I know my question is a bit difficult to understand, but all help would be appreciated because I’m really stuck right now !

Thanks in advance !

Regards,

       
evasion's avatar
evasion
58 posts
17 years ago
evasion's avatar evasion

I’ve found the solution, post it there, it may help :

Here’s some nice wiki article about inserting relationship manually : http://expressionengine.com/wiki/Relationships_-_Under_the_Hood/

My error was to insert child id into exp_weblog_data custom field, instead of auto-generated rel_id :

// Error was : $custom_data[$key]['field_id_32'] = $child;
// Must insert auto-generated rel_id 
$custom_data[$key]['field_id_32'] = $relation_entry_id;

Sorry for disturbing 😊

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Thanks for this Evasion… I’m working on a new module that uses relationships as well. This could save me a couple of hours. Good work!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.