16 May 2014

Drupal 7 has an issue discussing some strategies for inclusion. However, I wanted to accomplish a similar task in Drupal 6. One flaw with triggering the standard Drupal bootstrap is that it attempts to handle the request. A strategy that was more successful for me, at least within the context of command-line scripts, was to bootstrap Drupal via Drush to avoid the Drupal FrontController pattern. The code was pretty simple.

define('DRUPAL_ROOT', "/path/to/site");
include_once '/path-to-DRUSH-module-directory/includes/bootstrap.inc';
drush_bootstrap_prepare();
drush_set_option('root', DRUPAL_ROOT);
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL);

Drush creates some listeners, so you should be aware of their impact. For instance, if you exit(), then you will see "Drush command terminated abnormally due to an unrecoverable error." As long as the script runs to the end, however, the impact is still far less than a full Drupal bootstrap.

Technologies:


blog comments powered by Disqus