function insert_door_to_drupal($door_id) { // set HTTP_HOST or drupal will refuse to bootstrap $_SERVER['HTTP_HOST'] = 'zl-apps'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; include_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $door = new Door(); $door_detail = $door->read(null, $door_id); $door_nid = null; $query = new EntityFieldQuery(); $entities = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', 'doors')->propertyCondition('status', 1)->fieldCondition('field_door_id', 'value', $door_detail['Door']['id'], '=')->execute(); foreach ($entities['node'] as $nid => $value) { $door_nid = $nid; break; // no need to loop more even if there is multiple (it is supposed to be unique } $node = null; if (is_null($door_nid)) { $node = new stdClass(); $node->language = LANGUAGE_NONE; } else { $node = node_load($door_nid); } $node->type = 'doors'; node_object_prepare($node); $node->title = $door_detail['Door']['door_style']; $node->field_door_id[$node->language][0]['value'] = $door_detail['Door']['id']; $node->sell_price = 0; $node->model = $door_detail['Door']['door_style']; $node->shippable = 1; $path = 'door/' . $node->title; $node->path = array('alias' => $path); node_save($node); }