Support foreign keys with SQLite (#590)
This commit is contained in:
37
src/Doctrine/SqliteSessionInitSubscriber.php
Normal file
37
src/Doctrine/SqliteSessionInitSubscriber.php
Normal 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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user