Skip to content

Commit

Permalink
Merge pull request #10 from wunderio/feature/9-Create-wrapper-for-pmu…
Browse files Browse the repository at this point in the history
…-to-be-able-to-uninstall-modules-that-dont-exist-in-code

#9 Create pmu tooling (drush pmu) wrapper initial script.
  • Loading branch information
hkirsman authored Mar 4, 2024
2 parents 08e501c + 932b11e commit 4cd8816
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dist/.ddev/commands/web/wunderio-core-pmu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

## Description: Runs drush pmu commands but also creates dummy module folder if it does not exist.
## Usage: pmu
## Example: "ddev pmu module1 module2 ..."

/var/www/html/.ddev/wunderio/core/_run-scripts.sh tooling-pmu.sh "$@"
57 changes: 57 additions & 0 deletions dist/.ddev/wunderio/core/tooling-pmu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

#
# Helper script to run pmu, but also create temporary module directory if it doesn't exist.
#

set -u
if [[ -n "${WUNDERIO_DEBUG:-}" ]]; then
set -x
fi
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/var/www/html/vendor/bin

if [[ "$#" -lt 1 ]]; then
echo "Usage: ddev pmu <module1> <module2> ..."
exit 0
fi

modules="$1"

cd /var/www/html

disable_module() {
local module_name="$1"

local module_path="web/modules/custom/$module_name"

# Check if the module directory exists.
local module_exists=0
if [ -d "web/modules/contrib/$module_name" ] || [ -d "$module_path" ] || [ -d "web/core/modules/$module_name" ]; then
module_exists=1
fi

# Create dummy module if the module directory doesn't exist.
if [ $module_exists -eq 0 ]; then
mkdir -p "$module_path"
echo "name: 'Dummy module created by ddev pmu'" > "$module_path/$module_name.info.yml"
echo "type: module" >> "$module_path/$module_name.info.yml"
echo "core_version_requirement: ^9 || ^10 || ^11" >> "$module_path/$module_name.info.yml"

# Clear caches to make the module available.
drush cr
fi

# Run "drush pmu" command.
echo "Disabling module $module_name..."
drush pmu -y "$module_name"

# Remove dummy module if it was created.
if [ $module_exists -eq 0 ]; then
rm -rf "$module_path"
fi
}

for module in $*
do
disable_module "$module"
done

0 comments on commit 4cd8816

Please sign in to comment.