Stock Blog module bug: data lost on update when outside edit view

edited October 2012 in Bug Reports
Hi there,

I just found out that in v0.93 when a model gets updated from outside the EDIT view (ie clicking on Published: yes/no from the LIST view) the associated categories get lost. This is happening because inside the on_after_save function the categories are first deleted and then re-entered depending on the selection made by the user. But obviously no selection is made from within the LIST view, and so the previously entered categories are lost.

Is this something you're aware of?

Comments

  • edited 9:29AM
    This should be fixed in the 1.0 branch. It's no longer using the blog_categories_to_posts_model but instead using the new relationships functionality in 1.0:
    https://github.com/daylightstudio/FUEL-CMS/tree/1.0
    https://github.com/daylightstudio/FUEL-CMS-Blog-Module
  • edited 9:29AM
    That's good to know, however I'm stuck on 0.93 for this project I'm working on, and I'd appreciate it a lot if you could maybe point me in the right direction for a quick fix...

    I'm thinking something like finding a way to check if the 'save' event is being triggered from an ajax form... or maybe setting some 'nulled' value when the user is actually removing the categories rather than not passing any (which is the cause for inline edits losses)... but I'm kinda stuck!

    Anu clues?
    Cheers for the great work on v1!
  • edited 9:29AM
    You can try the following:

    1. Add a hidden field in the blog_posts_model form_fields method of something like "categories_exists":
    $fields['categories_exists'] = array('type' => 'hidden', 'value' => '1');
    2. In the on_after_save_hook of the blog_posts_model, you can add check for that value:
    if (!empty($saved_data['categories_exists'])) { $post_id = $values['id']; $categories = (!empty($saved_data['categories'])) ? $saved_data['categories'] : array(1); // 1 = Uncategorized // first remove all the categories $CI->blog_posts_to_categories_model->delete(array('post_id' => $post_id)); // then readd them foreach($categories as $val) { $post_category = $CI->blog_posts_to_categories_model->create(); $post_category->post_id = $post_id; $post_category->category_id = $val; $post_category->save(); } }
  • edited 9:29AM
    Gosh, why didnt I think of this ???!!
    Thanks a lot man, you made my day
Sign In or Register to comment.