Integrated FOSUserBundle (#216)

This commit is contained in:
Kevin Papst
2018-07-21 22:36:36 +02:00
committed by GitHub
parent 2d2525cff2
commit 75246e9db2
77 changed files with 1413 additions and 514 deletions

View File

@@ -0,0 +1,90 @@
<?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\Migrations\AbstractMigration as BaseAbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Base class for all Doctrine migrations.
*/
abstract class AbstractMigration extends BaseAbstractMigration implements ContainerAwareInterface
{
/**
* @var ContainerInterface
*/
private $container;
/**
* @param ContainerInterface $container
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
/**
* @return ContainerInterface
*/
public function getContainer()
{
return $this->container;
}
/**
* @param string $name
* @return string
*/
protected function getTableName($name)
{
return getenv('DATABASE_PREFIX') . $name;
}
/**
* @return string
* @throws \Doctrine\DBAL\DBALException
*/
protected function getPlatform()
{
return $this->connection->getDatabasePlatform()->getName();
}
/**
* Call me like this:
* $schema = $this->getClassMetaData(User::class);
*
* @param string $entityName
* @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
*/
protected function getClassMetaData($entityName)
{
$em = $this->getContainer()->get('doctrine')->getManager();
return $em->getClassMetadata($entityName);
}
/**
* we do it via addSql instead of $schema->getTable($users)->dropIndex()
* otherwise the commands will be executed as last ones.
*
* @param string $indexName
* @param string $tableName
* @throws \Doctrine\DBAL\DBALException
*/
protected function addSqlDropIndex($indexName, $tableName)
{
$dropSql = 'DROP INDEX ' . $indexName;
if ($this->getPlatform() === 'mysql') {
$dropSql .= ' ON ' . $tableName;
}
$this->addSql($dropSql);
}
}