ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

exp:channel:entries showing old (cached) data when using api submit_new_entry() to add entries

September 27, 2010 11:41am

Subscribe [3]
  • #1 / Sep 27, 2010 11:41am

    applicode

    5 posts

    EE 2.0 Build 20100810

    Entries appear to get cached when using $this->EE->api_channel_entries->submit_new_entry.

    In config/database.php the cache is set to FALSE
    $db[‘expressionengine’][‘cache_on’] = FALSE;

    In Admin/System Administration/ Database Settings, the Enable SQL Query Caching is set to No
    Enable SQL Query Caching:  no

    Apparently ExpressionEngine 2.1.0 build 20100805 disabled db caching but I am still seeing an issue:
    * Temporarily disabled db caching for all installations until all db caching issues are resolved.

    HOW TO REPRODUCE:

    Create a channel called “test”

    Do not assign any custom fields or categories.
    We’ll just use the title.
    Assign the default status group to the channel (open/closed)

    Note the channel id for the new channel (test).  You’ll need it in the code below:

    Create a template group called Test

    Add two templates (index and add) - see below. Be sure to Allow PHP / output for the add template.

    Go to site_url.com/test
    THen click add.

    Add a title and submit.  You will see that the list (index template) will only occupationally update.  You’ll need to refresh the page (site_url.com/test) to see the new entry.  Keep adding titles - some will display immediately while others will need a page refresh.


    template: index

    <a href="http://{site_url}test/add">+ Add</a>
    
    
    
    
    {exp:channel:entries channel="test" orderby="date" sort="desc"}
            
        {if no_results}No test data found.{/if}
                    
                       <div>{total_results}{title}</div>
    
    {/exp:channel:entries}

     

    NOTE: in the template add, you will need to modify the following two lines with your channel id for for test - in my case, my channel id is11.

    'channel_id' => 11, // temporary hack for ee bug
    
    if ($this->EE->api_channel_entries->submit_new_entry(11, $data) === FALSE)

    template:  add

    <?php
    
    $this->EE->load->library('api');
    $this->EE->load->library('form_validation');
    $this->EE->load->helper('form');
    
    $error_string = '';
    
    $this->EE->form_validation->set_rules('title', 'title', 'trim|required|xss_clean');    
    
    if ($this->EE->form_validation->run() == FALSE)
        $error_string = '<div class="error">'.$this->EE->form_validation->error_string().'</div>';
    else if (isset($_POST['submit-add'])) 
    {
        
        $data = array(     'title' => $this->EE->input->post('title'),
                    'entry_date' => time(), 
                    'expiration_date' => time()+30*24*60*60, // expires in 30 days 
                    'author_id' => $this->EE->session->userdata['member_id'],
    
                    'status' => 'open',            
                        
                    'channel_id' => 11, // temporary hack for ee bug
                
                        ); 
        $this->EE->api->instantiate('channel_entries');
        $this->EE->api->instantiate('channel_fields');
        if ($this->EE->api_channel_entries->submit_new_entry(11, $data) === FALSE)
        { 
            show_error('An Error Occurred Creating the Entry'); 
        } 
        
        $this->EE->functions->redirect('/test');
    
        return;
    }
    
    
    //   display add form 
    
    echo $error_string;
    
    echo form_open('test/add');
    
    
    $data = array(
                  'name'        => 'title',
                  'id'          => 'title',
                  'value'       => set_value('title', ''),
                  'maxlength'   => '40',
                  'size'        => '40',
                );
    
    echo 'Title '.form_input($data);
    
    
    
    echo '
    ';echo '
    ';
    
    echo form_submit('submit-add', 'Submit Test');
    
    echo form_close();
    ?>
  • #2 / Sep 27, 2010 2:38pm

    Rob Sanchez

    335 posts

    It could be the date—test by adding show_future_entries=“yes” to your channel:entries tag.

  • #3 / Sep 27, 2010 3:05pm

    applicode

    5 posts

    Wow.  Thanks.  I just tried added show_future_entries=“yes” and it fixed the problem. 

    As I was sitting here trying to figure out why it would work with show_future_entries=“yes” I realized it might have to do with my entry_date.  I checked the code that and found that if show_future_entries is not set, then it adds the following to the where clause:

    $sql .= " AND t.entry_date < ".$timestamp." ";

    Since my entry_date in some cases is EQUAL to the timestamp it ends up not showing the latest entry.

    The other option I have would be to set my entry_date = time() -1

    Thanks again.  That was my issue.

  • #4 / Sep 27, 2010 3:17pm

    Ingmar

    29245 posts

    Glad to see Rob was able to help (Thanks for the assist!), and please post again as needed in the future.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases