Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update patch_views.sh #408

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 100 additions & 54 deletions scripts/patch_views.sh
Original file line number Diff line number Diff line change
@@ -1,55 +1,101 @@
#!/usr/bin/env bash
set -e

# To be precise on the error message that matches the error this should address.
ERROR_MESSAGE=$(drush watchdog:show --severity=Error --filter="InvalidArgumentException: A valid cache entry key is required" | awk '{print $6}')

# If error message equals to "No such file or directory", then exit.
if [[ $ERROR_MESSAGE == *'InvalidArgumentException'* ]]; then

# Install Drupal Console.
drupal_console_installed() {
composer show 'drupal/console' | grep -q '/var/www/drupal/vendor/drupal/console'
}
if drupal_console_installed; then
echo 'Package installed'
else
composer require drupal/console:~1.0 --prefer-dist --optimize-autoloader -W
fi

# Reinstall views
enabled_view=`/var/www/drupal/vendor/drupal/console/bin/drupal debug:views --status='Enabled' | cut -d ' ' -f 2 | tail -n +2`
for dis_view in $enabled_view; do
echo "Disabling view $dis_view"
/var/www/drupal/vendor/drupal/console/bin/drupal views:disable $dis_view
done

for en_view in $enabled_view; do
echo "Reenabling view $en_view"
/var/www/drupal/vendor/drupal/console/bin/drupal views:enable $en_view
done

# Install devel.
devel_installed() {
composer show 'drupal/devel' | grep -q '/var/www/drupal/web/modules/contrib/devel'
}
if devel_installed; then
echo 'Package installed'
else
composer require 'drupal/devel:^4.1' -W
fi
drush pm:enable -y devel

echo -e "\n\nThis will likely throw an error, but that's okay. It's just a patch.\n\n"
{ # try
drush dev:reinstall -y islandora
} || { # catch
echo -e "\nIgnore these errors. This will fail if any content is already created.\n\n"
}

# Clear caches
/var/www/drupal/vendor/drupal/console/bin/drupal cache:rebuild
/var/www/drupal/vendor/drupal/console/bin/drupal cr all
/var/www/drupal/vendor/drupal/console/bin/drupal node:access:rebuild
drush cron
#!/bin/bash
set -euo pipefail

# Log file for tracking script operations
LOG_FILE="/tmp/drupal_troubleshoot_$(date +%Y%m%d_%H%M%S).log"

# Function to log messages
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
}

# Verify required commands exist
check_dependencies() {
local deps=("drush" "composer" "awk" "grep")
for cmd in "${deps[@]}"; do
if ! command -v "$cmd" &> /dev/null; then
log "Error: $cmd is not installed"
exit 1
fi
done
}

# Check Drush installation
ensure_drush() {
if ! composer show 'drush/drush' &>/dev/null; then
log "Installing Drush..."
composer require drush/drush
else
log "Drush is already installed"
fi
}

# Main troubleshooting function
troubleshoot_drupal() {
local ERROR_MESSAGE
ERROR_MESSAGE=$(drush watchdog:show --severity=Error --filter="InvalidArgumentException: A valid cache entry key is required" | awk '{print $6}')
log "Detected Error Message: '$ERROR_MESSAGE'"

# Retrieve enabled views
local VIEWS_FILE="/tmp/enabled_views.txt"
drush views:list --status=enabled --format=csv | grep -v "Machine name" | awk -F',' '{print $1}' > "$VIEWS_FILE"

log "Views file contents:"
log "$VIEWS_FILE"
echo "---------------------"

# Always process views, regardless of error message
while IFS= read -r dis_view; do
log "Processing view: $dis_view"
drush views:disable "$dis_view" || log "Error disabling view: $dis_view"
sleep 1
drush views:enable "$dis_view" || log "Error enabling view: $dis_view"
done < "$VIEWS_FILE"

# Ensure Devel module
DEVEL_INITIALLY_ENABLED=$(drush pm:list | grep devel | grep -F 'Devel (devel)' | grep -q "Enabled" && echo "Enabled" || echo "Disabled")
log "Devel module initial state: $DEVEL_INITIALLY_ENABLED"

if ! composer show 'drupal/devel' &>/dev/null; then
log "Installing Devel module..."
composer require 'drupal/devel' -W || log "Error: Devel module installation failed"
fi

# If it wasn't initially enabled, enable it.
if [[ "$DEVEL_INITIALLY_ENABLED" == "Disabled" ]]; then
drush pm:enable -y devel || log "Error: Devel module enabling failed"
fi

# Attempt to reinstall Islandora (with error suppression). For new installs only.
# log "Attempting Islandora module uninstallation..."
# drush devel:reinstall -y islandora || log "Islandora uninstall may have partial failure. This can be ignored."

# Clear caches
log "Rebuilding caches..."
drush cache:rebuild
drush cron

log "Troubleshooting complete."
}

# Main script execution
main() {
check_dependencies
ensure_drush
troubleshoot_drupal
}

# Execute main function with error trapping
if main; then
log "Script completed successfully"
else
log "Script encountered errors"
exit 1
fi

# If it wasn't initially enabled, disable it at the end
if [[ "$DEVEL_INITIALLY_ENABLED" == "Disabled" ]]; then
drush pm:uninstall -y devel
fi

echo "Check LOG at $LOG_FILE"
Loading