From e376d4014c5fd4776285114114adb6f517de63ea Mon Sep 17 00:00:00 2001 From: Buster Neece Date: Tue, 19 Mar 2024 06:53:36 -0500 Subject: [PATCH] Remove type annotations from old DBAL version; remove custom Carbon Immutable format. --- config/services.php | 4 -- src/Entity/Analytics.php | 9 ++-- .../Migration/Version20240319113446.php | 46 +++++++++++++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 src/Entity/Migration/Version20240319113446.php diff --git a/config/services.php b/config/services.php index 1654c8a78..20f56ca9d 100644 --- a/config/services.php +++ b/config/services.php @@ -135,10 +135,6 @@ return [ $config->addCustomNumericFunction('RAND', DoctrineExtensions\Query\Mysql\Rand::class); $config->addCustomStringFunction('FIELD', DoctrineExtensions\Query\Mysql\Field::class); - if (!Doctrine\DBAL\Types\Type::hasType('carbon_immutable')) { - Doctrine\DBAL\Types\Type::addType('carbon_immutable', Carbon\Doctrine\CarbonImmutableType::class); - } - $eventManager = new Doctrine\Common\EventManager(); $eventManager->addEventSubscriber($eventRequiresRestart); $eventManager->addEventSubscriber($eventAuditLog); diff --git a/src/Entity/Analytics.php b/src/Entity/Analytics.php index acd6b44b2..a55ad8fc5 100644 --- a/src/Entity/Analytics.php +++ b/src/Entity/Analytics.php @@ -7,6 +7,7 @@ namespace App\Entity; use App\Entity\Enums\AnalyticsIntervals; use App\Entity\Interfaces\IdentifiableEntityInterface; use Carbon\CarbonImmutable; +use DateTimeImmutable; use DateTimeInterface; use DateTimeZone; use Doctrine\ORM\Mapping as ORM; @@ -32,8 +33,8 @@ class Analytics implements IdentifiableEntityInterface #[ORM\Column(type: 'string', length: 15, enumType: AnalyticsIntervals::class)] protected AnalyticsIntervals $type; - #[ORM\Column(type: 'carbon_immutable')] - protected CarbonImmutable $moment; + #[ORM\Column(type: 'datetime_immutable')] + protected DateTimeImmutable $moment; #[ORM\Column] protected int $number_min; @@ -81,7 +82,7 @@ class Analytics implements IdentifiableEntityInterface public function getMoment(): CarbonImmutable { - return $this->moment; + return CarbonImmutable::instance($this->moment); } public function getMomentInStationTimeZone(): CarbonImmutable @@ -91,7 +92,7 @@ class Analytics implements IdentifiableEntityInterface } $tz = $this->station->getTimezoneObject(); - return CarbonImmutable::parse($this->moment, $tz)->shiftTimezone($tz); + return CarbonImmutable::instance($this->moment)->shiftTimezone($tz); } public function getNumberMin(): int diff --git a/src/Entity/Migration/Version20240319113446.php b/src/Entity/Migration/Version20240319113446.php new file mode 100644 index 000000000..7cedfab1b --- /dev/null +++ b/src/Entity/Migration/Version20240319113446.php @@ -0,0 +1,46 @@ +addSql('ALTER TABLE analytics CHANGE moment moment DATETIME NOT NULL'); + $this->addSql('ALTER TABLE audit_log CHANGE changes changes JSON NOT NULL'); + $this->addSql('ALTER TABLE podcast CHANGE id id CHAR(36) NOT NULL'); + $this->addSql('ALTER TABLE podcast_category CHANGE podcast_id podcast_id CHAR(36) NOT NULL'); + $this->addSql('ALTER TABLE podcast_episode DROP INDEX UNIQ_77EB2BD017421B18, ADD INDEX IDX_77EB2BD017421B18 (playlist_media_id)'); + $this->addSql('ALTER TABLE podcast_episode CHANGE id id CHAR(36) NOT NULL, CHANGE podcast_id podcast_id CHAR(36) NOT NULL'); + $this->addSql('ALTER TABLE podcast_media CHANGE id id CHAR(36) NOT NULL, CHANGE episode_id episode_id CHAR(36) DEFAULT NULL'); + $this->addSql('ALTER TABLE settings CHANGE app_unique_identifier app_unique_identifier CHAR(36) NOT NULL, CHANGE update_results update_results JSON DEFAULT NULL'); + $this->addSql('ALTER TABLE song_history CHANGE delta_points delta_points JSON DEFAULT NULL'); + $this->addSql('ALTER TABLE station CHANGE frontend_config frontend_config JSON DEFAULT NULL, CHANGE backend_config backend_config JSON DEFAULT NULL, CHANGE branding_config branding_config JSON DEFAULT NULL'); + $this->addSql('ALTER TABLE station_webhooks CHANGE triggers triggers JSON DEFAULT NULL, CHANGE config config JSON DEFAULT NULL, CHANGE metadata metadata JSON DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE podcast CHANGE id id CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\''); + $this->addSql('ALTER TABLE song_history CHANGE delta_points delta_points LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json)\''); + $this->addSql('ALTER TABLE podcast_media CHANGE id id CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', CHANGE episode_id episode_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:guid)\''); + $this->addSql('ALTER TABLE audit_log CHANGE changes changes LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\''); + $this->addSql('ALTER TABLE station_webhooks CHANGE triggers triggers LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json)\', CHANGE config config LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json)\', CHANGE metadata metadata LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json)\''); + $this->addSql('ALTER TABLE settings CHANGE app_unique_identifier app_unique_identifier CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', CHANGE update_results update_results LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json)\''); + $this->addSql('ALTER TABLE analytics CHANGE moment moment DATETIME NOT NULL COMMENT \'(DC2Type:carbon_immutable)\''); + $this->addSql('ALTER TABLE podcast_category CHANGE podcast_id podcast_id CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\''); + $this->addSql('ALTER TABLE podcast_episode DROP INDEX IDX_77EB2BD017421B18, ADD UNIQUE INDEX UNIQ_77EB2BD017421B18 (playlist_media_id)'); + $this->addSql('ALTER TABLE podcast_episode CHANGE id id CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', CHANGE podcast_id podcast_id CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\''); + $this->addSql('ALTER TABLE station CHANGE frontend_config frontend_config LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json)\', CHANGE backend_config backend_config LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json)\', CHANGE branding_config branding_config LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:json)\''); + } +}