mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
first commit
This commit is contained in:
84
setup.php
Normal file
84
setup.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// Load helper functions
|
||||
require_once __DIR__ . '/app/helpers.php';
|
||||
|
||||
// Load environment variables
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||
$dotenv->load();
|
||||
|
||||
// Load database configuration
|
||||
$dbConfig = require __DIR__ . '/config/database.php';
|
||||
|
||||
// Set up database connection
|
||||
try {
|
||||
\App\Database\Database::setConfig($dbConfig);
|
||||
$pdo = \App\Database\Database::getInstance();
|
||||
echo "Database connection established successfully.\n";
|
||||
} catch (Exception $e) {
|
||||
die('Database connection failed: ' . $e->getMessage() . "\n");
|
||||
}
|
||||
|
||||
// Set up Laravel facades for migrations
|
||||
$capsule = \App\Database\Database::getCapsule();
|
||||
$capsule->setAsGlobal();
|
||||
$capsule->bootEloquent();
|
||||
|
||||
// Run migrations
|
||||
echo "Running database migrations...\n";
|
||||
try {
|
||||
\App\Database\Database::migrate();
|
||||
echo "✓ Migrations completed successfully.\n";
|
||||
} catch (Exception $e) {
|
||||
echo "✗ Migration failed: " . $e->getMessage() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Seed the database
|
||||
echo "Seeding database with initial data...\n";
|
||||
try {
|
||||
\App\Database\Database::seed();
|
||||
echo "✓ Database seeded successfully.\n";
|
||||
} catch (Exception $e) {
|
||||
echo "✗ Seeding failed: " . $e->getMessage() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Create initial admin user
|
||||
echo "Creating initial admin user...\n";
|
||||
try {
|
||||
$adminUsername = env('ADMIN_USERNAME', 'admin');
|
||||
$adminEmail = env('ADMIN_EMAIL', 'admin@example.com');
|
||||
$adminPassword = env('ADMIN_PASSWORD', 'admin123');
|
||||
|
||||
if (empty($adminPassword)) {
|
||||
echo "! Warning: ADMIN_PASSWORD not set in environment variables.\n";
|
||||
echo " Please set ADMIN_PASSWORD in your .env file or environment.\n";
|
||||
echo " You can manually create an admin user later.\n";
|
||||
} else {
|
||||
$userModel = new \App\Models\User($pdo);
|
||||
|
||||
// Check if admin user already exists
|
||||
$existingUser = $userModel::findByUsername($pdo, $adminUsername);
|
||||
if (!$existingUser) {
|
||||
$userModel::createAdmin($pdo, $adminUsername, $adminEmail, $adminPassword);
|
||||
echo "✓ Admin user created successfully.\n";
|
||||
echo " Username: {$adminUsername}\n";
|
||||
echo " Email: {$adminEmail}\n";
|
||||
echo " Password: {$adminPassword}\n";
|
||||
} else {
|
||||
echo "✓ Admin user already exists.\n";
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "✗ Admin user creation failed: " . $e->getMessage() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo "\n🎉 Database setup completed successfully!\n";
|
||||
echo "You can now start your application with: php -S localhost:8000 -t public\n";
|
||||
echo "\nDefault admin credentials:\n";
|
||||
echo " Username: " . env('ADMIN_USERNAME', 'admin') . "\n";
|
||||
echo " Password: " . env('ADMIN_PASSWORD', 'admin123') . "\n";
|
||||
Reference in New Issue
Block a user