1

I am writing script to download, install and configure new Drupal site. The download and install steps are working, however. In the third step - configuration, i would like drush to bootstrap from the new installed directory, so the Drupal API is available for functions such as variable_set(),drupal_parse_info_file(). Here is the script so far:

#!/usr/bin/env drush
<?php

$default_dest = 'test-core';
$default_make = '../builds/build-drupal-core.make';
$make_file = ($build_src = drush_get_option('build-src', FALSE)) ? $build_src : $default_make;
$dest = ($build_dest = drush_get_option('build-dest', FALSE)) ? $build_dest : $default_dest;
$status = _process_make_file($make_file, $dest);
drush_print('Make Download '.(($status) ? "SUCCESS" : "FAILURE" ));

# Site
##########################################################
$siteName="Test Site";
$siteSlogan="Some test site";
$siteLocale="en";
##########################################################

# Database
##########################################################
$dbHost="localhost";
$dbName="drupal_test_db";
$dbUser="test_user";
$dbPassword="xxxxxx";
$dbPort ="3306";
##########################################################

# Admin
##########################################################
$AdminUsername="admin";
$AdminPassword="password";
$adminEmail="admin@example.com";
##########################################################

# Install core
##########################################################
// go to installed dir
drush_op('chdir', $dest);

$status = drush_invoke_process('@self', 'site-install', array('standard'), array(
                                                              'account-mail'=> $adminEmail,
                                                              'account-name' => $AdminUsername,
                                                              'account-pass' => $AdminPassword,
                                                              'site-name' => $siteName,
                                                              'locale' => $siteLocale,
                                                              'db-url' => 'mysql://'.$dbUser.':'.$dbPassword.'@'.$dbHost.':' . $dbPort . '/'.$dbName,
                                                        )
                              );
drush_print('Site Install - ' . (($status) ? 'SUCCESS' : 'FAILURE'));


//check if we can bootstrap
$self = drush_sitealias_get_record('@self');
if (empty($self)) {
    drush_die("I can't bootstrap from the current location.", 0);
}

# Enable modules
##########################################################
//@ToDo read from make file and enable modules
$build_file_parsed = drupal_parse_info_file($build_src);
print_r($build_file_parsed);

# Pre configure settings
##########################################################
//variable_set();

I tried different things as described in drush-isnt-bootstrapping-drush-script. I also tried something like creating dynamic alias:

$cur_dir = getcwd();
$site = array(
        'root' => $cur_dir,
        'uri' => 'http://default',
        '#name' => 'self',
        'path-aliases' => array(
            '%root' => $cur_dir
        ),
);

drush_bootstrap_max_to_sitealias($site);

All of the attempts have failed. How would one bootstrap from currently installed Drupal dir via drush script, so the Drupal API is available? Thank you

EDIT:

So, with a little bit more of understanding of Aliases, Phases and Bootstraping, i have

$site2 = drush_sitealias_get_record($cur_dir.'#default');
$boot_status = drush_bootstrap_max_to_sitealias($site2, DRUSH_BOOTSTRAP_DRUPAL_FULL);
drush_print('Attempting Bootstrap ' . (($boot_status) ? 'Yes' : 'No'));
drush_print('Current bootstap phase: ' . drush_get_context('DRUSH_BOOTSTRAP_PHASE'));

//perhaps it takes time to bootstrap
while(!drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)){
    sleep(2);
    drush_print('waiting...current phase '.drush_get_context('DRUSH_BOOTSTRAP_PHASE'));
}

This showed that the phase is staying the same '0' even thou the variable 'boot_status' confirming the attempt to bootstrap. Then i looked at the error:

($errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS')) ? print_r($errors) : drush_print('no errors') ;

This was printing the following error:

[DRUSH_NO_DRUPAL_ROOT] => A Drupal installation directory could not be found

I am confused because we are in the new install root directory. In addition, the alias is specifying the root as following(printed $site2):

[uri] => default
[root] => /Users/latvian/Sites/drupal/test/test-core
[path-aliases] => Array
    (
        [%root] => /Users/latvian/Sites/drupal/test/test-core
    )

[#name] => .Users.latvian.Sites.drupal.test.test-core#default

Why would drush not see the new install root directory? Thank you

2
  • You probably need to change directory into the sites/default folder and execute the install command from there. Jan 8 '14 at 20:42
  • Thank You Chadpeppers, but its already doing here(before 'site-install'), or i am missing something?
    – latvian
    Jan 8 '14 at 22:49
1

i wasn't able to figure out how to bootstrap the new Drupal instance in the installation directory as i would like, but what worked was creating a separate drush script only for configuring the instance and call it from the installation script as following:

drush_shell_exec('drush ../config/drush-scripts/configure-site.php --debug --build-src=the-make-file-installing-the-site.make');

And the configuration script:

#!/usr/bin/env drush
<?php    

// check if we can bootstrap
$self = drush_sitealias_get_record('@self');
if (empty($self)) {
    drush_die("I can't bootstrap from the current location.", 0);
}

//go to the install dir
drush_op('chdir', $self['root']);


# Enable modules
##########################################################
$build_file_parsed = drupal_parse_info_file($make_file);
$modules_to_enable = array_diff($build_file_parsed['projects'],array('drupal'));
$modules_enabled = drush_invoke_process("@self", "pm-enable", $modules_to_enable);
drush_print('Modules ' . (($modules_enabled) ? 'WAS' : 'WAS NOT' ). '  Enabled');

# Pre configure settings
##########################################################
# disable user pictures
variable_set('user_pictures',0);

# allow only admins to register users
variable_set('user_register',0);

# set site slogan
variable_set('site_slogan',$siteSlogan);

# Configure JQuery update
variable_set('jquery_update_compression_type', "min");
variable_set('jquery_update_jquery_cdn',"google");
variable_set('jquery_update_jquery_version',"1.7");

I hope one day it will become apparent why i wasn't able to do all - download, install and configure in one drush script or if you know, please, share

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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