0

I have a situation where I need to create a node that is of a custom content type outside of drupal.

Is there anything involved besides inserting an entry into the node table and data into the content type table?

3 Answers 3

3

Unless you known exactly what you are doing, don't try to integrate with Drupal at the database level.

Drupal database schema is dynamic. Tables to store nodes information are added and modified when you add fields or change theirs settings. So your database query will need to be checked for every changes. This could easily become a maintenance nightmare.

Any module can, an many do, add custom behaviors on node insertions and updates through Drupal hooks system. Inserting content in the database without using Drupal's API would bypass these added behavior and potentially create inconsistent data.

If you must really do it outside Drupal, you can either bootstrap Drupal in your PHP standalone script to be able to use its API or use the Services module to provides a REST API for node CRUD operations.

To bootstrap Drupal in your PHP script, use the following code. Note that most of Drupal's code expect the current dir to be Drupal's one. Drupal also register its own session handler that may conflicts with yours.

chdir("/path/to/drupal");
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
1
  • Thanks, very useful information. I had no idea you could bootstrap Drupal.
    – cbaigorri
    Dec 1, 2011 at 13:08
0

Maybe you can try to use the feeds module (http://drupal.org/project/feeds). That way you can have data in external databases, export them to csv, .... and then use feeds to import them. The module has a nice feature of mapping custom fields (eg. defined in your export csv file) to fields available in Drupal. If you use this module, you don't need to think about saving the data yourself to the correct tables,it handles that stuff for you.

0

If your code is run as CLI you could write it as a drush command. This way all the bootstraping is done for you for free.

Once you have you're drush command you can use it in almost any shell script.

The drush module has a good example on how to write your own commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.