Support foreign keys with SQLite (#590)

This commit is contained in:
Kevin Papst
2019-02-20 20:06:19 +01:00
committed by GitHub
parent 3f535cc506
commit fd4a87e3a6
4 changed files with 55 additions and 9 deletions

View File

@@ -0,0 +1,37 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Doctrine;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
class SqliteSessionInitSubscriber implements EventSubscriber
{
/**
* @param ConnectionEventArgs $args
* @throws \Doctrine\DBAL\DBALException
*/
public function postConnect(ConnectionEventArgs $args)
{
if ('sqlite' !== strtolower($args->getDatabasePlatform()->getName())) {
return;
}
$args->getConnection()->executeUpdate('PRAGMA foreign_keys = ON;');
}
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
{
return [Events::postConnect];
}
}