From 1a8c78944acdde24a75b544d7bd04bf51758f984 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Tue, 14 Mar 2023 23:51:49 +0100 Subject: [PATCH] Release 2.0.9 (#3922) * fix api definition * include customer number in validation message * fix doctrine deprecation, prepare for DBAL 4 * added DataSubscriberInterface to identify certain doctrine subscribers --- migrations/Version20190706224211.php | 16 +++++----- migrations/Version20210802152814.php | 2 +- migrations/Version20210802160837.php | 4 +-- src/Command/UpdateCommand.php | 13 ++++---- src/Constants.php | 4 +-- src/Doctrine/DataSubscriberInterface.php | 18 +++++++++++ src/Doctrine/TimesheetSubscriber.php | 4 +-- src/Doctrine/UTCDateTimeType.php | 5 ---- src/Entity/Activity.php | 2 +- src/Entity/User.php | 2 +- src/User/UserService.php | 2 +- src/Validator/Constraints/Customer.php | 2 +- .../Constraints/CustomerValidator.php | 1 + tests/Doctrine/UTCDateTimeTypeTest.php | 20 ++++--------- tests/phpstan.neon | 30 ------------------- 15 files changed, 50 insertions(+), 75 deletions(-) create mode 100644 src/Doctrine/DataSubscriberInterface.php diff --git a/migrations/Version20190706224211.php b/migrations/Version20190706224211.php index cd9f5f8b..c0de7a5c 100644 --- a/migrations/Version20190706224211.php +++ b/migrations/Version20190706224211.php @@ -29,20 +29,20 @@ final class Version20190706224211 extends AbstractMigration public function up(Schema $schema): void { $timesheetMeta = $schema->getTable('kimai2_timesheet_meta'); - $timesheetMeta->changeColumn('visible', ['notnull' => true, 'default' => false]); - $timesheetMeta->changeColumn('timesheet_id', ['notnull' => true]); + $timesheetMeta->modifyColumn('visible', ['notnull' => true, 'default' => false]); + $timesheetMeta->modifyColumn('timesheet_id', ['notnull' => true]); $projectMeta = $schema->getTable('kimai2_projects_meta'); - $projectMeta->changeColumn('visible', ['notnull' => true, 'default' => false]); - $projectMeta->changeColumn('project_id', ['notnull' => true]); + $projectMeta->modifyColumn('visible', ['notnull' => true, 'default' => false]); + $projectMeta->modifyColumn('project_id', ['notnull' => true]); $customerMeta = $schema->getTable('kimai2_customers_meta'); - $customerMeta->changeColumn('visible', ['notnull' => true, 'default' => false]); - $customerMeta->changeColumn('customer_id', ['notnull' => true]); + $customerMeta->modifyColumn('visible', ['notnull' => true, 'default' => false]); + $customerMeta->modifyColumn('customer_id', ['notnull' => true]); $activityMeta = $schema->getTable('kimai2_activities_meta'); - $activityMeta->changeColumn('visible', ['notnull' => true, 'default' => false]); - $activityMeta->changeColumn('activity_id', ['notnull' => true]); + $activityMeta->modifyColumn('visible', ['notnull' => true, 'default' => false]); + $activityMeta->modifyColumn('activity_id', ['notnull' => true]); } public function down(Schema $schema): void diff --git a/migrations/Version20210802152814.php b/migrations/Version20210802152814.php index 939e9413..bc3d68a0 100644 --- a/migrations/Version20210802152814.php +++ b/migrations/Version20210802152814.php @@ -51,7 +51,7 @@ final class Version20210802152814 extends AbstractMigration public function down(Schema $schema): void { $timesheet = $schema->getTable('kimai2_timesheet'); - $timesheet->changeColumn('date_tz', ['notnull' => false]); + $timesheet->modifyColumn('date_tz', ['notnull' => false]); $this->preventEmptyMigrationWarning(); } diff --git a/migrations/Version20210802160837.php b/migrations/Version20210802160837.php index ff22988e..af0a69e7 100644 --- a/migrations/Version20210802160837.php +++ b/migrations/Version20210802160837.php @@ -27,14 +27,14 @@ final class Version20210802160837 extends AbstractMigration public function up(Schema $schema): void { $timesheet = $schema->getTable('kimai2_timesheet'); - $timesheet->changeColumn('date_tz', ['notnull' => true]); + $timesheet->modifyColumn('date_tz', ['notnull' => true]); $timesheet->addIndex(['date_tz', 'user'], 'IDX_4F60C6B1BDF467148D93D649'); } public function down(Schema $schema): void { $timesheet = $schema->getTable('kimai2_timesheet'); - $timesheet->changeColumn('date_tz', ['notnull' => false]); + $timesheet->modifyColumn('date_tz', ['notnull' => false]); $timesheet->dropIndex('IDX_4F60C6B1BDF467148D93D649'); } } diff --git a/src/Command/UpdateCommand.php b/src/Command/UpdateCommand.php index 8ea49e1c..1bffe34a 100644 --- a/src/Command/UpdateCommand.php +++ b/src/Command/UpdateCommand.php @@ -11,6 +11,7 @@ namespace App\Command; use App\Constants; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Exception\ConnectionException; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArrayInput; @@ -47,12 +48,6 @@ final class UpdateCommand extends Command // make sure database is available, Kimai running and installed try { - if (!$this->connection->isConnected() && !$this->connection->connect()) { - throw new \Exception( - sprintf('Database connection could not be established: %s', $this->connection->getDatabase()) - ); - } - if (!$this->connection->createSchemaManager()->tablesExist(['kimai2_users', 'kimai2_timesheet'])) { $io->error('Tables missing. Did you run the installer already?'); @@ -64,8 +59,12 @@ final class UpdateCommand extends Command return Command::FAILURE; } + } catch (ConnectionException $e) { + $io->error(['Database connection could not be established.', $e->getMessage()]); + + return Command::FAILURE; } catch (\Exception $ex) { - $io->error('Failed to validate database: ' . $ex->getMessage()); + $io->error(['Failed to validate database.', $ex->getMessage()]); return Command::FAILURE; } diff --git a/src/Constants.php b/src/Constants.php index 9b6ffec3..4f9baddf 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -17,11 +17,11 @@ class Constants /** * The current release version */ - public const VERSION = '2.0.8'; + public const VERSION = '2.0.9'; /** * The current release: major * 10000 + minor * 100 + patch */ - public const VERSION_ID = 20008; + public const VERSION_ID = 20009; /** * The software name */ diff --git a/src/Doctrine/DataSubscriberInterface.php b/src/Doctrine/DataSubscriberInterface.php new file mode 100644 index 00000000..be831a59 --- /dev/null +++ b/src/Doctrine/DataSubscriberInterface.php @@ -0,0 +1,18 @@ +hashPassword($user); $this->hashApiToken($user); - $this->dispatcher->dispatch(new UserCreatePreEvent($user)); + $this->dispatcher->dispatch(new UserCreatePreEvent($user)); // @CloudRequired $this->repository->saveUser($user); $this->dispatcher->dispatch(new UserCreatePostEvent($user)); diff --git a/src/Validator/Constraints/Customer.php b/src/Validator/Constraints/Customer.php index 157c7819..2c52a86f 100644 --- a/src/Validator/Constraints/Customer.php +++ b/src/Validator/Constraints/Customer.php @@ -17,7 +17,7 @@ final class Customer extends Constraint public const CUSTOMER_NUMBER_EXISTING = 'kimai-customer-00'; protected const ERROR_NAMES = [ - self::CUSTOMER_NUMBER_EXISTING => 'This account number is already used.', + self::CUSTOMER_NUMBER_EXISTING => 'The account number %number% is already used.', ]; public string $message = 'This customer has invalid settings.'; diff --git a/src/Validator/Constraints/CustomerValidator.php b/src/Validator/Constraints/CustomerValidator.php index bcacdffa..599e1bb4 100644 --- a/src/Validator/Constraints/CustomerValidator.php +++ b/src/Validator/Constraints/CustomerValidator.php @@ -40,6 +40,7 @@ final class CustomerValidator extends ConstraintValidator $tmp = $this->customerRepository->findOneBy(['number' => $number]); if ($tmp !== null && $tmp->getId() !== $value->getId()) { $this->context->buildViolation(Customer::getErrorName(Customer::CUSTOMER_NUMBER_EXISTING)) + ->setParameter('%number%', $number) ->atPath('number') ->setTranslationDomain('validators') ->setCode(Customer::CUSTOMER_NUMBER_EXISTING) diff --git a/tests/Doctrine/UTCDateTimeTypeTest.php b/tests/Doctrine/UTCDateTimeTypeTest.php index 34624efd..d5e7074f 100644 --- a/tests/Doctrine/UTCDateTimeTypeTest.php +++ b/tests/Doctrine/UTCDateTimeTypeTest.php @@ -22,7 +22,7 @@ use PHPUnit\Framework\TestCase; */ class UTCDateTimeTypeTest extends TestCase { - public function testGetUtc() + public function testGetUtc(): void { Type::overrideType(Types::DATETIME_MUTABLE, UTCDateTimeType::class); /** @var UTCDateTimeType $type */ @@ -37,7 +37,7 @@ class UTCDateTimeTypeTest extends TestCase /** * @dataProvider getPlatforms */ - public function testConvertToDatabaseValue(AbstractPlatform $platform) + public function testConvertToDatabaseValue(AbstractPlatform $platform): void { Type::overrideType(Types::DATETIME_MUTABLE, UTCDateTimeType::class); /** @var UTCDateTimeType $type */ @@ -65,7 +65,7 @@ class UTCDateTimeTypeTest extends TestCase /** * @dataProvider getPlatforms */ - public function testConvertToPHPValue(AbstractPlatform $platform) + public function testConvertToPHPValue(AbstractPlatform $platform): void { Type::overrideType(Types::DATETIME_MUTABLE, UTCDateTimeType::class); /** @var UTCDateTimeType $type */ @@ -85,7 +85,7 @@ class UTCDateTimeTypeTest extends TestCase /** * @dataProvider getPlatforms */ - public function testConvertToPHPValueWithInvalidValue(AbstractPlatform $platform) + public function testConvertToPHPValueWithInvalidValue(AbstractPlatform $platform): void { $this->expectException(ConversionException::class); @@ -97,17 +97,9 @@ class UTCDateTimeTypeTest extends TestCase } /** - * @dataProvider getPlatforms + * @return \Doctrine\DBAL\Platforms\MySQLPlatform[][] */ - public function testRequiresSQLCommentHint(AbstractPlatform $platform) - { - Type::overrideType(Types::DATETIME_MUTABLE, UTCDateTimeType::class); - /** @var UTCDateTimeType $type */ - $type = Type::getType(Types::DATETIME_MUTABLE); - self::assertTrue($type->requiresSQLCommentHint($platform)); - } - - public function getPlatforms() + public function getPlatforms(): array { return [ [new MySQLPlatform()], diff --git a/tests/phpstan.neon b/tests/phpstan.neon index 31540b14..54399fdd 100644 --- a/tests/phpstan.neon +++ b/tests/phpstan.neon @@ -4727,36 +4727,6 @@ parameters: count: 1 path: Doctrine/TimesheetSubscriberTest.php - - - message: "#^Method App\\\\Tests\\\\Doctrine\\\\UTCDateTimeTypeTest\\:\\:getPlatforms\\(\\) has no return type specified\\.$#" - count: 1 - path: Doctrine/UTCDateTimeTypeTest.php - - - - message: "#^Method App\\\\Tests\\\\Doctrine\\\\UTCDateTimeTypeTest\\:\\:testConvertToDatabaseValue\\(\\) has no return type specified\\.$#" - count: 1 - path: Doctrine/UTCDateTimeTypeTest.php - - - - message: "#^Method App\\\\Tests\\\\Doctrine\\\\UTCDateTimeTypeTest\\:\\:testConvertToPHPValue\\(\\) has no return type specified\\.$#" - count: 1 - path: Doctrine/UTCDateTimeTypeTest.php - - - - message: "#^Method App\\\\Tests\\\\Doctrine\\\\UTCDateTimeTypeTest\\:\\:testConvertToPHPValueWithInvalidValue\\(\\) has no return type specified\\.$#" - count: 1 - path: Doctrine/UTCDateTimeTypeTest.php - - - - message: "#^Method App\\\\Tests\\\\Doctrine\\\\UTCDateTimeTypeTest\\:\\:testGetUtc\\(\\) has no return type specified\\.$#" - count: 1 - path: Doctrine/UTCDateTimeTypeTest.php - - - - message: "#^Method App\\\\Tests\\\\Doctrine\\\\UTCDateTimeTypeTest\\:\\:testRequiresSQLCommentHint\\(\\) has no return type specified\\.$#" - count: 1 - path: Doctrine/UTCDateTimeTypeTest.php - - message: "#^Method App\\\\Tests\\\\Entity\\\\AbstractCommentEntityTest\\:\\:testDefaultValues\\(\\) has no return type specified\\.$#" count: 1