Last active
September 15, 2022 07:31
-
-
Save yusufhm/23f1a25a886533d764e2 to your computer and use it in GitHub Desktop.
Drush commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# THESE COMMANDS HAVE TO BE RUN FROM INSIDE AN EXISTING DOCROOT | |
# Get docroot path | |
drush st root --no-field-labels --format=list | |
# Generate Drupal Hash - Drupal 8 | |
drush php:eval '$hash = Drupal\Component\Utility\Crypt::randomBytesBase64(55); print $hash . "\n";' | |
# Generate Drupal Hash - Drupal 7 | |
drush php:eval '$hash = drupal_random_key(); print $hash . "\n";' | |
# Set site to maintenance mode - Drupal 8 | |
drush @prod sset system.maintenance_mode 1 | |
# Publish all nodes of a type. | |
drush php:eval '$storage_handler = \Drupal::entityTypeManager()->getStorage("node"); $entities = $storage_handler->loadByProperties(["type" => "{node_type}"]); foreach ($entities as $node) { $node->setPublished(TRUE); | |
$node->set("moderation_state", "published"); $node->save(); }' | |
# Delete all nodes of a type. | |
drush php:eval '$storage_handler = \Drupal::entityTypeManager()->getStorage("node"); $entities = $storage_handler->loadByProperties(["type" => "{node_type}"]); $storage_handler->delete($entities);' | |
# Delete all terms of a vocabulary. | |
drush php:eval '$storage_handler = \Drupal::entityTypeManager()->getStorage("taxonomy_term"); $entities = $storage_handler->loadByProperties(["vid" => "{vocab_id}"]); $storage_handler->delete($entities);' | |
# Delete all profiles. | |
drush php:eval '$storage_handler = \Drupal::entityTypeManager()->getStorage("profile"); $entities = $storage_handler->loadMultiple(); $storage_handler->delete($entities);' | |
# Delete all blocks of a type. | |
drush php:eval '$storage_handler = \Drupal::entityTypeManager()->getStorage("block_content"); $entities = $storage_handler->loadByProperties(["type" => "carousel"]); $storage_handler->delete($entities);' | |
# Run a function from a module's install file. | |
drush php:eval '\Drupal::moduleHandler()->loadInclude("module_name", "install");_module_name_function();' | |
# Delete uninstalled module. | |
drush sql-query "DELETE FROM key_value WHERE collection='system.schema' AND name='module_name';" | |
# Search API re-indexing. | |
drush @prod search-api:status | |
drush @prod search-api:reset-tracker [indexId] | |
drush @prod search-api:index [indexId] | |
# Export config from remote drush environment. | |
# See https://unix.stackexchange.com/a/267438/39534 | |
drush -Dssh.tty=0 @prod config:status --field=name | xargs -L1 -I {} sh -c 'drush -Dssh.tty=0 @prod config:get "$1" > config/default/"$1".yml' sh {} | |
# Unblock user with id. | |
drush user:unblock $(drush user:information --uid=1 --field=name) | |
# Remove password expiry for user. | |
drush sql-query "DELETE FROM user__field_password_expiration WHERE entity_id=1;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment