Accessing hosting data from an install profile

Events happening in the community are now at Drupal community events on www.drupal.org.
benkant's picture

Hello chaps and chapettes,

Previously I've been able to use the various provision_db_connect(), provision_db_fetch_array() functions to obtain data from the aegir database from within my install profile for a newly provisioned site. With the new services abstraction these functions appear to be gone.

An example of what I need to do might be adding a openid credentials of the aegir client that created the site, or setting the site_name based on information gathered when the user created the site.

Something like...

  provision_db_connect();
  mysql_select_db(AEGIR_DB_NAME);
  $domain = variable_get('site_name', '');
  $site = provision_db_fetch_array(provision_db_query("SELECT * FROM node WHERE title = '%s'", $domain));
  $aegir_user = provision_db_fetch_array(provision_db_query("SELECT * FROM users WHERE uid = %d", $site['uid']));
  $aegir_url = unserialize(provision_db_result(provision_db_query("SELECT value FROM variable WHERE name = 'aegir_domain'")));
  variable_set('site_name', _get_site_name($site['uid'], $domain));
  // add openid authmap entry etc...

Those are simple examples but conceivably the install profile might need to get more complicated and dynamic data from hosting's database.

I thought perhaps I could use drush_set_option() in a drush provision hook and then in the profile drush_get_option, but it's a different instance of drush (I think) so that won't work.

So, just wondering what you guys think would be the best way to get data to an install profile?

Thanks!
Ben

Comments

Still looking for an answer

ac's picture

Still looking for an answer for this. Can anyone shed some light for us?

Tried this

benkant's picture

function drush_mymodule_pre_hosting_task() {
  $task =& drush_get_context('HOSTING_TASK');
  drush_log('settings foo to bar');
  $task->options['foo'] = 'bar';
}

then from inside the profile:

drush_log('foo is:'. drush_get_option('foo', null, 'site'));

In the log for the install task is says "settings foo to bar". So the pre_hosting_task is being run and the $task->options['foo'] should be set.

But then further down in the log when the install profile is running it says "foo is ". And it's blank.

Any ideas?

EDIT:

I should also add, this is in the first few lines of the install task log:

Running: /var/aegir/drush/drush.php --uri='some12.example.com.au' provision-save '@some12.example.com.au' --backend

also

Running: /var/aegir/drush/drush.php @some12.example.com.au provision-install --backend

So --foo='bar' is not being passed to drush on the command line, if it should be.

EDIT2:

In the installation profile I am adding:

drush_log('all drush options: '. print_r(drush_get_merged_options(), TRUE));

foo is not mentioned anywhere in the printed data structure.

Created test profile and drush.inc

benkant's picture

Hi Vertice and Mig5,

Thanks a lot for helping on IRC on Friday.

We upgraded to alpha12 today and it fixed the issue where I couldn't run drush from the command line. I ran it with --debug and didn't manage to get any closer.

I've uploaded zip file with:

testoption : to be placed in /var/aegir/.drush - This is implements pre_hosting_task() to set the option.
testoption_install : to be placed in a platform - This is a standard install profile. At the bottom of the .profile there's a function _testoption_install_var_test() that attempts to retrieve the option set in the testoption.drush.inc file.

As you can see when you create a site with this profile, the option is not being carried across.

I've tried both of these in the profile, I'm not sure what the difference is, but neither has the desired result:

    $task->options['fooburger'] = 'bar';
    // and
    drush_set_option('fooburger', 'bar');

In the install profile:

  dlm(drush_get_option('fooburger')); // 1
  dlm(drush_get_option('fooburger', null, 'options')); // 2
  dlm(drush_get_option('fooburger', null, 'stdin')); // 3
  dlm(drush_get_merged_options()); // 4

Lines 1 - 3 do not show any value, and the data structure dumped on line 4 does not contain the fooburger value anywhere.

I've bundled these two files so you can easily test it yourselves, or indeed spot my error!

The file is available at http://dl.dropbox.com/u/2655227/testoption.zip

Many thanks,

Ben

Aegir hosting system

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: