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="[email protected]";
##########################################################
# 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