From 169f5f98c810f59f49f6539edc7cc2ac4e7168cb Mon Sep 17 00:00:00 2001 From: Fran Rouco Date: Fri, 18 Oct 2024 22:00:22 +0200 Subject: [PATCH 1/5] Add a command to launches a drush command on all of the sites --- commands/host/all-sites-drush | 26 ++++++++++++++++++++++++++ commands/host/includes/aljibe_includes | 7 ++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 commands/host/all-sites-drush diff --git a/commands/host/all-sites-drush b/commands/host/all-sites-drush new file mode 100755 index 0000000..c299d4c --- /dev/null +++ b/commands/host/all-sites-drush @@ -0,0 +1,26 @@ +#!/bin/bash +#ddev-generated +## Description: Launches a drush command on all of the sites +## Usage: all-sites-drush [drush command] + +source "$(dirname "$0")/includes/aljibe_includes" + +ENV='local' +COMMAND='' +SITES=() + +COMMAND=$@; +if [ -z "$COMMAND" ]; then + echo "Please provide a drush command" + exit +fi + +## Get all sites from the drush/sites folder. +get_sites + +## Run the command in all sites. +for SITE in "${SITES[@]}"; do + SITE_ALIAS=$SITE.$ENV + echo "Running drush $COMMAND in $SITE" + ddev drush @${SITE_ALIAS} $COMMAND +done diff --git a/commands/host/includes/aljibe_includes b/commands/host/includes/aljibe_includes index 2ff472f..7066d44 100644 --- a/commands/host/includes/aljibe_includes +++ b/commands/host/includes/aljibe_includes @@ -43,4 +43,9 @@ run_hooks() { echo -e "\033[32mRunning $1 commands: \033[0m\n" readarray -t CMDS < <(ddev aljibe-config hooks.$1) run_commands "${CMDS[@]}" -} \ No newline at end of file +} + +## Get all sites list from the drush/sites folder. +get_sites() { + mapfile -t SITES < <(find drush/sites -name '*.site.yml' -exec basename {} \; | cut -d'.' -f1) +} From 3de93866e05b2aa3cffc5e1ca833c829993fe85e Mon Sep 17 00:00:00 2001 From: Fran Rouco Date: Fri, 18 Oct 2024 22:01:59 +0200 Subject: [PATCH 2/5] Detect correctly all the available sites --- commands/host/setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/host/setup b/commands/host/setup index 7311c69..1d6b63a 100755 --- a/commands/host/setup +++ b/commands/host/setup @@ -49,7 +49,7 @@ handle_options() { while [ $# -gt 0 ]; do case $1 in -a | --all) - mapfile -t SITES < <(drush site:alias --fields=name --format=list --filter=.local | sed 's/@//' | sed 's/.local//') + get_sites shift ;; -h | --help) From 63e34c84213cba770f8e3cb8992f788bd7099bec Mon Sep 17 00:00:00 2001 From: Juanjo Date: Wed, 11 Dec 2024 12:21:08 +0100 Subject: [PATCH 3/5] Change variable name --- commands/host/setup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/host/setup b/commands/host/setup index 1d6b63a..429a0a3 100755 --- a/commands/host/setup +++ b/commands/host/setup @@ -49,7 +49,7 @@ handle_options() { while [ $# -gt 0 ]; do case $1 in -a | --all) - get_sites + set_sites_variable shift ;; -h | --help) @@ -136,4 +136,4 @@ if [ "$NO_INSTALL" -eq 0 ]; then fi # Launch post setup hooks -run_hooks "post_setup" \ No newline at end of file +run_hooks "post_setup" From 15e91f8a94ade5a63d3849c5a3474e3883e0e345 Mon Sep 17 00:00:00 2001 From: Juanjo Date: Wed, 11 Dec 2024 12:21:53 +0100 Subject: [PATCH 4/5] Change get_sites function name --- commands/host/includes/aljibe_includes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/host/includes/aljibe_includes b/commands/host/includes/aljibe_includes index 7066d44..6f2099d 100644 --- a/commands/host/includes/aljibe_includes +++ b/commands/host/includes/aljibe_includes @@ -46,6 +46,6 @@ run_hooks() { } ## Get all sites list from the drush/sites folder. -get_sites() { +set_sites_variable() { mapfile -t SITES < <(find drush/sites -name '*.site.yml' -exec basename {} \; | cut -d'.' -f1) } From c016049200b77617a28dee70b946675eaed8defb Mon Sep 17 00:00:00 2001 From: Juanjo Date: Wed, 11 Dec 2024 12:22:19 +0100 Subject: [PATCH 5/5] drush command uses the set_sites_variable --- commands/host/all-sites-drush | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/host/all-sites-drush b/commands/host/all-sites-drush index c299d4c..4650b52 100755 --- a/commands/host/all-sites-drush +++ b/commands/host/all-sites-drush @@ -16,7 +16,7 @@ if [ -z "$COMMAND" ]; then fi ## Get all sites from the drush/sites folder. -get_sites +set_sites_variable ## Run the command in all sites. for SITE in "${SITES[@]}"; do