Skip to content

Commit 8100d05

Browse files
authored
Merge pull request #9 from solutionDrive/feature/de-activate-plugin-script
Feature/de activate plugin script
2 parents c4d356e + 7ba127c commit 8100d05

File tree

2 files changed

+121
-1
lines changed

2 files changed

+121
-1
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ Usage / First steps
3737
First you should start the testing docker containers (see also next section of this README):
3838

3939
vendor/bin/sdTest.sh start
40+
41+
42+
Handle plugin
43+
-------------
44+
45+
For all following commands you must pass a php version, e.g. 71 for PHP 7.1 container:
46+
47+
For adding the plugin run:
48+
49+
vendor/bin/sdPlugin.sh 71 add
50+
51+
For removing the plugin run:
52+
53+
vendor/bin/sdPlugin.sh 71 remove
54+
55+
For activating the plugin run:
56+
57+
vendor/bin/sdPlugin.sh 71 activate
58+
59+
For deactivating the plugin run:
60+
61+
vendor/bin/sdPlugin.sh 71 deactivate
62+
4063

4164
Controlling the testing environment
4265
-----------------------------------
@@ -97,7 +120,7 @@ Executing a command in the testing environment
97120
----------------------------------------------
98121

99122
Commands (for example to clear the cache or to run the setup) can be executed inside the container.
100-
You must give a version to execute command on, for example 7.1 for PHP 7.1 container:
123+
You must give a version to execute command on, e.g. 71 for PHP 7.1 container:
101124

102125
vendor/bin/runInSdTest.sh 71 ./app/install.sh
103126

bin/sdPlugin.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env bash
2+
VERSION=$1
3+
4+
if [ -z "${VERSION}" ]; then
5+
echo "You must give a version to execute command on, for example 71 for PHP 7.1 container."
6+
exit 1
7+
fi
8+
9+
# directory of this script
10+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
11+
12+
if [ -d ${DIR}/../vendor/solutiondrive/sd-test-environment-shopware ]; then
13+
PACKAGE_DIR="$( dirname "${DIR}" )"/vendor/solutiondrive/sd-test-environment-shopware
14+
elif [ -d ${DIR}/../solutiondrive/sd-test-environment-shopware ]; then
15+
PACKAGE_DIR="$( cd "$( dirname "${DIR}" )"/solutiondrive/sd-test-environment-shopware && pwd )"
16+
elif [ -d ${DIR}/../../../solutiondrive/sd-test-environment-shopware ]; then
17+
PACKAGE_DIR="$( dirname "${DIR}" )"
18+
fi
19+
20+
if [ ! -d ${PACKAGE_DIR} ]; then
21+
echo "Could not find package directory of sd-test-environment-shopware. Did you move the bin directory?"
22+
exit 1
23+
fi
24+
25+
PROJECT_DIR="$( dirname $( dirname $( dirname "${PACKAGE_DIR}") ) )"
26+
PROJECT_NAME="$( basename ${PROJECT_DIR} | tr '[:upper:]' '[:lower:]' )"
27+
# TODO: Think about a good solution for a different shopware version
28+
PHP_CONTAINER_NAME="${PROJECT_NAME}_shopware546_php${VERSION}_1"
29+
WORK_DIR="/var/www/shopware54_php${VERSION}"
30+
31+
PLUGIN_NAME=$(find . -name '*.php' -maxdepth 1 |sed 's#.*/##' | sed 's/\.php$//1')
32+
33+
PLUGIN_DIRECTORY="custom/plugins/$PLUGIN_NAME"
34+
35+
function add_plugin {
36+
echo "Init plugin $PLUGIN_NAME"
37+
link_plugin
38+
install_plugin
39+
activate_plugin
40+
}
41+
42+
function link_plugin {
43+
echo "Link plugin $PROJECT_NAME to $PLUGIN_DIRECTORY"
44+
execute_in_docker "ln -s /opt/host $PLUGIN_DIRECTORY"
45+
}
46+
47+
function install_plugin {
48+
execute_in_docker "bin/console sw:plugin:refresh"
49+
execute_in_docker "bin/console sw:plugin:install $PLUGIN_NAME"
50+
}
51+
52+
function activate_plugin {
53+
execute_in_docker "bin/console sw:plugin:activate $PLUGIN_NAME"
54+
execute_in_docker "bin/console sw:cache:clear"
55+
}
56+
57+
function deactivate_plugin {
58+
execute_in_docker "bin/console sw:plugin:deactivate $PLUGIN_NAME"
59+
execute_in_docker "bin/console sw:cache:clear"
60+
}
61+
62+
function remove_plugin {
63+
deactivate_plugin
64+
execute_in_docker "bin/console sw:plugin:uninstall $PLUGIN_NAME"
65+
execute_in_docker "rm $PLUGIN_DIRECTORY"
66+
}
67+
68+
function execute_in_docker {
69+
docker exec --workdir ${WORK_DIR} -it ${PHP_CONTAINER_NAME} $1
70+
}
71+
72+
## start of the real program
73+
74+
export PROJECT_DIR
75+
export PROJECT_NAME
76+
77+
case "$2" in
78+
add)
79+
shift
80+
add_plugin $@
81+
;;
82+
remove)
83+
shift
84+
remove_plugin $@
85+
;;
86+
activate)
87+
shift
88+
activate_plugin $@
89+
;;
90+
deactivate)
91+
shift
92+
deactivate_plugin $@
93+
;;
94+
*)
95+
echo "usage: add/remove/activate/deactivate"
96+
;;
97+
esac

0 commit comments

Comments
 (0)