Closed (fixed)
Project:
Drush
Version:
All-versions-3.x-dev
Component:
Core Commands
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
18 Dec 2009 at 18:02 UTC
Updated:
27 Mar 2011 at 14:51 UTC
Jump to comment: Most recent file
Comments
Comment #1
moshe weitzman commentedThis sounds pretty good. I'm just worried about the command listing getting unmanageable. Feedback welcome both about how to handle huge command listing and about the code here.
Comment #2
acrollet commentedIt seems like the command listing should probably be condensed by functionality type, e.g.:
At that point, one would want to have a command similar to the following, which would display the individual commands.
This is just off the cuff, so there's probably a better way of doing what I'm describing. It's unfortunate that it will require some changes to the guts of drush, but people are only going to want to do more with drush as time goes on...
Comment #3
drewish commentedI'd love to see an option to set a user's password added. I know it's reasonably easy to do via SQL but it seems like a natural fit for this command set.
Comment #4
acrollet commented@drewish: agreed that it's a nice fit. This patch adds a 'drush user password' command.
Comment #5
greg.1.anderson commentedI love this submission and think it's a great idea. I wonder, though, if this code should use user_save rather than making SQL calls directly. The advantage of this is that all of the built-in Drupal special handling would also be done; hook_user would be called, deleted users would be kicked off the system, etc.
Comment #6
acrollet commented@greg.1.anderson: as far as I know, user_save() is being used in all relevant places, with direct db queries only used to optimize search speed. (all SQL statements start with SELECT) Could you point out any queries that you feel should be replaced with an API call?
thanks!
Comment #7
greg.1.anderson commented@acrollet: You rock. I reviewed your patch to quickly; this is great as it is.
Comment #8
acrollet commented@greg.1.anderson: great, thanks for the input!
Comment #9
moshe weitzman commentedmixing uid and name and email is great. i guess it is not 100% reliable and thats why we disallow for other commands. thats reasonable for now. an alternative is to ask the user to disambuate use the same pattern as vset and clear cache commands (in HEAD).
perhaps too ambitious, but it would be great to be able to populate any fields that are attached to the user entity.
How hard would it be to support the other cancel modules like 'delete all content by this user? I think thats the most common, because of spam.
Is this available for D5/D6/D7?
Don't use drush_die() - use drush_set_error() and bail. But in this case, I'd just as soon not check these conditions. Drupal will happily save an account without an email address. Not sure about password. If it won't (doubtful), lets create one. Developers often just need accounts, even if they are bare.
This is an OK presentation, but consider how much better the dev/load tab is on a user. I think we should do drush_print_r($userinfo);
Lets do
return empty($uids)? FALSE : $uids;
Comment #10
greg.1.anderson commentedMy wishlists:
Add a
user listcommand. This isn't terribly important, as I can always usesqlq "select name from users;". I think it would be a nice as a convenience function, though.Add a function to add permissions to roles. The downside here is that there is no Drupal API to do this; you'd have to use SQL queries directly, so again, this feature would be only a convenience function, as
sqlqworks nearly as well.@moshe: $userinfo is an object, so drush_print_r($userinfo) produces some ugly output. I would recommend this presentation:
Optionally, drush_print_r instead of var_export, and optionally keep $userinfo['block'], but overall, a little bit of clean-up makes the whole thing easier to read.
Comment #11
acrollet commentedYes, uids and names can be ambiguous, unfortunately. Added disambiguation for the drush user info command, but it's better to leave the other commands as they are imo - mostly to make scripting safer.
I like the idea of allowing any fields, tried adding a function to get the possible field name options to the command hook, but ran into difficulties, at least when running 'drush help user create'. I guess drush doesn't bootstrap drupal before running the command hooks? We could hard-code the standard user fields, but that wouldn't help people with custom fields...
This is v. easy to do for drupal 7, but to do for 5-6 would take either adding a lot of code, or introducing a dependency on the user_delete module. thoughts?
Yes: http://api.drupal.org/api/function/user_multiple_role_edit/7
sounds good, changed.
I've re-worked the drush user info code, and added a --detail option - 'basic' gives the original presentation, 'extended' gives output based on the suggestion in #10 with pretty-printed dates, and 'all' does the drush_print_r($userinfo).
Thanks again for the feedback, looking forward to continuing work on this.
Comment #12
acrollet commented@greg.1.anderson: see #11 re: user info
How would you envision the interface working for either command?
For the user list command: In the case of a site with many users, which is common, a straight list of all users is not likely to be useful. Were you thinking of feeding it a search string, or simply having a paginated list of all commands?
For the role permissions editing: there are enough permissions that a cli interface is likely to be clunkier than the web UI, and if you have a specific permission or permissions in mind, I don't see a big advantage for a hard-coded command over running an sql query. Open to having my mind changed about this...
Comment #13
greg.1.anderson commentedFor the user list command:
drush user listwould list the name of all of the users on the system, persqlq "select name from users;"(minus the initial 'name' column). The user could use 'grep' to filter or 'more' to paginate. The purpose of the command would be discoverability;drush help user listwould say 'identical to drush sql query "select name from users;".' Rather than add more features for filtering and such, the user could switch to sqlq if a 'where' clause was needed. I think this command would mostly be used in test sites with a small number of users. The bash "alias" command could also be used to provide this functionality, but again, the advantage of building it in to drush is that it is more discoverable.My logic for the add permissions to roles features is pretty much the same. I like to script basic site setup operations, and setting up basic permissions is a useful part of module setup. This might be better done with features, which I really haven't started using yet. An add permissions command would then naturally beg for a list / add / remove role command. The main reason for adding these would be completeness.
My use case for editing permissions is as follows. I have a drupal-backed static html site. On the edit site, the "anonymous user" role has no permissions. When the site is published, I copy all of the permissions from a template role over the anonymous user role to grant the anonymous user the right to read content on the live site. The script is like this:
Sqlq does work just fine, so this is an optional feature. It would be nice, though. It would be even nicer to just add a role to the anonymous user with the existing "add role" command; unfortunately, the anonymous user is a role, not a user in Drupal, so that won't work.
I have also briefly contemplated user migration. I sometimes migrate all users wholesale like this:
drush --tables-list="users,role,users_roles,permission,fckeditor_role" sql sync live devIf the user info command would output a cvs list, you might be able to send it to node_import to do individual user migration. I don't have a use case for this yet; it's just a thought.
Comment #14
moshe weitzman commentedI think we can skip the user list and permission editing for now.
I really want disambiguation on the write commands in addition to just info command. Thats how we do it for the vset command, for example. Its just so handy. We can add something like the always-set option which was just added to vset command.
By default, drush commands run after a full drupal bootstrap. But we can skip this request for now - I think profile fields will open a small can of worms.
I really want the cancel methods for d7. if we can support them in d6 using user_delete module, thats icing on the cake. we could consider shipping that code with user_delete module.
Comment #15
acrollet commentedNew patch attached - this one adds a --users= option for the write commands with disambiguation, and supports the user_cancel_delete method for d7.
btw, ran into a frustrating problem with drush_choice() - because it uses array_unshift, which re-indexes numerical keys, (even when explicitly cast to a string) I'm having to prepend name_ to any numeric user names when using drush_choice to disambiguate. Not a show-stopper, but kind of ugly...
Comment #16
moshe weitzman commenteddrush_choice() is quite new code. it's quite possible that less than a dozen people have seen it. i welcome improvements there.
Comment #17
greg.1.anderson commented'user info' will need to change to 'user-info' if #550522: Change white spaces in commands by another symbol lands first. I don't want to have to redo that patch if it can be avoided, because it was a bit of a pain to roll; this issue won't cause any problems there, though, (since it's all in its own new file) so I'm fine with either commit order, & will even fix this one up if it commits first.
The code looks pretty good on quick inspection, but unfortunately, my home system died this morning (motherboard went, maybe), and at the moment I'm on a Windows laptop that doesn't even have cygwin installed. :p I'll give this a spin at work if I have a chance today; this patch will be useful to us.
Comment #18
acrollet commented#16: created a new issue to discuss drush_choice: #674940: drush_choice() uses array_unshift(), which re-indexes numerical keys
#17: whatever works is good by me. I assume all the commands would have to be changed? e.g. we'd end up with user-add-role and so on?
Comment #19
greg.1.anderson commentedYes, that's correct. I tried to roll a patch to change $command['command'] on the fly, but doing that in drush help dispatching was too complicated -- it turned out to not be worth the effort. So, all commands will need to be changed (spaces to dashes) by hand.
Comment #20
greg.1.anderson commentedHere is a patch that makes two modification:
This patch therefore does not work correctly unless you first apply the patch to drush_choice mentioned above.
Comment #21
acrollet commented@#20: tested this patch, the drush_choice call works nicely and looks great. Unfortunately, quoting the named parameters is making PDO choke when used with mysql:
I did a little searching, but was unable to come up with a cross-compatible syntax. (and don't have postgres installed locally to try things) Is there perhaps another syntax that postgres will accept? Alternatively, perhaps a bug needs to be filed on db_query()... thoughts?
Comment #22
greg.1.anderson commentedNah, there are tons of modules that work with both. Sorry I messed up the syntax for mysql -- give me some time and I'll pull up something that works both places. Actually, I think this might be a D7-specific problem; perhaps I shouldn't have added the quotes on the D7 code. I'll have to install D7 to try it; might not get to that for a couple of days.
Comment #23
greg.1.anderson commentedComment #24
greg.1.anderson commentedHere is a patch for experimentation. I've updated the call to drush_choice to match the latest patch over there, and rolled out all of the D7 changes I made. I haven't tested on D7 yet, nor have I tested on D6 + mysql, but this works great on D6 + postgres (and I presume D7 + mysql), provided that you also take patch #6 from #674940: drush_choice() uses array_unshift(), which re-indexes numerical keys. Give it a try if you have a chance. I will test it myself on D7 & mysql when I can, but I still haven't recovered my home system with the dead motherboard yet. (At least I've got the internet gateway back up, using my son's computer, and I'm on a proper Linux laptop with Drupal installed now... ;) ).
Comment #25
moshe weitzman commentedmost recent patches are some sort of incremental patches. lets post full patches if possible (i.e. the whole user.drush.inc)
Comment #26
greg.1.anderson commentedEdit: This patch is broken, don't use it...
Comment #27
moshe weitzman commentedLets wrap this option in a conditional which checks: drush_drupal_major_version() >= 7
drush_get_option('delete-content')) == 'true'. i think we can just check for drush_get_option('delete-content')). It will be TRUE if present. If we think thats too dangerous, we could add a drush_confirm().Comment #28
greg.1.anderson commentedI fixed my mangling from #26, and did item 2. from #27 in the attached patch.
@acrollet: Can I pass this back to you for the other items?
Comment #29
moshe weitzman commentedAny chance we can revive this.
In there interest of fewer commands, I think we should cobine add-role and remove-role into a user-role command. same for block and unblock
Comment #30
greg.1.anderson commentedHaven't heard from acrollet for a while, so I'll pick this up. No complaints from me if someone else does it, though.
Comment #31
acrollet commented@greg.1.anderson: I would appreciate it very much if you could pick it up - work has gotten very busy for me of late, which is why I haven't been heard from. That said, if things slow down for me and no progress has been made, I'll take another look at it.
Comment #32
anarcat commentedComment #33
greg.1.anderson commentedBump... but only to mention that I'm not planning on fixing this for 3.0. It's nearly done, though, so please feel free to add a drush-3.0 tag if you feel like holding up the drush-3.0-stable release for this.
Comment #34
Darkflare commentedHi
Is the drush user-info implemented correctly? From the example I cant actually get a response to tell me weather the user even exists. I using the latest patch and running : "drush user-info --basic targetusername" and getting a response telling me its missing an arugment and prints the details for user '' (ie no information passed in) whats the correct format for passing in a user/users?
Thanks
DF
Comment #35
acrollet commentedFinally got a chance to try and polish this up. I believe this patch addresses all the concerns in #27, with the exception of not providing disambiguation for user-create (where it wouldn't make sense, user-cancel, and user-password. In the case of the latter two, I think it's perhaps safer to stick with usernames only - it's easy enough to add the code to those commands as well, if you disagree.
Comment #36
moshe weitzman commentedThanks for jumping back on this. A few minor notes below.
should we just re-use the verbose option here? if there are more than 1 level of detail, lets itemize each one. note that the 'sa' command has --full and --short options. might be worth considering here instead of inventing own names.
omit this line (and similar below) when not needed. we expect this command to work on d8 until some api change breaks it. thats ok.
Isn't this option a duplicate of the argument?
Comment #37
acrollet commented--full and --short sound good to me, re-rolled with that change and the two other bugfixes.
Comment #38
moshe weitzman commentedLooks like we should print basic user info using same approach as status command. this makes for better wrapping of long values. search for
drush_print_table(drush_key_value_to_array_table($status_table));in core.drush.incComment #39
acrollet commentedre-rolled. definitely prettier now.
Comment #40
moshe weitzman commentedthanks. just reviewed yet again and found:
drush_die("You must specify a password!");should be return drush_set_error() for better compatibility with backend calls.looks to me like --pipe only works with basic user info which is surprising.
Comment #41
acrollet commentedre-rolled with drush_set_error and --pipe for full user info.
Comment #42
moshe weitzman commentedneed command aliases. i propose
usin
usbl
usubl
usar
usrr
uscr
usca
usp
Comment #43
greg.1.anderson commentedRegarding aliases, I'd rather see one less character from "user", and one more character from the verb.
uins,ublk,unblk, etc.Comment #44
acrollet commentedI tend to agree with greg, aliases with just u and more from the verb feel more mnemonic to me. I'm proposing the following, and attaching a patch:
uinf
ublk
uublk
urol
urrol
ucrt
ucan
upwd
these also have more of the 'unix command line utility' feel to them imo.
Comment #45
acrollet commentedwhoops, didn't mean to set RTBC above.
Comment #46
moshe weitzman commentedFinally trying these out ...
I get 4 warnings similar to below when doing a user-create on d7. similar for uinf so i think the problem is in a common subroutine.
I passed an invalid string to user-block and got no error back. Same for uinf. Lets do descriptive confirm and error messages for these commands.
Comment #47
acrollet commentedhadn't tested on d7 in a while, you caught me ;) Fixed the above mentioned errors, and a few more I found while testing all commands on d5-7 with valid and invalid input.
Comment #48
acrollet commentedforgot to set status.
Comment #49
moshe weitzman commentedThanks for your persistence ...
you can just do
return drush_set_error("Could not find a uid for the search term '" . $search . "'!");drush_log(dt("Added the %role role to uid %uid", array('%role' => $role, '%uid' => $uid)), 'notice');. In general, I'd like to see more success messages in these commands. i know the unix way is to be quiet on success but thats pretty disconcerting IMO. Not a big deal.Comment #50
acrollet commented1. the code is there, and should work pending resolution of #836910: drush_drupal_version() is broken on d7
3. done.
4. I believe this is already the case:
5. done
As for the rest... I appreciate the nod to my persistence, but this seems to have turned into a bit of a sisyphean task. This module reached the point of usefulness for our organization long ago, and it's hard to justify spending a lot more of my employer's time on it. I have no particular feeling of ownership, so I'm happy if someone else wants to take over the back and forth until it's committed. If you can tell me "these are the things it needs to be committed, full stop", I can make a single expenditure of time, but I can no longer afford the steady drain...
thanks,
Adrian
Comment #51
moshe weitzman commentedI implemented --simulate and committed this. I also fixed #836910: drush_drupal_version() is broken on d7 in a later commit.
thanks to acrollet for persisting on this. very nice first patch for drush4.
i wil leave it to anarcat to decide if this should get into drush3.
Comment #52
moshe weitzman commentedComment #53
anarcat commentedWe have discussed the policy of the drush 3.x branch at a BOF at Drupalcon CPH and it was agreed to only include critical and security fixes on the branch, to make it easier to sync in the official distributions (e.g. Debian). New features and small bug reports like this one, unless really critical or security, will therefore be refused for the 3.x branch.
Comment #54
anarcat commentedActually, i'm reconsidering this one, since Debian is still in a "sludge" rather than a full freeze... Can we get a complete patch here? Moshe, you mentionned adding --simulate in there... Should I just slap in the user.drush.inc file?
Comment #55
omega8cc commentedThat would be great to have it ported to Drush 3.x, it is extremely useful stuff.
[EDIT] It seems this change Component: Code » PM (dl, en, up ...) was forced without my intention
Comment #56
omega8cc commentedJust tried the patch for Drush 3.3 from http://drupal.org/project/drush_user and it works great.
Comment #57
jonhattanComment #58
moshe weitzman commented3.x gets security fixes only. this is in 4.