Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -10,6 +10,7 @@
namespace App\Doctrine;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration as BaseAbstractMigration;
@@ -20,17 +21,6 @@ use Doctrine\Migrations\AbstractMigration as BaseAbstractMigration;
*/
abstract class AbstractMigration extends BaseAbstractMigration
{
/**
* @param string $name
* @return string
*/
protected function getTableName($name)
{
@trigger_error('AbstractMigration::getTableName() is deprecated and will be removed with 2.0', E_USER_DEPRECATED);
return 'kimai2_' . $name;
}
/**
* @see https://github.com/doctrine/migrations/issues/1104
*/
@@ -39,16 +29,6 @@ abstract class AbstractMigration extends BaseAbstractMigration
return false;
}
/**
* @deprecated since 1.14 - will be removed with 2.0
*/
protected function isSupportingForeignKeys(): bool
{
@trigger_error('isSupportingForeignKeys() is deprecated and will be removed with 2.0', E_USER_DEPRECATED);
return true;
}
/**
* @param Schema $schema
* @throws Exception
@@ -74,46 +54,12 @@ abstract class AbstractMigration extends BaseAbstractMigration
*/
protected function abortIfPlatformNotSupported()
{
$platform = $this->getPlatform();
if (!$this->isPlatformMysql()) {
$this->abortIf(true, 'Unsupported database platform: ' . $platform);
$platform = $this->connection->getDatabasePlatform();
if (!($platform instanceof MySQLPlatform)) {
$this->abortIf(true, 'Unsupported database platform: ' . \get_class($platform));
}
}
/**
* @deprecated since 1.14 - will be removed with 2.0
*/
protected function isPlatformSqlite(): bool
{
@trigger_error('isPlatformSqlite() is deprecated and will be removed with 2.0', E_USER_DEPRECATED);
return ($this->getPlatform() === 'sqlite');
}
protected function isPlatformMysql(): bool
{
return ($this->getPlatform() === 'mysql');
}
/**
* @return string
* @throws Exception
*/
protected function getPlatform()
{
return $this->connection->getDatabasePlatform()->getName();
}
/**
* @deprecated since 1.14 - will be removed with 2.0
*/
protected function addSqlDropIndex($indexName, $tableName)
{
@trigger_error('addSqlDropIndex() is deprecated and will be removed with 2.0', E_USER_DEPRECATED);
$this->addSql('DROP INDEX ' . $indexName . ' ON ' . $tableName);
}
protected function preventEmptyMigrationWarning(): void
{
$this->addSql('#prevent empty warning - no SQL to execute');

View File

@@ -0,0 +1,34 @@
<?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\Extensions;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
final class Date extends FunctionNode
{
private Node|string|null $value;
public function getSql(SqlWalker $sqlWalker): string
{
return 'DATE(' . $sqlWalker->walkArithmeticPrimary($this->value) . ')';
}
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->value = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}

View File

@@ -0,0 +1,34 @@
<?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\Extensions;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
final class Day extends FunctionNode
{
private Node|string|null $value;
public function getSql(SqlWalker $sqlWalker): string
{
return 'DAY(' . $sqlWalker->walkArithmeticPrimary($this->value) . ')';
}
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->value = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}

View File

@@ -0,0 +1,34 @@
<?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\Extensions;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
final class Month extends FunctionNode
{
private Node|string|null $value;
public function getSql(SqlWalker $sqlWalker): string
{
return 'MONTH(' . $sqlWalker->walkArithmeticPrimary($this->value) . ')';
}
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->value = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}

View File

@@ -0,0 +1,34 @@
<?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\Extensions;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
final class Year extends FunctionNode
{
private Node|string|null $value;
public function getSql(SqlWalker $sqlWalker): string
{
return 'YEAR(' . $sqlWalker->walkArithmeticPrimary($this->value) . ')';
}
public function parse(Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->value = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}

View File

@@ -18,23 +18,18 @@ use Doctrine\ORM\Events;
/**
* A listener to make sure all Timesheet entries will have a proper duration.
*/
class TimesheetSubscriber implements EventSubscriber
final class TimesheetSubscriber implements EventSubscriber
{
/**
* @var CalculatorInterface[]
*/
private $calculator;
/**
* @var CalculatorInterface[]
*/
private $sorted;
private ?array $sorted = null;
/**
* @param CalculatorInterface[] $calculators
*/
public function __construct(iterable $calculators)
public function __construct(private iterable $calculators)
{
$this->calculator = $calculators;
}
public function getSubscribedEvents(): array
@@ -46,7 +41,7 @@ class TimesheetSubscriber implements EventSubscriber
public function onFlush(OnFlushEventArgs $args): void
{
$em = $args->getEntityManager();
$em = $args->getObjectManager();
$uow = $em->getUnitOfWork();
$meta = $em->getClassMetadata(Timesheet::class);
@@ -69,17 +64,14 @@ class TimesheetSubscriber implements EventSubscriber
}
}
protected function calculateFields(Timesheet $entity, array $changes = []): void
private function calculateFields(Timesheet $entity, array $changes = []): void
{
if ($this->sorted === null) {
$this->sorted = [];
foreach ($this->calculator as $calculator) {
foreach ($this->calculators as $calculator) {
$i = 0;
$prio = 1000;
if (method_exists($calculator, 'getPriority')) {
$prio = $calculator->getPriority();
}
$prio = $calculator->getPriority();
do {
$key = $prio + $i++;
@@ -92,7 +84,6 @@ class TimesheetSubscriber implements EventSubscriber
}
foreach ($this->sorted as $calculator) {
/* @phpstan-ignore-next-line */
$calculator->calculate($entity, $changes);
}
}

View File

@@ -13,12 +13,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\DateTimeType;
class UTCDateTimeType extends DateTimeType
final class UTCDateTimeType extends DateTimeType
{
/**
* @var \DateTimeZone|null
*/
private static $utc;
private static ?\DateTimeZone $utc = null;
/**
* @param mixed $value
@@ -26,7 +26,7 @@ class UTCDateTimeType extends DateTimeType
* @return mixed|string
* @throws ConversionException
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed
{
if ($value instanceof \DateTime) {
$value = clone $value;
@@ -36,21 +36,22 @@ class UTCDateTimeType extends DateTimeType
return parent::convertToDatabaseValue($value, $platform);
}
/**
* @return \DateTimeZone
*/
public static function getUtc()
public static function getUtc(): \DateTimeZone
{
return self::$utc ? self::$utc : self::$utc = new \DateTimeZone('UTC');
if (self::$utc === null) {
self::$utc = new \DateTimeZone('UTC');
}
return self::$utc;
}
/**
* @param mixed $value
* @param AbstractPlatform $platform
* @return bool|\DateTime|false|mixed
* @return null|\DateTime
* @throws ConversionException
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
public function convertToPHPValue($value, AbstractPlatform $platform): ?\DateTime
{
if (null === $value || $value instanceof \DateTime) {
return $value;
@@ -73,7 +74,7 @@ class UTCDateTimeType extends DateTimeType
return $converted;
}
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}