enhanced plugin support (#634)

- refactored admin controller and templates
- plugin support for entity actions
- changed column mail to email in customer table
- refactored theme events
This commit is contained in:
Kevin Papst
2019-03-11 14:46:30 +01:00
committed by GitHub
parent 519be2d5a2
commit 3ac72a5c89
104 changed files with 1878 additions and 976 deletions

View File

@@ -11,6 +11,7 @@ namespace App\Doctrine;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration as BaseAbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -50,6 +51,55 @@ abstract class AbstractMigration extends BaseAbstractMigration implements Contai
return getenv('DATABASE_PREFIX') . $name;
}
/**
* @param Schema $schema
* @throws DBALException
*/
public function preUp(Schema $schema): void
{
$this->abortIfPlatformNotSupported();
}
/**
* @param Schema $schema
* @throws DBALException
*/
public function preDown(Schema $schema): void
{
$this->abortIfPlatformNotSupported();
}
/**
* Abort the migration is the current platform is not supported.
*
* @throws DBALException
*/
protected function abortIfPlatformNotSupported()
{
$platform = $this->getPlatform();
if (!in_array($platform, ['sqlite', 'mysql'])) {
$this->abortIf(true, 'Unsupported database platform: ' . $platform);
}
}
/**
* @return bool
* @throws DBALException
*/
protected function isPlatformSqlite()
{
return ($this->getPlatform() === 'sqlite');
}
/**
* @return bool
* @throws DBALException
*/
protected function isPlatformMysql()
{
return ($this->getPlatform() === 'mysql');
}
/**
* @return string
* @throws DBALException
@@ -84,7 +134,7 @@ abstract class AbstractMigration extends BaseAbstractMigration implements Contai
protected function addSqlDropIndex($indexName, $tableName)
{
$dropSql = 'DROP INDEX ' . $indexName;
if ($this->getPlatform() === 'mysql') {
if (!$this->isPlatformSqlite()) {
$dropSql .= ' ON ' . $tableName;
}
$this->addSql($dropSql);

View File

@@ -15,6 +15,16 @@ use Doctrine\DBAL\Events;
class SqliteSessionInitSubscriber implements EventSubscriber
{
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
{
return [
Events::postConnect,
];
}
/**
* @param ConnectionEventArgs $args
* @throws \Doctrine\DBAL\DBALException
@@ -24,14 +34,7 @@ class SqliteSessionInitSubscriber implements EventSubscriber
if ('sqlite' !== strtolower($args->getDatabasePlatform()->getName())) {
return;
}
$args->getConnection()->executeUpdate('PRAGMA foreign_keys = ON;');
}
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
{
return [Events::postConnect];
}
}

View File

@@ -12,8 +12,8 @@ namespace App\Doctrine;
use App\Entity\Timesheet;
use App\Timesheet\CalculatorInterface;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Events;
/**
* A listener to make sure all Timesheet entries will have a proper duration.
@@ -26,7 +26,6 @@ class TimesheetSubscriber implements EventSubscriber
protected $calculator;
/**
* TimesheetSubscriber constructor.
* @param iterable $calculators
*/
public function __construct(iterable $calculators)
@@ -48,38 +47,43 @@ class TimesheetSubscriber implements EventSubscriber
public function getSubscribedEvents()
{
return [
'prePersist',
'preUpdate',
Events::onFlush,
];
}
/**
* @param PreUpdateEventArgs $args
* @param OnFlushEventArgs $args
*/
public function preUpdate(PreUpdateEventArgs $args)
public function onFlush(OnFlushEventArgs $args)
{
$this->calculateFields($args);
}
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
$meta = $em->getClassMetadata(Timesheet::class);
/**
* @param LifecycleEventArgs $args
*/
public function prePersist(LifecycleEventArgs $args)
{
$this->calculateFields($args);
}
foreach ($uow->getScheduledEntityUpdates() as $entity) {
if (!($entity instanceof Timesheet)) {
continue;
}
/**
* @param LifecycleEventArgs $args
*/
protected function calculateFields(LifecycleEventArgs $args)
{
$entity = $args->getObject();
if (!($entity instanceof Timesheet)) {
return;
$this->calculateFields($entity);
$uow->recomputeSingleEntityChangeSet($meta, $entity);
}
foreach ($uow->getScheduledEntityInsertions() as $entity) {
if (!($entity instanceof Timesheet)) {
continue;
}
$this->calculateFields($entity);
$uow->recomputeSingleEntityChangeSet($meta, $entity);
}
}
/**
* @param Timesheet $entity
*/
protected function calculateFields(Timesheet $entity)
{
foreach ($this->calculator as $calculator) {
$calculator->calculate($entity);
}