git-hacks

git-hacks Commit Details

Date:2012-11-18 21:18:37 (5 years 11 months ago)
Author:Nicola Fontana
Branch:master
Commit:98c3b8985c69ab175bcebc095c221ab2264ba065
Parents: d5944aa1cb38fd3cf930728756796f0997c723f9
Message:gitdeploy: use PHP to get database config

After all bringing up the framework seems to be the only viable way to
not get lost on every _config.php modification.
Changes:
Mgitdeploy (1 diff)

File differences

gitdeploy
6060
6161
6262
63
64
65
66
67
68
69
7063
7164
7265
7366
7467
7568
76
69
70
71
72
73
74
75
76
77
7778
7879
79
80
80
81
8182
8283
83
84
85
86
87
88
84
85
86
8987
90
88
9189
92
90
9391
9492
9593
bootstrap
}
# Get the value part of a key => value assignment from a PHP source.
# The approach using regex is quite flaky but way better than loading
# a whole PHP framework to get a freaking value.
lookup() {
sed -n "s/\s*['\"]$1['\"]\s*=>\s*['\"]\(.*\)['\"].*/\1/p" $2 2> /dev/null
}
refresh_dummy() {
return 0
}
refresh_silverstripe() {
local path="$1"
local cfg db host user pwd
local cfg type server username password database
local php="
define('BASE_PATH', '$path');
define('FRAMEWORK_DIR', 'framework');
set_include_path(BASE_PATH . '/framework' . PATH_SEPARATOR . get_include_path());
require_once('core/Core.php');
foreach (\$databaseConfig as \$k => \$v)
echo \$k, '=', \$v, \"\n\";"
for cfg in "$path"/*/_config.php; do
db="$(lookup database $cfg)"
[ -n "$db" ] && break
eval $(php -r "$php")
[ -n "$database" ] && break
done
if [ -z "$db" ]; then return 1; fi
host=$(lookup server "$cfg")
[ -z "$host" ] && host=localhost
user=$(lookup username "$cfg")
pwd=$(lookup password "$cfg")
if [ -z "$server" -o -z "$username" -o -z "$password" -o -z "$database" ]; then
return 1
fi
mysqldump -h"$host" -u"$user" -p"$pwd" \
mysqldump -h"$server" -u"$username" -p"$password" \
--skip-lock-tables --skip-dump-date \
$db > $(dirname "$path")/"$db".sql
$database > $(dirname "$path")/"$database".sql
return 0
}

Archive Download the corresponding diff file

Branches