EllisLab text mark
Advanced Search
     
exp:channel:entries showing old (cached) data when using api submit_new_entry() to add entries
Posted: 27 September 2010 11:41 AM   [ Ignore ]
Joined: 2008-05-05
9 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="{site_url}test/add">+ Add</a>
<
br />


{exp:channel:entries channel="test" orderby="date" sort="desc"}
        
    {if no_results}
<p>No test data found.</p>{/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 
'<br />';echo '<br />';

echo 
form_submit('submit-add''Submit Test');

echo 
form_close();
?> 
 
Posted: 27 September 2010 02:38 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-03
319 posts

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

 Signature 

http://robsanchez.com
http://twitter.com/_rsan
http://github.com/rsanchez

 
Posted: 27 September 2010 03:05 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-05-05
9 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.

 
Posted: 27 September 2010 03:17 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2004-05-15
29075 posts

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