#!/usr/bin/env php = 7 && PHP_MINOR_VERSION >= 1) ?: die('Sorry, PHP 7.1 or above is required to run XBackBone.'); if (php_sapi_name() !== 'cli') { die(); } use App\Database\DB; use App\Database\Migrator; require __DIR__.'/../vendor/autoload.php'; $config = include __DIR__.'/../config.php'; if (!$config) { die('config.php not found. Please create a new one.'); } chdir(__DIR__.'/../'); $firstMigrate = false; if ($config['db']['connection'] === 'sqlite' && !file_exists(__DIR__.'/../'.$config['db']['dsn'])) { touch(__DIR__.'/../'.$config['db']['dsn']); $firstMigrate = true; } $db = new DB(dsnFromConfig($config, getcwd().DIRECTORY_SEPARATOR), $config['db']['username'], $config['db']['password']); $migrator = new Migrator($db, 'resources/schemas', $firstMigrate); $migrator->migrate(); if (isset($argv[1]) && $argv[1] === '--install') { $db->query("INSERT INTO `users` (`email`, `username`, `password`, `is_admin`, `user_code`) VALUES ('admin@example.com', 'admin', ?, 1, ?)", [password_hash('admin', PASSWORD_DEFAULT), humanRandomString(5)]); } if (file_exists(__DIR__.'/../install') && (!isset($config['debug']) || !$config['debug'])) { removeDirectory(__DIR__.'/../install'); } echo 'If you are upgrading from a previous version, please run a "php bin\clean".'.PHP_EOL; echo 'Done.'.PHP_EOL; exit(0);