Created
December 30, 2008 17:36
-
-
Save akahn/41679 to your computer and use it in GitHub Desktop.
This file contains 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
function sti_migrate_import($options, &$context) { | |
// For node_object_prepare() | |
module_load_include('inc', 'node', 'node.pages'); | |
module_load_include('inc', 'filefield', 'field_file'); | |
$query = 'SELECT * FROM {sti_stories} ORDER BY imagefile DESC'; | |
$context['sandbox']['progress'] = 0; | |
$context['sandbox']['results'] = array(); | |
$context['sandbox']['max'] = $options['count']; | |
db_set_active('stories'); | |
$result = db_query_range($query, $options['from'], $options['count']); | |
db_set_active(); // back to default | |
while ($story = db_fetch_object($result)) { | |
$node = new stdClass(); | |
$node->type = 'tell_your_story'; | |
$node->uid = 0; // Anonymous submission | |
$node->taxonomy = _get_taxonomy_term($story->i_am); | |
$node->name = 'Alex Kahn'; | |
$node->title = $story->first || $story->last ? $story->first . ' ' . $story->last : 'Anonymous'; | |
$node->body = $story->comment; | |
node_object_prepare($node); | |
$node->field_story_title[0] = array('value' => $story->subject); | |
$node->field_email[0] = array('email' => $story->email); | |
$node->locations[0] = array( | |
'city' => $story->city, | |
'state' => $story->state, | |
'postal_code' => $story->zip, | |
); | |
if ($story->in_rotation == 'Y') { | |
$node->field_story_featured[0] = array('value' => 1); | |
} | |
if ($story->imagefile != NULL && $story->imagefile != '') { | |
$image = file_create_path("migrate/" . $story->imagefile); | |
$field = content_fields('field_story_image', 'tell_your_story'); | |
$validators = array_merge(filefield_widget_upload_validators($field), | |
imagefield_widget_upload_validators($field)); | |
$files_path = filefield_widget_file_path($field); | |
$file = field_file_save_file($image, $validators, $files_path); | |
$node->field_story_image = array(0 => $file); | |
} | |
$node = node_submit($node); | |
node_save($node); | |
$context['sandbox']['progress']++; | |
$context['sandbox']['results'][] = $node->title; | |
$context['message'] = "Now processing " . $node->title; | |
} | |
if ($context['sandbox']['progress'] != $context['sandbox']['max']) { | |
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment