Is it possible to add new nodes (custom content-types actually) via SQL instead of through the site?

I've got a database of products (1800 or so) that I want to import into my custom content-types. I have a background job that creates these rows in another table, what I need to do is convert these to new nodes and have drupal index them, etc.

Is this possible? Any examples?

I looked at the node.module and see where adding a new node is done. I can copy this code and and duplicate it, just curious if there was a backdoor method (i.e. INSERT into ...) to accomplish the same thing.

Thanks again, in advance.

-- J

Comments

Scott Reynolds’s picture

http://api.drupal.org/api/4.7/function/node_save that is the documentation on it.

create a php script that creates the node objects from existing data and pass it along to node_save.

To create said php script make sure u do these following things:

   require_once "path/to/drupal/directory/includes/bootstrap.inc

Then before looping through and calling all the node_save

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // makes ur script an offical Drupal script

// ... loop through
node_save($new_node_object_from_old_item);

Doing it this way allows all the drupal modules that you have enabled to react to a new item being added....

Not sure if this helps you or if its the right direction for your project. But it is how I would add nodes from existing data

brenda003’s picture

First, you'll need to create the content type via something like CCK or Flexinode. Then you can use the node import module at http://drupal.org/project/node_import
--
Abtech Creative: Beautiful Design Powered by Beautiful Development

Scott Reynolds’s picture

but I believe he has created his own module that defines his content-type. And node_import only works with a select number of content-types and it seems that CCK import isn't done yet either.

By doing it my complex way you will actually be simulating logging into the site, filling out the node creation form and submitting it. Just does it through programming, and no form validation.

lucifurious’s picture

I didn't create a new module, I created a new node type with the CCK. I have a table of data that I want to convert into nodes.

seakayjay’s picture

I'm looking into the same thing as xx666xx does. Have you get to know on how to add new nodes to database with SQL? Do you mind sharing with me on how can it be done? I'm still struggling on this issue because I've more than 1000 entries of content in SQL and I want to transfer them to MySQL in Drupal. I know this somehow can be done by writing a php script as mentioned by Scott Reynolds but my knowledge in PHP is pretty limited. I really need help in doing this...

Someone please... help me out, I don't want to manually key in all the entries.

Thank you in advance.

lucifurious’s picture

but I used the content import module which allowed me to import a CSV of my data (which I pulled from SQL). :)

seakayjay’s picture

How to use import module? Do you mind instruct me on how to use that?

When i point my browser to http://www.example.com/admin/node/node_import it doesn't seem to import anything.

and what is CSV btw? And read through the documentation provided already at http://drupal.org/handbook/modules/node_import but i didn't get anything from it.

Any help would be appreciated.

Thanks

seakayjay’s picture

Ooops... i used 4.6 module on 4.7. no wonder i can't see the import page.

so now i can see the import page... how's the csv file gonna look like? can you provide me a sample on how csv data looks like?