Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Afief on
Hello,
I am building a website from a huge amount of files that are generated from a shell script, I have found a way to insert the generated HTML pages into drupal by using the following code:
<?
function mySave($type, $title, $body)
{
$edit = array();
$edit['type'] = $type;
// get the node type defaults
$edit['uid'] = 1;
$edit['name'] = 'mathQuestion';
$edit['promote'] = 0;
$edit['comment'] = 0;
//$edit['revision'] = ;
$edit['format'] = FILTER_HTML_ESCAPE;
$edit['status'] = 1;
$edit['title'] = $title;
$edit['body'] = $body;
$edit['date'] = format_date(time(), 'custom', 'Y-m-d H:i:s O');
node_invoke_nodeapi($edit, $type);
node_validate($edit);
if ($errors = form_get_errors()) {
print_r($errors);
}
$node = node_submit($edit);
node_save($node);
}
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if($_SERVER['argc'] != 4)
{
echo "Expected 3 arguments: FileName,Question,PageNumber\n";
die();
}
$arg=$_SERVER['argv'];
$title=$arg[2] . $arg[3];
$myFile=$arg[1];
$fh = fopen($myFile, 'r');
if($fh==FALSE)
{
echo "Unable To Open File $myFile";
die();
}
$size=filesize($myFile);
$content = fread($fh, $size);
fclose($fh);
mySave('mathsln',$title,$content);
?>
What I am unable to figure out is how to group my new nodes using taxonomies. How to create those Taxonomies through code would be great too, but I can do that manually.
Thanks in advance,
Afief