I am importing data into drupal from an old site. I wrote a script to parse an html page and insert the new nodes. The script runs correctly and I see all of the data in the DB. However, when I view nodes through drupal, some of the fields do not show.

For example, I have custom content type "Publication." A publication has title&body + url and type (both text). When I look at the content_type_publication table in phpMyAdmin, for the first node I see that field_type_value="print" and field_url_value="http://employeebenefitnews.blogspot.com/". But when I go to mysite.com/node/1, I do not see type: print
url:http://employeebenefitnews.blogspot.com/. On the page html, <div class="field field-type-text field-field-url"> is missing entirely.

If my data is in the database, why isn't it showing up on the site? I will paste my code below. Am i missing some inserts?

function insert_publication( $pub_name, $type, $time, $url ) {
	global $db_conn;
	if( empty( $url ) || is_null( $url ) ) {
		$url = '';
	}

	// create node
	mysql_query( "insert into node (type, title, uid, status, created, changed, comment) VALUES ('publication', '".$pub_name."', 1, 1, ".$time.", ".$time.", 2)", $db_conn );
	$nid = mysql_insert_id( $db_conn );
	mysql_query( "update node set vid=".$nid." where nid=".$nid, $db_conn );
	
	// create revision
	mysql_query( "insert into node_revisions (nid, vid, uid, title, timestamp) values (".$nid.", ".$nid.", 1, '".$pub_name."', ".$time.")", $db_conn );
	
	// create comment statistics
	mysql_query( "insert into node_comment_statistics (nid, last_comment_timestamp, last_comment_uid) values (".$nid.", ".$time.", 1)", $db_conn );
	
	// add auxillary fields
	mysql_query( "insert into content_type_publication (vid, nid, field_type_value, field_url_value) values (".$nid.", ".$nid.", '".$type."', '".$url."')", $db_conn );
	
	// return nid
	return $nid;
}

Comments

jasonsafro’s picture

<?php
	// Get file
	$file = file_get_contents( './news.txt' );
	
	// Drop brackets
	$file = str_replace( array( '<', '>', 'target="_blank"' ), array( '&lt;', '&gt;', '' ), $file );
	
	// Match
	$regex = '/(&lt;a href=\")(.+)(\"&gt;)(.+)(&lt;\/a&gt;)(.+)(&lt;br&gt;)(.+)(&lt;br&gt;)/U';
	$matches = array();
	echo preg_match_all( $regex, $file, $matches );
	
	//DB connect
	$db_conn = mysql_connect( 'localhost', 'telework', 'tuRP7pa5LrCexbsb' );
	mysql_select_db( 'telework', $db_conn );
	
	// declare time
	$time = 1224623048;
	
	for( $i = 0; $i<count( $matches[0] ); $i++ ) {
		$time+=2;

		// Get data
		$url = trim($matches[2][$i]);
		$title = trim($matches[4][$i]);
		$date = trim($matches[6][$i]);
		$pub_name = trim($matches[8][$i]);
		
		// Remove italics tags from pub name and get type
		$regex = '/(&lt;i&gt;)(.+)(&lt;\/i&gt;)/';
		$pub_matches = array();
		if( preg_match( $regex, $pub_name, $pub_matches ) ) {
			$pub_name = $pub_matches[2];
			$type = 'print';
		} else {
			$pub_name = $pub_name;
			$type = 'web';
		}

		// Get Pub URL from $url
		$regex = '/^(http:\/\/)([A-z0-9]+)(\.)([A-z0-9]+)(\.)([A-z]{2,5})(\/)/U';
		$pub_url_matches = array();
		preg_match( $regex, $url, $pub_url_matches );

		// Look for publication
		$pub_nid = find_publication_nid( $pub_name );
	
		// Create publication
		if( empty( $pub_nid ) ) {
			$pub_nid = insert_publication( $pub_name, $type, $time, $pub_url_matches[0] );
		}
		
		// Create news item
		insert_news_item( $title, $url, $date, $pub_nid, $time );
	}
	
	function insert_news_item( $title, $url, $date, $pub_id, $time ) {
		global $db_conn;
		$time+=1;

		mysql_query( "insert into node (type, title, uid, status, created, changed, comment) VALUES ('news_item', '".$title."', 1, 1, ".$time.", ".$time.", 2)", $db_conn );
		$nid = mysql_insert_id( $db_conn );
		mysql_query( "update node set vid=".$nid." where nid=".$nid, $db_conn );
		
		// create revision
		mysql_query( "insert into node_revisions (nid, vid, uid, title, timestamp) values (".$nid.", ".$nid.", 1, '".$title."', ".$time.")", $db_conn );
		
		// create comment statistics
		mysql_query( "insert into node_comment_statistics (nid, last_comment_timestamp, last_comment_uid) values (".$nid.", ".$time.", 1)", $db_conn );
		
		// add auxillary fields
		$formatted_date = str_replace( '-:-', 'T', date( 'Y-m-d-:-00:00:00', strtotime( $date ) ) );
		mysql_query( "insert into content_type_news_item (vid, nid, 	field_news_item_url_value, field_publication_date_value, field_publication_nid ) values (".$nid.", ".$nid.", '".$url."', '".$formatted_date."', '".$pub_id."')", $db_conn );
	}
	
function insert_publication( $pub_name, $type, $time, $url ) {
	global $db_conn;
	if( empty( $url ) || is_null( $url ) ) {
		$url = '';
	}

	// create node
	mysql_query( "insert into node (type, title, uid, status, created, changed, comment) VALUES ('publication', '".$pub_name."', 1, 1, ".$time.", ".$time.", 2)", $db_conn );
	$nid = mysql_insert_id( $db_conn );
	mysql_query( "update node set vid=".$nid." where nid=".$nid, $db_conn );
	
	// create revision
	mysql_query( "insert into node_revisions (nid, vid, uid, title, timestamp) values (".$nid.", ".$nid.", 1, '".$pub_name."', ".$time.")", $db_conn );
	
	// create comment statistics
	mysql_query( "insert into node_comment_statistics (nid, last_comment_timestamp, last_comment_uid) values (".$nid.", ".$time.", 1)", $db_conn );
	
	// add auxillary fields
	mysql_query( "insert into content_type_publication (vid, nid, field_type_value, field_url_value) values (".$nid.", ".$nid.", '".$type."', '".$url."')", $db_conn );
	
	// return nid
	return $nid;
}

	function find_publication_nid( $pub_name ) {
		global $db_conn;
		
		$sql = "select nid from node where type='publication' and title='".$pub_name."'";
		$result = mysql_query( $sql, $db_conn );
		
		$row = mysql_fetch_assoc( $result );
		mysql_free_result( $result );
		
		return $row['nid'];
	}

?>