Viewers: in countries Watching now:
Manage your Drupal sites even more efficiently with Drush, the shell interface for managing and scripting Drupal site development. In this quick course, author Jon Peck describes what Drush is, how to install it, and how to use it effectively for everyday—and exceptional—tasks.
The course describes how to manage users, download and install modules and themes, archive and restore your entire site, and employ site variables for fast, full control over your Drupal sites. Plus, discover how to script an entire Drupal site installation with and without site profiles.
Managing users is an everyday task for many Drupal site administrators. So Drush provides an interface for that as well. Let's start with getting information about a user. drush help user information. The User information command, aliased as uinf, displays information about a user. The argument passed as a comma separated list of usernames UIDs and email addresses. Right now there's only one user on the system, the admin user that was created during site installation.
So I will get information about that user, drush uinf admin. The user id, name, mail, roles and status are displayed. Additional information can be shown using the option --full. The full view is a bit more extreme and is useful for low-level debugging. For example, the password is shown in a sense. It's the hashed password not the actual password which in this case is admin.
A common problem is that users are constantly forgetting their passwords. Drupal's Password API hashes passwords using a secured stretched hash, meaning that it's both salted and hashed multiple times to increase the complexity of the stored password to reduce the risk of brute force decryption. Due to these privacy and security restrictions this means the passwords cannot be read even by administrators, despite whatever a client may request or demand. Instead, Drupal's administrative interface provides a mechanism that allows users to request one time Logins and allows administrators to arbitrarily set a user's password.
I will demonstrate both of these techniques using Drush. First, setting passwords manually, this is useful when working on a local duplicated copy of a client site and the particular password is not known. drush user password, or just aliased as upwd sets, the password for a user. The only argument is the username and there is a required option, yes that's oxymoronic but it is required names password containing the new password in plain text. So I am going to set password for admin with the required option, password =hello.
I can also put quotes around the password if the target password contains quotes or spaces. "Hello" isn't a good password so set it back to admin which is still insecure but easy to remember in a development environment. drush upwd admin password=admin. The second technique, generates a one- time login URL which can be given to a user. This is preferable to setting a password for user as administrators should never know a users password.
The user login command aliased uli will generate these log in URLs for a given user, drush uli admin. Depending on the way the site was set up Drush may not know the actual site URL and out-of-the-box the URL is not set which is why it's showing as http default. Always look at the output before blindly passing it on to the user. These generated one time log-ins are not emailed by Drush, the administrator needs to manually use these URLs in whatever way they see fit.
Drush user interaction goes beyond passwords, users can be created, blocked and unblocked and even canceled. I will start by creating a test user using the User Create command aliased as ucrt, drush help ucrt. User create takes an argument containing the username followed by the two options with a mail and password. drush ucrt test mail="test@ example.com" and password=test.
Now if I get user information on the test user, drush uinf test, I will see the same information as I was shown when I created the user. While user create is used on one user at a time the block and unblock commands will work on multiple users at a time. The user list can be separated by commas and the users can be specified by UID, email or username. Be careful with this command as there is no prompt and Drush will respect whatever email preferences that have been set on the site such as not notifying on blocks and sending an activation email when unblocking.
To block a user I would use the user block command aliased as ublk followed by an argument containing the users. drush ublk, let's get the help for that, I will block both the admin user by UID and the test user, by user name. Notice that I am not using the additional options specifying that I'm using a UID or username, Drush will do the work for me. Verify that the admin user is blocked with the command line. drush uinf 1.
Then, return to the browser and attempt to navigate to a page. Being blocked, the admin user is kicked out. The user status is shown as blocked, given that it's easy to block someone without a prompt the block can be also similarly removed, user unblock operates in a very similar manner and has a similar alias, uublk. I will leave the test user blocked, drush uublk 1.
I'm shown an error regarding e-mail as my local development environment was not set up to send email at this time and by default Drupal will send an email upon account activation. Finally, if I want to gracefully get rid of an account I can cancel a user using the user cancel command. Ironically aliased as ucan, drush help ucan. By default all contents owned by the user reverts to UID 1. I will cancel the test account now as I'm done with it.
User cancel takes one argument a single user to cancel, an optional argument will just arbitrarily delete all content created by the user as well, drush ucan test delete content. Following a prompt the user in all their content will be deleted. Throughout this chapter I've covered a number of core functionalities for everyday operation, including: site installation and introspection for building a site from the ground up and getting a high-level perspective of site configuration, listing and managing modules which is useful for downloading, enabling and disabling modules, theme and variable management using variable set and get in user management including creation, blocking and unblocking and cancellation.
In the next chapter, I will discuss more advanced and low-level site management techniques
There are currently no FAQs about Simplified Drupal Sites with Drush.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.