Newwebshop/src/Core/Installer/Installer.php

88 lines
3.1 KiB
PHP

<?php
/**
* Copyright seit 2024 Webshop System
*
* Installer für das Webshop-System
*
* @author Webshop System
* @license GPL v3
*/
namespace Webshop\Core\Installer;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception;
class Installer
{
public static function postInstall()
{
// DB-Verbindung herstellen
$connectionParams = [
'dbname' => getenv('DB_DATABASE') ?: 'freeshop',
'user' => getenv('DB_USERNAME') ?: 'freeshop_user',
'password' => getenv('DB_PASSWORD') ?: 'freeshop_password',
'host' => getenv('DB_HOST') ?: 'db',
'driver' => 'pdo_mysql',
'port' => getenv('DB_PORT') ?: 3306,
'charset' => 'utf8mb4',
];
try {
$conn = DriverManager::getConnection($connectionParams);
} catch (Exception $e) {
echo "Fehler bei der DB-Verbindung: " . $e->getMessage() . "\n";
exit(1);
}
// Admin-User anlegen
$adminMail = 'admin@webshop.local';
$adminPass = password_hash('admin123', PASSWORD_DEFAULT);
$conn->executeStatement('INSERT IGNORE INTO ws_user (email, password, firstname, lastname, is_admin) VALUES (?, ?, ?, ?, 1)', [
$adminMail, $adminPass, 'Admin', 'Webshop'
]);
// Shop anlegen
$conn->executeStatement('INSERT IGNORE INTO ws_shop (name, domain, domain_ssl, physical_uri, theme) VALUES (?, ?, ?, ?, ?)', [
'Mein Webshop', 'localhost', 'localhost', '/', 'classic'
]);
// Sprachen anlegen
$conn->executeStatement('INSERT IGNORE INTO ws_language (name, iso_code, locale) VALUES (?, ?, ?)', [
'Deutsch', 'de', 'de_DE'
]);
$conn->executeStatement('INSERT IGNORE INTO ws_language (name, iso_code, locale) VALUES (?, ?, ?)', [
'English', 'en', 'en_US'
]);
// Länder anlegen
$conn->executeStatement('INSERT IGNORE INTO ws_country (name, iso_code) VALUES (?, ?)', [
'Deutschland', 'DE'
]);
$conn->executeStatement('INSERT IGNORE INTO ws_country (name, iso_code) VALUES (?, ?)', [
'Österreich', 'AT'
]);
$conn->executeStatement('INSERT IGNORE INTO ws_country (name, iso_code) VALUES (?, ?)', [
'Schweiz', 'CH'
]);
// Konfiguration anlegen
$conn->executeStatement('INSERT IGNORE INTO ws_configuration (config_key, config_value) VALUES (?, ?)', [
'WS_COUNTRY_DEFAULT', '1'
]);
$conn->executeStatement('INSERT IGNORE INTO ws_configuration (config_key, config_value) VALUES (?, ?)', [
'WS_LANG_DEFAULT', '1'
]);
$conn->executeStatement('INSERT IGNORE INTO ws_configuration (config_key, config_value) VALUES (?, ?)', [
'WS_TIMEZONE', 'Europe/Berlin'
]);
echo "Webshop erfolgreich installiert!\n";
echo "Admin-Login: admin@webshop.local / admin123\n";
}
public static function postUpdate()
{
// TODO: Update-Logik
echo "Webshop erfolgreich aktualisiert!\n";
}
}