When i provision install a new site, I'd like to be able to specify the username for user 1.
I'm a provision noob, so I'm not sure what the best approach to this would be - a drush flag? a system variable? an element on a form field?

If someone wants to offer some guidance, I'd be happy to work on a patch.

CommentFileSizeAuthor
#2 provision-697954.patch2.56 KBaaronbauman

Comments

Anonymous’s picture

Hi there,

Great idea! And thanks for volunteering to work on a patch :)

Here are some starting points:

1) Modify hosting_site_form() to add an 'admin_user' (or somesuch) field. Perhaps default it to 'admin'

2) Modify the hosting_site table schema to add an 'admin_user' column to store the value (and of course add a hook_update() for upgrades)

3) Modify the site module's hook_insert and hook_update to put the value from the form into that column in the table.

4) Modify the site module's hook_load to load the admin_user value

5) Pass the admin_user value as an 'option' to drush in hosting_site.drush.inc (hint: $task->options['admin_user'] = $task->ref->admin_user )

6) Modify each implementation of install_$n.inc where $n = drupal core version in the Provision extension (provision/platform/drupal/install_6.inc for example) to use drush_get_option('admin_user') for the username if the value is present, or else default it to admin (could simply be handled as a default in 1), but if you do so, make sure that that field is #required. Otherwise, set the default in an 'else' conditional in the install_$n.inc file if no other value was sent by the user.

Let us know how you go!

aaronbauman’s picture

Status: Active » Needs review
StatusFileSize
new2.56 KB

IMPORTANT:
Since the bulk of this patch is actually to hosting module, I've posted the related patch in hosting's issue queue.
This patch is interdependent with
#699250: Support for admin_user option in order to set user 1 name other than "admin"
You must install both!

mig5:
Thanks so much for your explicit and thorough guidance. I've got a much better understanding of the system now after rolling this patch.

In this patch:
provision/platform/drupal/install_N.inc files now accept a drush option "admin_user".
You can specify this flag on install in order to set a username for user 1 other than "admin", e.g.
drush provision install example.com --admin_user="administrator"

Anonymous’s picture

Status: Needs review » Needs work

Sorry for taking so long to review your work!

All is great here except for one thing: in Provision you check if the username is valid with user_validate_name() - this is good in case someone installs a site from the commandline (i.e I see you do the same thing in a validate hook in the frontend).

The only problem is you try to revert back to a default user, but the HOSTING_DEFAULT_ADMIN_USER_SITE global is not recognised in the backend.

As an example:

li94-211:~$ php /var/aegir/drush/drush.php --root='/var/aegir/hostmaster-HEAD' provision-install 'us2.mig5-forge.net' --backend --admin-user='dsgsd#@@$1'
mysql> select name from users;
+---------------------------------+
| name                            |
+---------------------------------+
|                                 | 
| HOSTING_DEFAULT_ADMIN_USER_SITE | 
+---------------------------------+
2 rows in set (0.00 sec)

I think it would be easier to just hardcode 'admin' here perhaps?

aaronbauman’s picture

So the problem is that hosting/site/hosting_site.module doesn't get include'ed when provision-install runs.
Would moving HOSTING_DEFAULT_ADMIN_USER_SITE constant out of Hosting and into Provision fix this issue?
Is there a better place to define this constant?

thanks for the review

Anonymous’s picture

Status: Needs work » Fixed

Sorry I never got back to you.

I decided it was easier not to set a default with variable_set - let's keep things simpler and just put a #default_value of 'admin' in the form. In the backend, we can do drush_get_option('admin_user', 'admin') which defines the default if none was given from a CLI-only install, and in the validation you do there, default to admin if it's no good too.

Less elegant but easier and I can live with it rather than try and fetch globals from Hosting.

I committed such a simplified version along with the rest of your work. Thanks very much for it!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.