I am using the channel entry api to sync a bit of data into ExpressionEngine. The problem seems to be that the update_entry call needs to have all data for the entry, otherwise the current data gets flattened.
For example.. Say I have a channel that has 10 channel fields..
If I try to update 1 via update_entry, the data in the other 9 gets lost..
$data = array(
'channel_id' => 8,
'title' => 'test',
'entry_date' => time(),
'field_id_1' => 'test data'
);
$this->EE->api_channel_entries->update_entry(1, $data)Produces a mysql update for exp_channel_data like:
UPDATE `exp_channel_data` SET `channel_id` = 8, `field_id_1` = 'test data', `field_id_2` = '', `field_id_3` = '', `field_id_4` = '', `field_id_5` = '', `field_id_6` = '', `field_id_7` = '', `field_id_8` = '', `field_id_9` = '', `field_id_10` = '', WHERE `entry_id` = '1'Is there anyway around this?
If not, the documentation should probably be updated to remove the word “required”
http://ellislab.com/expressionengine/user-guide/development/api/api_channel_entries.html#update-entry This function will update a channel entry. The data array must contain a title, an entry date, and data for all required fields.
Thanks -tim
[EDIT] Looking through the code, it appears this behavior is intended. Lines 928-929 of Api_channel_entries.php state:
// Make sure all the fields have a key in our data array even
// if no data was sentThe next line it looks like this is bypassable if i set “autosave” to TRUE.
What is “autosave” and what would happen if I set it to TRUE? (I can’t find any documentation that relates to “autosave”) [/EDIT]
Hi timmaah,
We don’t generally offer support on Development issues, but I have an idea that might get you a workaround. If you sidestep the API and create the query statement directly, you should be able to update only the fields you intend.
$query = "UPDATE exp_channel_data SET channel_id = 8, title = 'test', entry_date = time(), field_id_1 = 'test date' WHERE entry_id = 1"
$this->EE->db->query($query);That’s untested and off the top of my head, it may require some tweaks 😉
To better serve this thread, I’m going to move it over into Development and Programming to keep the discussion going.
Cheers!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.