generated from ddev/ddev-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctoggle
executable file
·81 lines (71 loc) · 2.59 KB
/
ctoggle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
## #ddev generated
## Description: Enable or disable caching
## Usage: ctoggle on|off|enable|disable|true|false
## Example: ddev ctoggle (default is "on")\nddev ctoggle off\nddev ctoggle on <site> - for multisite, specify the folder
## ProjectTypes: drupal8,drupal9,drupal10,drupal
# define configuration
local_settings="settings.personal.php"
site=${2:-"default"}
token="#caching#"
# DDEV will always start you in /var/www/html in container commands.
cd "web/sites" || exit 3
# Enables caching by adding a container yaml that points to a service
# that has caching on. If the line is already there, avoids adding
# it twice.
disable_caching() {
cd "$site" || exit 1
# Create the personal settings file if it doesn't exist.
if [ ! -f $local_settings ]; then
printf "<?php\n" > $local_settings
fi
if grep -qi "$token" $local_settings; then
echo "Caching was already off.";
else
echo "\$config['system.performance']['css']['preprocess'] = FALSE; $token" >> $local_settings
echo "\$config['system.performance']['js']['preprocess'] = FALSE; $token" >> $local_settings
echo "\$settings['cache']['bins']['render'] = 'cache.backend.null'; $token" >> $local_settings
echo "\$settings['cache']['bins']['page'] = 'cache.backend.null'; $token" >> $local_settings
echo "\$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null'; $token" >> $local_settings
echo -e "\e[32mCaching disabled.\e[0m"
cd "/var/www/html/$DDEV_DOCROOT" || exit 5
if [ "$site" != "default" ]; then
drush "@$site.local" cr
else
drush cr
fi
fi
}
# Disables caching by removing the line that points to the container
# yaml. It does this by searching for a token that's appended as a comment.
enable_caching() {
cd "$site" || exit 1
# Create the personal settings file if it doesn't exist.
if [ ! -f $local_settings ]; then
printf "<?php\n" > $local_settings
fi
# Remove the line that contains the token if you are turning off.
sed -i -e "/$token/d" $local_settings || exit 4
echo -e "\e[32mCaching enabled.\e[0m"
cd "/var/www/html/$DDEV_DOCROOT" || exit 5
if [ "$site" != "default" ]; then
drush "@$site.local" cr
else
drush cr
fi
}
# Assume that they want the 'default' site folder if they have not specified.
if [ $# -eq 0 ] ; then
enable_caching "$site"
exit
fi
case $1 in
on|true|enable)
enable_caching "$site"
;;
off|false|disable)
disable_caching "$site"
;;
*)
echo "Please enter a valid argument."
esac