-
Notifications
You must be signed in to change notification settings - Fork 8
/
bootstrap.php
71 lines (58 loc) · 2.2 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
$autoloader = require_once "vendor/autoload.php";
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\EntityManager;
use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager;
use Doctrine\Migrations\Configuration\Migration\YamlFile;
use Doctrine\Migrations\DependencyFactory;
use Symfony\Component\Yaml\Yaml;
$configFile = __DIR__."/config.yaml";
if(!file_exists($configFile) || !is_file($configFile))
die("config.yaml does not exist or is not a file)\n");
$config = Yaml::parseFile($configFile);
if(!is_array($config))
die("bad config file\n");
$isDevMode = true;
// keeping scripts entities in separate dirs so the script files are not autoloaded at the wrong time
$paths = [
__DIR__ . "/entities",
__DIR__ . "/scripts/linktitles/entities",
__DIR__ . "/scripts/weather/entities",
__DIR__ . "/scripts/lastfm/entities"
];
$ORMconfig = ORMSetup::createAttributeMetadataConfiguration($paths, $isDevMode);
// database configuration parameters
$conn = DriverManager::getConnection($config['database'], $ORMconfig);
//$conn = DriverManager::getConnection(array(
// 'driver' => 'pdo_pgsql',
// 'user' => 'lolbot',
// 'dbname' => 'lolbot',
// 'password' => 'lolpass',
// 'host' => 'localhost',
// 'port' => 5432,
// 'charset' => 'utf-8'
//), $ORMconfig);
/*
$conn = DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
], $ORMconfig);
*/
if($conn->getDatabasePlatform()::class == \Doctrine\DBAL\Platforms\SqlitePlatform::class)
$conn->executeStatement("PRAGMA foreign_keys=ON");
/**
* @psalm-suppress InvalidGlobal
*/
global $entityManager;
$entityManager = new EntityManager($conn, $ORMconfig);
$migrationConfig = new YamlFile('migrations.yml');
$dependencyFactory = DependencyFactory::fromEntityManager($migrationConfig, new ExistingEntityManager($entityManager));
function dieIfPendingMigration(): void
{
global $dependencyFactory;
$availMigrations = $dependencyFactory->getMigrationStatusCalculator()->getNewMigrations();
if ($availMigrations->count() != 0) {
die("EXITING: You have pending migrations to execute\n Use the vendor/bin/doctrine-migrations tool first\n");
}
}