kimai-plugin-heatmap/dev/setup.sh
Christopher Mühl 9871c2e707
feat: DI extension, services.yaml, and autoloader fix for plugin detection
- Add DependencyInjection/KimaiHeatmapExtension to load services.yaml
- Register bundle as tagged PluginInterface service so PluginManager finds it
- Exclude recursive symlink path from Kimai's autoloader classmap
- Bump PHP memory_limit to 1G for Kimai cache warmup

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 12:26:17 +02:00

91 lines
2.8 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
KIMAI_DIR="$SCRIPT_DIR/kimai"
DATA_DIR="$SCRIPT_DIR/.mariadb-data"
# Step 1: Initialize MariaDB data directory
if [ ! -d "$DATA_DIR" ]; then
echo "==> Initializing MariaDB data directory..."
mysql_install_db --datadir="$DATA_DIR" --auth-root-authentication-method=normal
fi
# Step 2: Start MariaDB temporarily for setup
echo "==> Starting MariaDB for setup..."
mysqld --datadir="$DATA_DIR" --socket="$SCRIPT_DIR/.mariadb.sock" --port=3307 --skip-grant-tables --skip-networking=false --bind-address=127.0.0.1 &
MARIADB_PID=$!
trap "kill $MARIADB_PID 2>/dev/null || true; wait $MARIADB_PID 2>/dev/null || true" EXIT
# Wait for MariaDB to be ready
for i in $(seq 1 30); do
if mysqladmin --socket="$SCRIPT_DIR/.mariadb.sock" ping 2>/dev/null; then
break
fi
sleep 1
done
# Create database
mysql --socket="$SCRIPT_DIR/.mariadb.sock" -e "CREATE DATABASE IF NOT EXISTS kimai;"
# Step 3: Clone Kimai
if [ ! -d "$KIMAI_DIR" ]; then
echo "==> Cloning Kimai 2.52.0..."
git clone -b 2.52.0 --depth 1 https://github.com/kimai/kimai.git "$KIMAI_DIR"
fi
# Step 4: Configure Kimai
cat > "$KIMAI_DIR/.env.local" <<EOF
DATABASE_URL=mysql://root@127.0.0.1:3307/kimai?charset=utf8mb4&serverVersion=11.4.9-MariaDB
APP_SECRET=$(openssl rand -hex 16)
APP_ENV=dev
MAILER_URL=null://null
EOF
# Step 5: Install Composer dependencies
echo "==> Installing Composer dependencies..."
cd "$KIMAI_DIR"
composer install --no-interaction
# Step 6: Install Kimai (creates schema, runs migrations)
echo "==> Installing Kimai..."
bin/console kimai:install -n
# Step 7: Load test fixtures
echo "==> Loading test fixtures..."
bin/console kimai:reset:dev -n
# Step 8: Symlink plugin
echo "==> Symlinking plugin..."
mkdir -p var/plugins
ln -sfn "$PROJECT_DIR" var/plugins/KimaiHeatmapBundle
# Step 9: Exclude recursive symlink from autoloader classmap
# The plugin symlink points to project root which contains dev/kimai/ creating a loop.
# Tell Composer to skip scanning the dev/ directory inside the plugin symlink.
cd "$KIMAI_DIR"
php -r '
$f = "composer.json";
$j = json_decode(file_get_contents($f), true);
$exclude = "var/plugins/KimaiHeatmapBundle/dev/";
if (!in_array($exclude, $j["autoload"]["exclude-from-classmap"] ?? [])) {
$j["autoload"]["exclude-from-classmap"][] = $exclude;
file_put_contents($f, json_encode($j, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n");
}
'
composer dump-autoload
# Step 10: Clear cache
bin/console cache:clear
# Stop MariaDB
kill $MARIADB_PID 2>/dev/null || true
wait $MARIADB_PID 2>/dev/null || true
trap - EXIT
echo ""
echo "==> Setup complete!"
echo " Run: process-compose -f dev/process-compose.yaml up"
echo " Then open: http://127.0.0.1:8010"
echo " Login: susan_super / password"