Create a new users.php in the /cli folder.
The script accepts the following input params
--name Name of the User (mandatory)
--email Email Address of the user (mandatory)
--username Username. Defaults to email if not supplied
--password The password to set for the user. Creates a random password if not supplied
--groups Comma separated list of group ids. If empty uses the default group from user configuration
--block Defaults to 0
--activation Defaults to 0
Output
If successful, the script prints a JSON output of the user object
If creation fails, the script prints an error in JSON form and also sends the FAILURE exit code
Example Uses
php users.php --name="Ashwin Date" --email="coolbung@mailinator.com"
Will create a new user with a random password and default groups
php users.php --name="Ashwin Date" --email="coolbung@maildrop.cc" --username="coolbung" --password="q1w2e3R$" --groups="2,8"
Will create a new user with the provided details
Labels |
Added:
?
|
Labels |
Added:
?
|
Category | ⇒ | CLI Feature Request |
Sadly far too much of Joomla's code base assumes (and doesn't validate) that you're running with a web application in an HTML context. Even the webservices project found it easier/better to build that as a standalone application off the Framework with a bridging CMS component versus trying to tie it in properly to the CMS architecture.
Sounds like an extension to me and not something for core
And what about adding users to the Super Users group, like in your example?
If we have a standard ID for the Super Users group, this script could be used to add users to this group and this could cause potential security issues.
Closing for the reasons stated above. It can always be re-opened if someone has some code to contribute
(to be honest this sounds like a requirement you have from a a client that you want someone to code for you)
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-07-13 00:19:25 |
Closed_By | ⇒ | brianteeman |
CLI scripts are designed to only execute from the command line (JApplicationCli
actually won't let a class extending it run unless you're basically on the CLI SAPI or fake a lot of stuff which you'd still need server side access in some form to accomplish).
But alas, I'm not going to hold my breath waiting for the day Joomla really has an infrastructure to support server side task management (I'm not talking about shipping an application class and claiming to support CLI either).
@mbabker Its not only a Joomla problem, its a user problem too, I just dont think Joomla "web masters" are command line savvy folk... not the mass market for sure... not even some of the self-proclaimed "Joomla developers" who release extensions (ok with exceptions for @johanjanssens, @nikosdion and the like ) ... I just don't see Joomla becoming that kind of composer based, command line driven CMS. I know WP and Drupal have their command line tools, but again, totally different class of users I think... maybe I'm wrong...
When WordPress has a better supported CLI package and REST API offering than Joomla, it makes you wonder...
@PhilETaylor That's a very fair statement. Simple comparison:
With that said, the wp-cli is a very clunky piece of code, full of work arounds. From our experience it's a lot easier to run Joomla from the command line then it is to run WP from the command line.
@coolbung Your script is actually a great candidate to build as a Joomlatools Console plugin. (It would be the first ever) Our console is using Symfony Console and it's very easy to build your own plugins, we have build our own composer installer for them. More info:
If you need help let me know!
@mbabker @PhilETaylor do you have any thoughts on how a full blown CLI interface for Joomla should be architect-ed ? Knowing that work is going on for the Service Layer is it worth the while, or can it be created as a forward compatible layer so it works when the service layer is in.
Would be happy to write out a PR and start with the user management part of it.
@johanjanssens will surely give that a shot.
@coolbung If you need any help creating the CLI plugin for the console just let me know, happy to assist.
About your question, personally I don't think Joomla needs a full blown CLI layer. Lessons you can learn from the console and as @PhilETaylor says there is not much Joomla integrators and developers that are CLI savy. If it's not a problem a majority of users have, no need to fix it in the core.
If you do want to create one the best solution would be to create a REST interface and expose that REST interface over CLI. Wordpress community is trying to do something like this: http://wp-cli.org/restful/ REST is a more urgent problem to solve.
In my opinion. For Joomla a simple REST API is the best way to enforce a service layer, a HTTP API and a CLI over REST API. If the solution is kept simple and pluggable, developers could easily create plugins for it for their existing extensions, ideally this is developed as a extension for Joomla 3 first, from where it can be fine-tuned.
Up until now the cli scripts shipping with Joomla have been more for cleaning up and system health - this crosses the line into providing scripts to be used by "web masters" [A loose term] - and as the "average Joomla webmaster" [putting it politely] can "only just install Joomla" and has no access to the command line on their server I dont see that providing command line options that ship with Joomla, like the proposed is of any advantage to Joomla, unless a full api, or suite of commands is provided...
Its not like Joomla is a composer installed web application like symfony which REQUIRES the web "master" to actually have access to the command line in order to install/maintain and app:add-user :-)