0

I'm installing drush profile via:

drush site-install my_profile --db-url=db.url --account-name=admin --account-mail="admin@example.com" --site-mail="admin@example.com" --site-name="My Site"

But how I can pass some variables into my_profile to initialize them with default values?

In example I'd like to set specific file_public_path and file_private_path as some module fails to install because of the folder misconfiguration.

4

You can add any additional settings you wish to pass to the profile in the following format (the key is in the form [form name].[parameter name]):

drush site-install my_profile install_configure_form.site_default_country=FR my_profile_form.my_settings.key=value
drush site-install my_profile install_configure_form.date_default_timezone="Europe/London" update_notifications.update_status_module=1
drush site-install my_profile variables.file_public_path="sites/default/files" variables.file_private_path="sites/default/private/files"

Then you can handle the variables in your profile code by either implementing hook_install_tasks or hook_install_tasks_alter where you can access $install_state array which have information about the current installation state of your profile and your variables which can be accessed in $install_state['forms'].

In example (when set from drush via variables.X="Y"):

foreach ($install_state['forms']['variables'] as $name => $value) {
  variable_set($name, $value);
}

For file_public_path and file_private_path, it's not enough only to pass the variables, but you should prepare the directories as part of the installation script, e.g.:

file_prepare_directory($install_state['forms']['variables']['file_public_path'], FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
file_prepare_directory($install_state['forms']['variables']['file_private_path'], FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
file_prepare_directory($install_state['forms']['variables']['file_temporary_path'], FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
drupal_static_reset('file_get_stream_wrappers'); // clear static cache for stream wrappers

This was implemented in drush as part of Site Install: allow passing additional form parameters feature request.

Please note that above feature it's only supported on Drupal 7 and above.

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.