Skip to content

Instantly share code, notes, and snippets.

@danbruder
Last active December 21, 2015 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbruder/6311297 to your computer and use it in GitHub Desktop.
Save danbruder/6311297 to your computer and use it in GitHub Desktop.
<?php
$results = db_select("old_table", "w")
->fields('w')
->execute();
foreach($results as $child){
$node = new stdClass();
$node->type = "waiting_child";
node_object_prepare($node);
$node->title = $child->name;
$node->language = LANGUAGE_NONE;
$node->uid = 1;
$node->status = 1;
if(preg_match("/removed/i", $child->status)){
$node->status = 0;
}
$node->field_waiting_child_profile[$node->language][0]['value'] = $child->short_desc;
$node->field_waiting_child_profile[$node->language][0]['format'] = 'wysiwyg';
$node->field_waiting_child_country[$node->language][0]['target_id'] = 38;
//$node->field_waiting_child_dob[$node->language][0]['value'] = strtotime($child->dob);
if(preg_match("/Family Link Pending!/", $child->status)){
$child->status = "pending";
}
elseif(preg_match("/I'm Home with my family!/i", $child->status)){
$child->status = "placed";
}
elseif(preg_match("/Linked to family!/i", $child->status)){
$child->status = "placed";
}
$node->field_waiting_child_status[$node->language][0]['value'] = $child->status;
$file_path = drupal_realpath(file_default_scheme() . '://' . '/waiting_child_china_photos/' . $child->pic);
if(file_exists($file_path)){
$file = (object) array(
'uid' => 1,
'uri' => $file_path,
'filemime' => file_get_mimetype($file_path),
'status' => 1,
);
$file = file_copy($file, 'public://waiting_child_china_photos');
$node->field_waiting_child_image[$node->language][0] = (array) $file;
}
elseif($node->status == 1){
dsm("Missing file for " . $child->name);
}
if($node = node_submit($node)) { // Prepare node for saving
node_save($node);
dsm("Child saved: " . $node->title);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment