Created
July 7, 2011 02:08
-
-
Save iainurquhart/1068770 to your computer and use it in GitHub Desktop.
Importing/updating via the channel_entries api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// a bunch of stuff up here that fetches/preps the external data | |
// basically create an array with all your data to insert / update | |
$data = array( | |
'title' => $operator['nameofbusiness'], | |
'entry_date' => date("Y-m-d h:i A", $entry_date), | |
'channel_id' => $channel_id, | |
'category' => array($category_id), | |
'status' => ($operator['ts_share'] == 1) ? 'Not Shared' : 'open', | |
'field_id_1' => $operator['activitydetails'], | |
'field_ft_1' => 'xhtml', | |
... etc etc | |
// in my module I'm doing a check if we're updating or inserting | |
// so a query here to see if the incoming ID matches what we got | |
// we've got a match | |
if($match) | |
{ | |
if ($this->EE->api_channel_entries->update_entry($data['entry_id'], $data) === FALSE) | |
{ | |
// got an error | |
$this->EE->tnz_utils->log_item('An Error Occurred UPDATING: '.$operator['nameofbusiness']); | |
foreach($this->EE->api_channel_entries->errors as $error) | |
{ | |
$this->EE->tnz_utils->log_item($error."\n"); | |
} | |
} | |
else | |
{ | |
// success | |
$this->EE->tnz_utils->log_item('Updated entry_id: '.$data['entry_id']."\n"); | |
$this->EE->tnz_utils->log_item('category id: '.$category_id."\n"); | |
$this->EE->tnz_utils->log_item('Sort order: '.$data['field_id_56']."\n"); | |
} | |
} | |
// inserting a new entry | |
else | |
{ | |
$this->EE->tnz_utils->log_item('No match found, inserting new entry'); | |
if ($this->EE->api_channel_entries->submit_new_entry($channel_id, $data) === FALSE) | |
{ | |
$this->EE->tnz_utils->log_item('An Error Occurred Importing: '.$operator['nameofbusiness']); | |
} | |
else | |
{ | |
// store the entry_id for reporting & cleanup | |
$imported_ids[] = $this->EE->api_channel_entries->entry_id; | |
$this->EE->tnz_utils->log_item('Insert OK'); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment