diff --git a/composer.json b/composer.json
index 8ed288c41..a251d2834 100644
--- a/composer.json
+++ b/composer.json
@@ -89,9 +89,9 @@
"flow/jsonpath": "^0.5",
"mockery/mockery": "^1.0",
"overtrue/phplint": "^1.1",
- "phpstan/phpstan": "^0.11.1",
- "phpstan/phpstan-doctrine": "^0.11.0",
- "phpstan/phpstan-strict-rules": "^0.11.0",
+ "phpstan/phpstan": "^0.12",
+ "phpstan/phpstan-doctrine": "^0.12",
+ "phpstan/phpstan-strict-rules": "^0.12",
"phpunit/php-timer": "^3.1.4",
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "3.*"
diff --git a/composer.lock b/composer.lock
index 5fa009ddb..7dcb249a7 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "30fb1823a2fd210b7eb08ccbe9bab99c",
+ "content-hash": "5ba7e8647fd9f110a7573d7999a5fac1",
"packages": [
{
"name": "aws/aws-sdk-php",
@@ -10141,172 +10141,108 @@
],
"time": "2020-03-05T15:02:03+00:00"
},
- {
- "name": "phpstan/phpdoc-parser",
- "version": "0.3.5",
- "source": {
- "type": "git",
- "url": "https://github.com/phpstan/phpdoc-parser.git",
- "reference": "8c4ef2aefd9788238897b678a985e1d5c8df6db4"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/8c4ef2aefd9788238897b678a985e1d5c8df6db4",
- "reference": "8c4ef2aefd9788238897b678a985e1d5c8df6db4",
- "shasum": ""
- },
- "require": {
- "php": "~7.1"
- },
- "require-dev": {
- "consistence/coding-standard": "^3.5",
- "jakub-onderka/php-parallel-lint": "^0.9.2",
- "phing/phing": "^2.16.0",
- "phpstan/phpstan": "^0.10",
- "phpunit/phpunit": "^6.3",
- "slevomat/coding-standard": "^4.7.2",
- "squizlabs/php_codesniffer": "^3.3.2",
- "symfony/process": "^3.4 || ^4.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "0.3-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "PHPStan\\PhpDocParser\\": [
- "src/"
- ]
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "description": "PHPDoc parser with support for nullable, intersection and generic types",
- "time": "2019-06-07T19:13:52+00:00"
- },
{
"name": "phpstan/phpstan",
- "version": "0.11.19",
+ "version": "0.12.31",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
- "reference": "63cc502f6957b7f74efbac444b4cf219dcadffd7"
+ "reference": "776c8056b401e1b67f277b9e9fb334d1a274671d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan/zipball/63cc502f6957b7f74efbac444b4cf219dcadffd7",
- "reference": "63cc502f6957b7f74efbac444b4cf219dcadffd7",
+ "url": "https://api.github.com/repos/phpstan/phpstan/zipball/776c8056b401e1b67f277b9e9fb334d1a274671d",
+ "reference": "776c8056b401e1b67f277b9e9fb334d1a274671d",
"shasum": ""
},
"require": {
- "composer/xdebug-handler": "^1.3.0",
- "jean85/pretty-package-versions": "^1.0.3",
- "nette/bootstrap": "^2.4 || ^3.0",
- "nette/di": "^2.4.7 || ^3.0",
- "nette/neon": "^2.4.3 || ^3.0",
- "nette/robot-loader": "^3.0.1",
- "nette/schema": "^1.0",
- "nette/utils": "^2.4.5 || ^3.0",
- "nikic/php-parser": "^4.2.3",
- "php": "~7.1",
- "phpstan/phpdoc-parser": "^0.3.5",
- "symfony/console": "~3.2 || ~4.0",
- "symfony/finder": "~3.2 || ~4.0"
+ "php": "^7.1"
},
"conflict": {
- "symfony/console": "3.4.16 || 4.1.5"
- },
- "require-dev": {
- "brianium/paratest": "^2.0 || ^3.0",
- "consistence/coding-standard": "^3.5",
- "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
- "ext-intl": "*",
- "ext-mysqli": "*",
- "ext-simplexml": "*",
- "ext-soap": "*",
- "ext-zip": "*",
- "jakub-onderka/php-parallel-lint": "^1.0",
- "localheinz/composer-normalize": "^1.1.0",
- "phing/phing": "^2.16.0",
- "phpstan/phpstan-deprecation-rules": "^0.11",
- "phpstan/phpstan-php-parser": "^0.11",
- "phpstan/phpstan-phpunit": "^0.11",
- "phpstan/phpstan-strict-rules": "^0.11",
- "phpunit/phpunit": "^7.5.14 || ^8.0",
- "slevomat/coding-standard": "^4.7.2",
- "squizlabs/php_codesniffer": "^3.3.2"
+ "phpstan/phpstan-shim": "*"
},
"bin": [
- "bin/phpstan"
+ "phpstan",
+ "phpstan.phar"
],
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "0.11-dev"
+ "dev-master": "0.12-dev"
}
},
"autoload": {
- "psr-4": {
- "PHPStan\\": [
- "src/"
- ]
- }
+ "files": [
+ "bootstrap.php"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
- "time": "2019-10-22T20:20:22+00:00"
+ "funding": [
+ {
+ "url": "https://github.com/ondrejmirtes",
+ "type": "github"
+ },
+ {
+ "url": "https://www.patreon.com/phpstan",
+ "type": "patreon"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2020-06-24T20:55:29+00:00"
},
{
"name": "phpstan/phpstan-doctrine",
- "version": "0.11.6",
+ "version": "0.12.17",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-doctrine.git",
- "reference": "77592865e167b32c7dcb4f39a35210e909a8854c"
+ "reference": "5eed42b2815f100f25bd45fe8c1a9b01f3e41657"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/77592865e167b32c7dcb4f39a35210e909a8854c",
- "reference": "77592865e167b32c7dcb4f39a35210e909a8854c",
+ "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/5eed42b2815f100f25bd45fe8c1a9b01f3e41657",
+ "reference": "5eed42b2815f100f25bd45fe8c1a9b01f3e41657",
"shasum": ""
},
"require": {
- "nikic/php-parser": "^4.0",
"php": "~7.1",
- "phpstan/phpdoc-parser": "^0.3",
- "phpstan/phpstan": "^0.11.7"
+ "phpstan/phpstan": "^0.12.26"
},
"conflict": {
"doctrine/collections": "<1.0",
"doctrine/common": "<2.7",
"doctrine/mongodb-odm": "<1.2",
- "doctrine/orm": "<2.5"
+ "doctrine/orm": "<2.5",
+ "doctrine/persistence": "<1.3"
},
"require-dev": {
- "consistence/coding-standard": "^3.8",
+ "consistence/coding-standard": "^3.0.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
"doctrine/collections": "^1.0",
- "doctrine/common": "^2.7",
- "doctrine/mongodb-odm": "^1.2",
+ "doctrine/common": "^2.7 || ^3.0",
+ "doctrine/mongodb-odm": "^1.3 || ^2.1",
"doctrine/orm": "^2.5",
+ "doctrine/persistence": "^1.1 || ^2.0",
+ "ergebnis/composer-normalize": "^2.0.2",
"jakub-onderka/php-parallel-lint": "^1.0",
"phing/phing": "^2.16.0",
- "phpstan/phpstan-phpunit": "^0.11",
- "phpstan/phpstan-strict-rules": "^0.11",
+ "phpstan/phpstan-phpunit": "^0.12",
+ "phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^7.0",
- "slevomat/coding-standard": "^5.0.4"
+ "ramsey/uuid-doctrine": "^1.5.0",
+ "slevomat/coding-standard": "^4.5.2"
},
"type": "phpstan-extension",
"extra": {
"branch-alias": {
- "dev-master": "0.11-dev"
+ "dev-master": "0.12-dev"
},
"phpstan": {
"includes": [
@@ -10325,40 +10261,40 @@
"MIT"
],
"description": "Doctrine extensions for PHPStan",
- "time": "2019-09-13T08:40:06+00:00"
+ "time": "2020-06-23T08:50:27+00:00"
},
{
"name": "phpstan/phpstan-strict-rules",
- "version": "0.11.1",
+ "version": "0.12.2",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-strict-rules.git",
- "reference": "a203a7afdda073d4ea405a6d9007a5b32de3be61"
+ "reference": "a670a59aff7cf96f75d21b974860ada10e25b2ee"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/a203a7afdda073d4ea405a6d9007a5b32de3be61",
- "reference": "a203a7afdda073d4ea405a6d9007a5b32de3be61",
+ "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/a670a59aff7cf96f75d21b974860ada10e25b2ee",
+ "reference": "a670a59aff7cf96f75d21b974860ada10e25b2ee",
"shasum": ""
},
"require": {
- "nikic/php-parser": "^4.0",
"php": "~7.1",
- "phpstan/phpstan": "^0.11.4"
+ "phpstan/phpstan": "^0.12.6"
},
"require-dev": {
"consistence/coding-standard": "^3.0.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
+ "ergebnis/composer-normalize": "^2.0.2",
"jakub-onderka/php-parallel-lint": "^1.0",
"phing/phing": "^2.16.0",
- "phpstan/phpstan-phpunit": "^0.11",
+ "phpstan/phpstan-phpunit": "^0.12",
"phpunit/phpunit": "^7.0",
"slevomat/coding-standard": "^4.5.2"
},
"type": "phpstan-extension",
"extra": {
"branch-alias": {
- "dev-master": "0.11-dev"
+ "dev-master": "0.12-dev"
},
"phpstan": {
"includes": [
@@ -10376,7 +10312,7 @@
"MIT"
],
"description": "Extra strict and opinionated rules for PHPStan",
- "time": "2019-05-12T16:59:47+00:00"
+ "time": "2020-01-20T13:08:52+00:00"
},
{
"name": "phpunit/php-code-coverage",
diff --git a/config/events.php b/config/events.php
index 9e2a27dd8..1217f06a0 100644
--- a/config/events.php
+++ b/config/events.php
@@ -23,8 +23,8 @@ return function (\App\EventDispatcher $dispatcher) {
Doctrine\ORM\Tools\Console\ConsoleRunner::addCommands($console);
// Add Doctrine Migrations
- /** @var Doctrine\ORM\EntityManager $em */
- $em = $di->get(Doctrine\ORM\EntityManager::class);
+ /** @var Doctrine\ORM\EntityManagerInterface $em */
+ $em = $di->get(Doctrine\ORM\EntityManagerInterface::class);
$helper_set = $console->getHelperSet();
$doctrine_helpers = Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($em);
@@ -73,6 +73,9 @@ return function (\App\EventDispatcher $dispatcher) {
$app->add(Middleware\InjectRouter::class);
$app->add(Middleware\InjectRateLimit::class);
+ // Re-establish database connection if multiple requests are handled by the same stack.
+ $app->add(Middleware\ReopenEntityManagerMiddleware::class);
+
// System middleware for routing and body parsing.
$app->addBodyParsingMiddleware();
$app->addRoutingMiddleware();
diff --git a/config/services.php b/config/services.php
index c0c03bde4..c793ccace 100644
--- a/config/services.php
+++ b/config/services.php
@@ -4,7 +4,6 @@
*/
use App\Settings;
-use Doctrine\ORM\EntityManager;
use Psr\Container\ContainerInterface;
return [
@@ -49,13 +48,12 @@ return [
},
// DBAL
- Doctrine\DBAL\Connection::class => function (Doctrine\ORM\EntityManager $em) {
+ Doctrine\DBAL\Connection::class => function (Doctrine\ORM\EntityManagerInterface $em) {
return $em->getConnection();
},
- 'db' => DI\Get(Doctrine\DBAL\Connection::class),
// Doctrine Entity Manager
- Doctrine\ORM\EntityManager::class => function (
+ App\Doctrine\DecoratedEntityManager::class => function (
Doctrine\Common\Cache\Cache $doctrineCache,
Doctrine\Common\Annotations\Reader $reader,
App\Settings $settings,
@@ -112,12 +110,18 @@ return [
$eventManager->addEventSubscriber($eventRequiresRestart);
$eventManager->addEventSubscriber($eventAuditLog);
- return Doctrine\ORM\EntityManager::create($connectionOptions, $config, $eventManager);
+ return new App\Doctrine\DecoratedEntityManager(function () use (
+ $connectionOptions,
+ $config,
+ $eventManager
+ ) {
+ return Doctrine\ORM\EntityManager::create($connectionOptions, $config, $eventManager);
+ });
} catch (Exception $e) {
throw new App\Exception\BootstrapException($e->getMessage());
}
},
- 'em' => DI\Get(Doctrine\ORM\EntityManager::class),
+ Doctrine\ORM\EntityManagerInterface::class => DI\Get(App\Doctrine\DecoratedEntityManager::class),
// Cache
Psr\Cache\CacheItemPoolInterface::class => function (App\Settings $settings, Psr\Container\ContainerInterface $di) {
@@ -284,7 +288,7 @@ return [
// Symfony Serializer
Symfony\Component\Serializer\Serializer::class => function (
Doctrine\Common\Annotations\Reader $annotation_reader,
- Doctrine\ORM\EntityManager $em
+ Doctrine\ORM\EntityManagerInterface $em
) {
$meta_factory = new Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory(
new Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader($annotation_reader)
@@ -316,7 +320,7 @@ return [
Redis $redis,
ContainerInterface $di,
Monolog\Logger $logger,
- EntityManager $em
+ Doctrine\ORM\EntityManagerInterface $em
) {
// Build QueueFactory
$driver = new Bernard\Driver\PhpRedis\Driver($redis);
diff --git a/phpstan.neon b/phpstan.neon
index 3d046950d..3d06287c6 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -4,7 +4,8 @@ parameters:
paths:
- src
- bootstrap: %rootDir%/../../../util/phpstan.php
+ bootstrapFiles:
+ - %rootDir%/../../../util/phpstan.php
universalObjectCratesClasses:
- App\Session\NamespaceInterface
diff --git a/src/ApiUtilities.php b/src/ApiUtilities.php
index 0aa3221a6..b386a9188 100644
--- a/src/ApiUtilities.php
+++ b/src/ApiUtilities.php
@@ -3,7 +3,7 @@ namespace App;
use App\Entity\Station;
use App\Http\Router;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use GuzzleHttp\Psr7\UriResolver;
use Psr\Http\Message\UriInterface;
@@ -13,13 +13,13 @@ use Psr\Http\Message\UriInterface;
*/
class ApiUtilities
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Router $router;
protected Customization $customization;
- public function __construct(EntityManager $em, Router $router, Customization $customization)
+ public function __construct(EntityManagerInterface $em, Router $router, Customization $customization)
{
$this->em = $em;
$this->router = $router;
diff --git a/src/Auth.php b/src/Auth.php
index 96cea9071..46d6fcb38 100644
--- a/src/Auth.php
+++ b/src/Auth.php
@@ -4,7 +4,6 @@ namespace App;
use App\Entity\Repository\UserRepository;
use App\Entity\User;
use App\Exception\NotLoggedInException;
-use App\Exception;
use Mezzio\Session\SessionInterface;
class Auth
@@ -170,7 +169,7 @@ class Auth
}
return ($this->user instanceof User)
- ? $this->user
+ ? $this->userRepo->getRepository()->find($this->user->getId())
: null;
}
diff --git a/src/Console/Command/BackupCommand.php b/src/Console/Command/BackupCommand.php
index 24c4d37e6..08dae2ec3 100644
--- a/src/Console/Command/BackupCommand.php
+++ b/src/Console/Command/BackupCommand.php
@@ -4,8 +4,7 @@ namespace App\Console\Command;
use App\Entity;
use App\Sync\Task\Backup;
use App\Utilities;
-use App\Console\Command\CommandAbstract;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use InfluxDB\Database;
use Symfony\Component\Console\Style\SymfonyStyle;
use const PATHINFO_EXTENSION;
@@ -16,7 +15,7 @@ class BackupCommand extends CommandAbstract
public function __invoke(
SymfonyStyle $io,
- EntityManager $em,
+ EntityManagerInterface $em,
Database $influxdb,
?string $path = '',
bool $excludeMedia = false
diff --git a/src/Console/Command/Internal/DjAuthCommand.php b/src/Console/Command/Internal/DjAuthCommand.php
index 6f5c9c4cf..253240322 100644
--- a/src/Console/Command/Internal/DjAuthCommand.php
+++ b/src/Console/Command/Internal/DjAuthCommand.php
@@ -1,18 +1,18 @@
title('AzuraCast User Accounts');
diff --git a/src/Console/Command/ReprocessMediaCommand.php b/src/Console/Command/ReprocessMediaCommand.php
index 052480a90..a1339d99f 100644
--- a/src/Console/Command/ReprocessMediaCommand.php
+++ b/src/Console/Command/ReprocessMediaCommand.php
@@ -4,8 +4,7 @@ namespace App\Console\Command;
use App\Entity;
use App\Entity\Repository\StationRepository;
use App\Entity\Station;
-use App\Console\Command\CommandAbstract;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -13,7 +12,7 @@ class ReprocessMediaCommand extends CommandAbstract
{
public function __invoke(
SymfonyStyle $io,
- EntityManager $em,
+ EntityManagerInterface $em,
StationRepository $stationRepo,
Entity\Repository\StationMediaRepository $media_repo,
?string $stationName = null
diff --git a/src/Console/Command/ResetPasswordCommand.php b/src/Console/Command/ResetPasswordCommand.php
index 0a87a951b..93e90831e 100644
--- a/src/Console/Command/ResetPasswordCommand.php
+++ b/src/Console/Command/ResetPasswordCommand.php
@@ -3,15 +3,14 @@ namespace App\Console\Command;
use App\Entity;
use App\Utilities;
-use App\Console\Command\CommandAbstract;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class ResetPasswordCommand extends CommandAbstract
{
public function __invoke(
SymfonyStyle $io,
- EntityManager $em,
+ EntityManagerInterface $em,
string $email
) {
$io->title('Reset Account Password');
diff --git a/src/Console/Command/RestartRadioCommand.php b/src/Console/Command/RestartRadioCommand.php
index 5b7039b54..fe53be24e 100644
--- a/src/Console/Command/RestartRadioCommand.php
+++ b/src/Console/Command/RestartRadioCommand.php
@@ -4,14 +4,14 @@ namespace App\Console\Command;
use App\Entity\Repository\StationRepository;
use App\Entity\Station;
use App\Radio\Configuration;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class RestartRadioCommand extends CommandAbstract
{
public function __invoke(
SymfonyStyle $io,
- EntityManager $em,
+ EntityManagerInterface $em,
StationRepository $stationRepo,
Configuration $configuration,
?string $stationName = null
diff --git a/src/Console/Command/RestoreCommand.php b/src/Console/Command/RestoreCommand.php
index 740ae7b53..3404a6445 100644
--- a/src/Console/Command/RestoreCommand.php
+++ b/src/Console/Command/RestoreCommand.php
@@ -3,7 +3,7 @@ namespace App\Console\Command;
use App\Sync\Task\Backup;
use App\Utilities;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use InfluxDB\Database;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -16,7 +16,7 @@ class RestoreCommand extends CommandAbstract
public function __invoke(
SymfonyStyle $io,
OutputInterface $output,
- EntityManager $em,
+ EntityManagerInterface $em,
Database $influxdb,
string $path
) {
diff --git a/src/Console/Command/SetAdministratorCommand.php b/src/Console/Command/SetAdministratorCommand.php
index eaad7c359..9337e4815 100644
--- a/src/Console/Command/SetAdministratorCommand.php
+++ b/src/Console/Command/SetAdministratorCommand.php
@@ -3,15 +3,14 @@ namespace App\Console\Command;
use App\Acl;
use App\Entity;
-use App\Console\Command\CommandAbstract;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class SetAdministratorCommand extends CommandAbstract
{
public function __invoke(
SymfonyStyle $io,
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\RolePermissionRepository $perms_repo,
string $email
) {
diff --git a/src/Console/Command/SetupFixturesCommand.php b/src/Console/Command/SetupFixturesCommand.php
index 1b110d876..2194268cc 100644
--- a/src/Console/Command/SetupFixturesCommand.php
+++ b/src/Console/Command/SetupFixturesCommand.php
@@ -3,12 +3,11 @@ namespace App\Console\Command;
use App\Entity\Station;
use App\Settings;
-use App\Console\Command\CommandAbstract;
use Cake\Chronos\Chronos;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use InfluxDB\Database;
use InfluxDB\Point;
use Psr\Container\ContainerInterface;
@@ -20,7 +19,7 @@ class SetupFixturesCommand extends CommandAbstract
{
public function __invoke(
SymfonyStyle $io,
- EntityManager $em,
+ EntityManagerInterface $em,
ContainerInterface $di,
Database $influx,
Settings $settings
diff --git a/src/Controller/Admin/AbstractAdminCrudController.php b/src/Controller/Admin/AbstractAdminCrudController.php
index d740ffcfc..8526f44d7 100644
--- a/src/Controller/Admin/AbstractAdminCrudController.php
+++ b/src/Controller/Admin/AbstractAdminCrudController.php
@@ -4,14 +4,14 @@ namespace App\Controller\Admin;
use App\Exception\NotFoundException;
use App\Form\EntityForm;
use App\Http\ServerRequest;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
abstract class AbstractAdminCrudController
{
protected EntityForm $form;
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected string $entity_class;
diff --git a/src/Controller/Admin/DebugController.php b/src/Controller/Admin/DebugController.php
index 2c7df33bc..b9bff53de 100644
--- a/src/Controller/Admin/DebugController.php
+++ b/src/Controller/Admin/DebugController.php
@@ -7,7 +7,7 @@ use App\Http\ServerRequest;
use App\Radio\AutoDJ;
use App\Radio\Backend\Liquidsoap;
use App\Sync\Runner;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
use Psr\Http\Message\ResponseInterface;
@@ -75,7 +75,7 @@ class DebugController
public function nextsongAction(
ServerRequest $request,
Response $response,
- EntityManager $em,
+ EntityManagerInterface $em,
AutoDJ $autoDJ
): ResponseInterface {
$this->logger->pushHandler($this->testHandler);
@@ -92,7 +92,7 @@ class DebugController
$this->logger->debug('Current queue cleared.');
$autoDJ->buildQueue($station);
-
+
$this->logger->popHandler();
return $request->getView()->renderToResponse($response, 'system/log_view', [
diff --git a/src/Controller/Admin/LogsController.php b/src/Controller/Admin/LogsController.php
index 12ff24e4a..c9b641858 100644
--- a/src/Controller/Admin/LogsController.php
+++ b/src/Controller/Admin/LogsController.php
@@ -7,14 +7,14 @@ use App\Exception;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Settings;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class LogsController extends AbstractLogViewerController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
- public function __construct(EntityManager $em)
+ public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
diff --git a/src/Controller/Admin/RelaysController.php b/src/Controller/Admin/RelaysController.php
index f293b6dc1..0a3203659 100644
--- a/src/Controller/Admin/RelaysController.php
+++ b/src/Controller/Admin/RelaysController.php
@@ -4,14 +4,14 @@ namespace App\Controller\Admin;
use App\Entity;
use App\Http\Response;
use App\Http\ServerRequest;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class RelaysController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
- public function __construct(EntityManager $em)
+ public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
diff --git a/src/Controller/Api/AbstractApiCrudController.php b/src/Controller/Api/AbstractApiCrudController.php
index 3b0222066..b32d476b1 100644
--- a/src/Controller/Api/AbstractApiCrudController.php
+++ b/src/Controller/Api/AbstractApiCrudController.php
@@ -6,7 +6,7 @@ use App\Exception\ValidationException;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Utilities;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Query;
@@ -18,7 +18,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
abstract class AbstractApiCrudController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Serializer $serializer;
@@ -30,7 +30,7 @@ abstract class AbstractApiCrudController
/** @var string The route name used to generate the "self" links for each record. */
protected string $resourceRouteName;
- public function __construct(EntityManager $em, Serializer $serializer, ValidatorInterface $validator)
+ public function __construct(EntityManagerInterface $em, Serializer $serializer, ValidatorInterface $validator)
{
$this->em = $em;
$this->serializer = $serializer;
diff --git a/src/Controller/Api/Admin/AuditLogController.php b/src/Controller/Api/Admin/AuditLogController.php
index 5fc45dc9b..1be637970 100644
--- a/src/Controller/Api/Admin/AuditLogController.php
+++ b/src/Controller/Api/Admin/AuditLogController.php
@@ -1,21 +1,21 @@
em = $em;
}
diff --git a/src/Controller/Api/Admin/RelaysController.php b/src/Controller/Api/Admin/RelaysController.php
index 60c7a8b5f..2725dd06b 100644
--- a/src/Controller/Api/Admin/RelaysController.php
+++ b/src/Controller/Api/Admin/RelaysController.php
@@ -6,18 +6,18 @@ use App\Entity;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Radio\Adapters;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
class RelaysController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Adapters $adapters;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Adapters $adapters
) {
$this->em = $em;
diff --git a/src/Controller/Api/Admin/SettingsController.php b/src/Controller/Api/Admin/SettingsController.php
index d678cd208..d10eadad6 100644
--- a/src/Controller/Api/Admin/SettingsController.php
+++ b/src/Controller/Api/Admin/SettingsController.php
@@ -5,7 +5,7 @@ use App\Entity;
use App\Exception\ValidationException;
use App\Http\Response;
use App\Http\ServerRequest;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
@@ -14,7 +14,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
class SettingsController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Serializer $serializer;
@@ -25,7 +25,7 @@ class SettingsController
protected Entity\Api\Admin\Settings $api_settings;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settings_repo,
Serializer $serializer,
ValidatorInterface $validator
diff --git a/src/Controller/Api/Admin/StationsController.php b/src/Controller/Api/Admin/StationsController.php
index f2d8b38d9..7ee312688 100644
--- a/src/Controller/Api/Admin/StationsController.php
+++ b/src/Controller/Api/Admin/StationsController.php
@@ -4,7 +4,7 @@ namespace App\Controller\Api\Admin;
use App\Entity;
use App\Exception\ValidationException;
use App\Normalizer\DoctrineEntityNormalizer;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use OpenApi\Annotations as OA;
use Symfony\Component\Serializer\Serializer;
@@ -18,7 +18,7 @@ class StationsController extends AbstractAdminApiCrudController
protected Entity\Repository\StationRepository $station_repo;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Serializer $serializer,
ValidatorInterface $validator,
Entity\Repository\StationRepository $station_repo
diff --git a/src/Controller/Api/NowplayingController.php b/src/Controller/Api/NowplayingController.php
index a7c7adfba..e7dddb0f6 100644
--- a/src/Controller/Api/NowplayingController.php
+++ b/src/Controller/Api/NowplayingController.php
@@ -6,7 +6,7 @@ use App\Event\Radio\LoadNowPlaying;
use App\EventDispatcher;
use App\Http\Response;
use App\Http\ServerRequest;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
use Psr\SimpleCache\CacheInterface;
@@ -14,7 +14,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class NowplayingController implements EventSubscriberInterface
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Entity\Repository\SettingsRepository $settingsRepo;
@@ -23,7 +23,7 @@ class NowplayingController implements EventSubscriberInterface
protected EventDispatcher $dispatcher;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
CacheInterface $cache,
EventDispatcher $dispatcher
diff --git a/src/Controller/Api/Stations/AbstractScheduledEntityController.php b/src/Controller/Api/Stations/AbstractScheduledEntityController.php
index a4c8817c1..51585d7e6 100644
--- a/src/Controller/Api/Stations/AbstractScheduledEntityController.php
+++ b/src/Controller/Api/Stations/AbstractScheduledEntityController.php
@@ -5,7 +5,7 @@ use App\Entity;
use App\Http\Response;
use App\Http\ServerRequest;
use Cake\Chronos\Chronos;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Validator\Validator\ValidatorInterface;
@@ -15,7 +15,7 @@ abstract class AbstractScheduledEntityController extends AbstractStationApiCrudC
protected Entity\Repository\StationScheduleRepository $scheduleRepo;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Serializer $serializer,
ValidatorInterface $validator,
Entity\Repository\StationScheduleRepository $scheduleRepo
diff --git a/src/Controller/Api/Stations/Files/BatchAction.php b/src/Controller/Api/Stations/Files/BatchAction.php
index 595e14ad0..5cd5912b6 100644
--- a/src/Controller/Api/Stations/Files/BatchAction.php
+++ b/src/Controller/Api/Stations/Files/BatchAction.php
@@ -9,7 +9,7 @@ use App\Http\ServerRequest;
use App\Message\WritePlaylistFileMessage;
use App\MessageQueue;
use App\Radio\Backend\Liquidsoap;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Psr\Http\Message\ResponseInterface;
@@ -18,7 +18,7 @@ class BatchAction
public function __invoke(
ServerRequest $request,
Response $response,
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\StationMediaRepository $mediaRepo,
Entity\Repository\StationPlaylistMediaRepository $playlistMediaRepo,
Entity\Repository\StationPlaylistFolderRepository $playlistFolderRepo,
@@ -55,7 +55,7 @@ class BatchAction
$music_files = $this->getMusicFiles($fs, $files);
$files_found = count($music_files);
- /** @var Entity\StationPlaylist[] $playlists */
+ /** @var Entity\StationPlaylist[] $affected_playlists */
$affected_playlists = [];
foreach ($music_files as $file) {
diff --git a/src/Controller/Api/Stations/Files/FlowUploadAction.php b/src/Controller/Api/Stations/Files/FlowUploadAction.php
index a3ce7b066..f9243c5c9 100644
--- a/src/Controller/Api/Stations/Files/FlowUploadAction.php
+++ b/src/Controller/Api/Stations/Files/FlowUploadAction.php
@@ -5,7 +5,7 @@ use App\Entity;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Service\Flow;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Error;
use Exception;
use Psr\Http\Message\ResponseInterface;
@@ -15,7 +15,7 @@ class FlowUploadAction
public function __invoke(
ServerRequest $request,
Response $response,
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\StationMediaRepository $mediaRepo,
Entity\Repository\StationPlaylistMediaRepository $spmRepo
): ResponseInterface {
diff --git a/src/Controller/Api/Stations/Files/ListAction.php b/src/Controller/Api/Stations/Files/ListAction.php
index 0bcc0f2ab..1f51b1ce4 100644
--- a/src/Controller/Api/Stations/Files/ListAction.php
+++ b/src/Controller/Api/Stations/Files/ListAction.php
@@ -7,7 +7,7 @@ use App\Flysystem\Filesystem;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Utilities;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
use const SORT_ASC;
use const SORT_DESC;
@@ -17,7 +17,7 @@ class ListAction
public function __invoke(
ServerRequest $request,
Response $response,
- EntityManager $em,
+ EntityManagerInterface $em,
Filesystem $filesystem,
Customization $customization
): ResponseInterface {
diff --git a/src/Controller/Api/Stations/Files/RenameAction.php b/src/Controller/Api/Stations/Files/RenameAction.php
index 3f91dbde7..977cbe0bd 100644
--- a/src/Controller/Api/Stations/Files/RenameAction.php
+++ b/src/Controller/Api/Stations/Files/RenameAction.php
@@ -5,7 +5,7 @@ use App\Entity;
use App\Flysystem\Filesystem;
use App\Http\Response;
use App\Http\ServerRequest;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class RenameAction
@@ -14,7 +14,7 @@ class RenameAction
ServerRequest $request,
Response $response,
Filesystem $filesystem,
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\StationMediaRepository $mediaRepo
): ResponseInterface {
$originalPath = $request->getAttribute('file');
diff --git a/src/Controller/Api/Stations/FilesController.php b/src/Controller/Api/Stations/FilesController.php
index c066ddeca..5e99a2803 100644
--- a/src/Controller/Api/Stations/FilesController.php
+++ b/src/Controller/Api/Stations/FilesController.php
@@ -10,7 +10,7 @@ use App\Message\WritePlaylistFileMessage;
use App\MessageQueue;
use App\Radio\Adapters;
use App\Radio\Backend\Liquidsoap;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
@@ -38,7 +38,7 @@ class FilesController extends AbstractStationApiCrudController
protected Entity\Repository\StationPlaylistMediaRepository $playlist_media_repo;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Serializer $serializer,
ValidatorInterface $validator,
Filesystem $filesystem,
@@ -271,7 +271,7 @@ class FilesController extends AbstractStationApiCrudController
if (null !== $playlists) {
$station = $record->getStation();
- /** @var Entity\StationPlaylist[] $playlists */
+ /** @var Entity\StationPlaylist[] $affected_playlists */
$affected_playlists = [];
// Remove existing playlists.
@@ -288,13 +288,13 @@ class FilesController extends AbstractStationApiCrudController
$playlist_id = $new_playlist['id'];
$playlist_weight = $new_playlist['weight'] ?? 0;
} else {
- $playlist_id = $new_playlist;
+ $playlist_id = (int)$new_playlist;
$playlist_weight = 0;
}
$playlist = $this->em->getRepository(Entity\StationPlaylist::class)->findOneBy([
'station_id' => $station->getId(),
- 'id' => (int)$playlist_id,
+ 'id' => $playlist_id,
]);
if ($playlist instanceof Entity\StationPlaylist) {
@@ -330,7 +330,7 @@ class FilesController extends AbstractStationApiCrudController
$station = $record->getStation();
- /** @var Entity\StationPlaylist[] $playlists */
+ /** @var Entity\StationPlaylist[] $affected_playlists */
$affected_playlists = [];
$media_playlists = $this->playlist_media_repo->clearPlaylistsFromMedia($record);
diff --git a/src/Controller/Api/Stations/HistoryController.php b/src/Controller/Api/Stations/HistoryController.php
index db101133a..0ea605d06 100644
--- a/src/Controller/Api/Stations/HistoryController.php
+++ b/src/Controller/Api/Stations/HistoryController.php
@@ -9,17 +9,17 @@ use App\Http\ServerRequest;
use App\Utilities\Csv;
use Cake\Chronos\Chronos;
use DateTimeZone;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
class HistoryController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected App\ApiUtilities $api_utils;
- public function __construct(EntityManager $em, App\ApiUtilities $api_utils)
+ public function __construct(EntityManagerInterface $em, App\ApiUtilities $api_utils)
{
$this->em = $em;
$this->api_utils = $api_utils;
diff --git a/src/Controller/Api/Stations/IndexController.php b/src/Controller/Api/Stations/IndexController.php
index e4e77fb12..3e32289f6 100644
--- a/src/Controller/Api/Stations/IndexController.php
+++ b/src/Controller/Api/Stations/IndexController.php
@@ -7,17 +7,17 @@ use App\Exception\NotFoundException;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Radio\Adapters;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
class IndexController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Adapters $adapters;
- public function __construct(EntityManager $em, Adapters $adapters)
+ public function __construct(EntityManagerInterface $em, Adapters $adapters)
{
$this->em = $em;
$this->adapters = $adapters;
diff --git a/src/Controller/Api/Stations/ListenersController.php b/src/Controller/Api/Stations/ListenersController.php
index 367581289..ec61e8075 100644
--- a/src/Controller/Api/Stations/ListenersController.php
+++ b/src/Controller/Api/Stations/ListenersController.php
@@ -8,18 +8,18 @@ use App\Service\IpGeolocation;
use App\Utilities\Csv;
use Cake\Chronos\Chronos;
use DateTimeZone;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Mobile_Detect;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
class ListenersController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected IpGeolocation $geoLite;
- public function __construct(EntityManager $em, IpGeolocation $geoLite)
+ public function __construct(EntityManagerInterface $em, IpGeolocation $geoLite)
{
$this->em = $em;
$this->geoLite = $geoLite;
diff --git a/src/Controller/Api/Stations/OnDemand/ListAction.php b/src/Controller/Api/Stations/OnDemand/ListAction.php
index 26ae141c0..2da6bef56 100644
--- a/src/Controller/Api/Stations/OnDemand/ListAction.php
+++ b/src/Controller/Api/Stations/OnDemand/ListAction.php
@@ -7,7 +7,7 @@ use App\Entity;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Utilities;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class ListAction
@@ -15,7 +15,7 @@ class ListAction
public function __invoke(
ServerRequest $request,
Response $response,
- EntityManager $em,
+ EntityManagerInterface $em,
ApiUtilities $apiUtils
): ResponseInterface {
$station = $request->getStation();
diff --git a/src/Controller/Api/Stations/QueueController.php b/src/Controller/Api/Stations/QueueController.php
index 1c7423e38..3c1bd358c 100644
--- a/src/Controller/Api/Stations/QueueController.php
+++ b/src/Controller/Api/Stations/QueueController.php
@@ -5,7 +5,7 @@ use App;
use App\Entity;
use App\Http\Response;
use App\Http\ServerRequest;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
@@ -20,7 +20,7 @@ class QueueController extends AbstractStationApiCrudController
protected App\ApiUtilities $apiUtils;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Serializer $serializer,
ValidatorInterface $validator,
App\ApiUtilities $apiUtils
diff --git a/src/Controller/Api/Stations/RequestsController.php b/src/Controller/Api/Stations/RequestsController.php
index 4a9818c79..b8018c576 100644
--- a/src/Controller/Api/Stations/RequestsController.php
+++ b/src/Controller/Api/Stations/RequestsController.php
@@ -8,20 +8,20 @@ use App\Exception;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Utilities;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
class RequestsController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Entity\Repository\StationRequestRepository $requestRepo;
protected ApiUtilities $api_utils;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\StationRequestRepository $requestRepo,
ApiUtilities $api_utils
) {
@@ -163,7 +163,7 @@ class RequestsController
} catch (Exception\InvalidRequestAttribute $e) {
$user = null;
}
-
+
$isAuthenticated = ($user instanceof Entity\User);
try {
diff --git a/src/Controller/Api/Stations/ScheduleController.php b/src/Controller/Api/Stations/ScheduleController.php
index 6fab89a6a..a1d82c0e8 100644
--- a/src/Controller/Api/Stations/ScheduleController.php
+++ b/src/Controller/Api/Stations/ScheduleController.php
@@ -5,7 +5,7 @@ use App\Entity\Repository\StationScheduleRepository;
use App\Http\Response;
use App\Http\ServerRequest;
use Cake\Chronos\Chronos;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
use Psr\SimpleCache\CacheInterface;
@@ -42,7 +42,7 @@ class ScheduleController extends AbstractStationApiCrudController
*
* @param ServerRequest $request
* @param Response $response
- * @param EntityManager $em
+ * @param EntityManagerInterface $em
* @param CacheInterface $cache
* @param StationScheduleRepository $scheduleRepo
*
@@ -51,7 +51,7 @@ class ScheduleController extends AbstractStationApiCrudController
public function __invoke(
ServerRequest $request,
Response $response,
- EntityManager $em,
+ EntityManagerInterface $em,
CacheInterface $cache,
StationScheduleRepository $scheduleRepo
): ResponseInterface {
diff --git a/src/Controller/Api/Stations/ServicesController.php b/src/Controller/Api/Stations/ServicesController.php
index 18121c652..5246c5cca 100644
--- a/src/Controller/Api/Stations/ServicesController.php
+++ b/src/Controller/Api/Stations/ServicesController.php
@@ -8,17 +8,17 @@ use App\Http\ServerRequest;
use App\Radio\AutoDJ;
use App\Radio\Backend\Liquidsoap;
use App\Radio\Configuration;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
class ServicesController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Configuration $configuration;
- public function __construct(EntityManager $em, Configuration $configuration)
+ public function __construct(EntityManagerInterface $em, Configuration $configuration)
{
$this->em = $em;
$this->configuration = $configuration;
diff --git a/src/Controller/Frontend/Account/LoginAction.php b/src/Controller/Frontend/Account/LoginAction.php
index c2bf87964..2d272a787 100644
--- a/src/Controller/Frontend/Account/LoginAction.php
+++ b/src/Controller/Frontend/Account/LoginAction.php
@@ -11,7 +11,7 @@ use App\Http\Response;
use App\Http\ServerRequest;
use App\RateLimit;
use App\Session\Flash;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class LoginAction
@@ -21,7 +21,7 @@ class LoginAction
Response $response,
Acl $acl,
Auth $auth,
- EntityManager $em,
+ EntityManagerInterface $em,
RateLimit $rateLimit,
SettingsRepository $settingsRepo
): ResponseInterface {
@@ -65,7 +65,7 @@ class LoginAction
if (!$auth->isLoginComplete()) {
return $response->withRedirect($request->getRouter()->named('account:login:2fa'));
}
-
+
// Redirect to complete setup if it's not completed yet.
if ($settingsRepo->getSetting(Settings::SETUP_COMPLETE, 0) === 0) {
$flash->addMessage('' . __('Logged in successfully.') . '
' . __('Complete the setup process to get started.'),
diff --git a/src/Controller/Frontend/ApiKeysController.php b/src/Controller/Frontend/ApiKeysController.php
index 862e21d61..f5de3b306 100644
--- a/src/Controller/Frontend/ApiKeysController.php
+++ b/src/Controller/Frontend/ApiKeysController.php
@@ -1,18 +1,18 @@
em = $em;
$this->record_repo = $apiKeyRepository;
diff --git a/src/Controller/Frontend/DashboardController.php b/src/Controller/Frontend/DashboardController.php
index 8ab9405ad..7f6413fb6 100644
--- a/src/Controller/Frontend/DashboardController.php
+++ b/src/Controller/Frontend/DashboardController.php
@@ -9,7 +9,7 @@ use App\Http\Response;
use App\Http\Router;
use App\Http\ServerRequest;
use App\Radio\Adapters;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use InfluxDB\Database;
use Psr\Http\Message\ResponseInterface;
use Psr\SimpleCache\CacheInterface;
@@ -17,7 +17,7 @@ use stdClass;
class DashboardController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Entity\Repository\SettingsRepository $settingsRepo;
@@ -34,7 +34,7 @@ class DashboardController
protected EventDispatcher $dispatcher;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
Acl $acl,
CacheInterface $cache,
diff --git a/src/Controller/Frontend/Profile/DisableTwoFactorAction.php b/src/Controller/Frontend/Profile/DisableTwoFactorAction.php
index 9a9303841..9073f0125 100644
--- a/src/Controller/Frontend/Profile/DisableTwoFactorAction.php
+++ b/src/Controller/Frontend/Profile/DisableTwoFactorAction.php
@@ -4,7 +4,7 @@ namespace App\Controller\Frontend\Profile;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Session\Flash;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class DisableTwoFactorAction
@@ -12,7 +12,7 @@ class DisableTwoFactorAction
public function __invoke(
ServerRequest $request,
Response $response,
- EntityManager $em
+ EntityManagerInterface $em
): ResponseInterface {
$user = $request->getUser();
diff --git a/src/Controller/Frontend/Profile/EnableTwoFactorAction.php b/src/Controller/Frontend/Profile/EnableTwoFactorAction.php
index 6a97b2772..3e11f93d1 100644
--- a/src/Controller/Frontend/Profile/EnableTwoFactorAction.php
+++ b/src/Controller/Frontend/Profile/EnableTwoFactorAction.php
@@ -9,7 +9,7 @@ use App\Http\ServerRequest;
use App\Session\Flash;
use AzuraForms\Field\AbstractField;
use BaconQrCode;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use OTPHP\TOTP;
use ParagonIE\ConstantTime\Base32;
use Psr\Http\Message\ResponseInterface;
@@ -20,7 +20,7 @@ class EnableTwoFactorAction
ServerRequest $request,
Response $response,
Config $config,
- EntityManager $em
+ EntityManagerInterface $em
): ResponseInterface {
$twoFactorFormConfig = $config->get('forms/profile_two_factor');
diff --git a/src/Controller/Frontend/PublicPages/OnDemandAction.php b/src/Controller/Frontend/PublicPages/OnDemandAction.php
index 972650eee..1a626dea2 100644
--- a/src/Controller/Frontend/PublicPages/OnDemandAction.php
+++ b/src/Controller/Frontend/PublicPages/OnDemandAction.php
@@ -5,7 +5,7 @@ use App\Exception\StationNotFoundException;
use App\Exception\StationUnsupportedException;
use App\Http\Response;
use App\Http\ServerRequest;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class OnDemandAction
@@ -13,7 +13,7 @@ class OnDemandAction
public function __invoke(
ServerRequest $request,
Response $response,
- EntityManager $em,
+ EntityManagerInterface $em,
bool $embed = false
): ResponseInterface {
// Override system-wide iframe refusal
diff --git a/src/Controller/Frontend/SetupController.php b/src/Controller/Frontend/SetupController.php
index 0045677f0..dcc3f4815 100644
--- a/src/Controller/Frontend/SetupController.php
+++ b/src/Controller/Frontend/SetupController.php
@@ -9,14 +9,14 @@ use App\Form\SettingsForm;
use App\Form\StationForm;
use App\Http\Response;
use App\Http\ServerRequest;
-use App\Settings;
use App\Session\Flash;
-use Doctrine\ORM\EntityManager;
+use App\Settings;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class SetupController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Entity\Repository\SettingsRepository $settingsRepo;
@@ -27,7 +27,7 @@ class SetupController
protected Settings $settings;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepository,
Auth $auth,
Acl $acl,
diff --git a/src/Controller/Stations/AbstractStationCrudController.php b/src/Controller/Stations/AbstractStationCrudController.php
index e6559f353..dc9679133 100644
--- a/src/Controller/Stations/AbstractStationCrudController.php
+++ b/src/Controller/Stations/AbstractStationCrudController.php
@@ -7,7 +7,7 @@ use App\Exception\CsrfValidationException;
use App\Exception\NotFoundException;
use App\Form\EntityForm;
use App\Http\ServerRequest;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
@@ -16,7 +16,7 @@ abstract class AbstractStationCrudController
{
protected EntityForm $form;
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected string $entity_class;
diff --git a/src/Controller/Stations/AutomationController.php b/src/Controller/Stations/AutomationController.php
index ea95c34e0..00e130c69 100644
--- a/src/Controller/Stations/AutomationController.php
+++ b/src/Controller/Stations/AutomationController.php
@@ -1,20 +1,20 @@
getStation();
diff --git a/src/Controller/Stations/FilesController.php b/src/Controller/Stations/FilesController.php
index 95a025088..0dee0c4fb 100644
--- a/src/Controller/Stations/FilesController.php
+++ b/src/Controller/Stations/FilesController.php
@@ -5,7 +5,7 @@ use App\Entity;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Service\SftpGo;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class FilesController
@@ -13,7 +13,7 @@ class FilesController
public function __invoke(
ServerRequest $request,
Response $response,
- EntityManager $em
+ EntityManagerInterface $em
): ResponseInterface {
$station = $request->getStation();
diff --git a/src/Controller/Stations/ProfileController.php b/src/Controller/Stations/ProfileController.php
index 515453169..eeea06ea0 100644
--- a/src/Controller/Stations/ProfileController.php
+++ b/src/Controller/Stations/ProfileController.php
@@ -5,12 +5,12 @@ use App\Entity;
use App\Form\StationForm;
use App\Http\Response;
use App\Http\ServerRequest;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class ProfileController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Entity\Repository\StationRepository $station_repo;
@@ -19,7 +19,7 @@ class ProfileController
protected string $csrf_namespace = 'stations_profile';
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\StationRepository $station_repo,
StationForm $station_form
) {
diff --git a/src/Controller/Stations/Reports/DuplicatesController.php b/src/Controller/Stations/Reports/DuplicatesController.php
index 61fb28dee..18aca0431 100644
--- a/src/Controller/Stations/Reports/DuplicatesController.php
+++ b/src/Controller/Stations/Reports/DuplicatesController.php
@@ -6,19 +6,19 @@ use App\Flysystem\Filesystem;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Session\Flash;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class DuplicatesController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Entity\Repository\StationMediaRepository $mediaRepo;
protected Filesystem $filesystem;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\StationMediaRepository $mediaRepo,
Filesystem $filesystem
) {
diff --git a/src/Controller/Stations/Reports/OverviewController.php b/src/Controller/Stations/Reports/OverviewController.php
index 9dcf3fb70..5f5df6d01 100644
--- a/src/Controller/Stations/Reports/OverviewController.php
+++ b/src/Controller/Stations/Reports/OverviewController.php
@@ -6,7 +6,7 @@ use App\Http\Response;
use App\Http\ServerRequest;
use Cake\Chronos\Chronos;
use DateTimeZone;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use InfluxDB\Database;
use Psr\Http\Message\ResponseInterface;
use stdClass;
@@ -15,14 +15,17 @@ use function array_slice;
class OverviewController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Entity\Repository\SettingsRepository $settingsRepo;
protected Database $influx;
- public function __construct(EntityManager $em, Entity\Repository\SettingsRepository $settingsRepo, Database $influx)
- {
+ public function __construct(
+ EntityManagerInterface $em,
+ Entity\Repository\SettingsRepository $settingsRepo,
+ Database $influx
+ ) {
$this->em = $em;
$this->settingsRepo = $settingsRepo;
$this->influx = $influx;
diff --git a/src/Controller/Stations/Reports/PerformanceController.php b/src/Controller/Stations/Reports/PerformanceController.php
index f77733760..ba397297b 100644
--- a/src/Controller/Stations/Reports/PerformanceController.php
+++ b/src/Controller/Stations/Reports/PerformanceController.php
@@ -6,16 +6,16 @@ use App\Http\Response;
use App\Http\ServerRequest;
use App\Sync\Task\RadioAutomation;
use App\Utilities\Csv;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class PerformanceController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected RadioAutomation $sync_automation;
- public function __construct(EntityManager $em, RadioAutomation $sync_automation)
+ public function __construct(EntityManagerInterface $em, RadioAutomation $sync_automation)
{
$this->em = $em;
$this->sync_automation = $sync_automation;
diff --git a/src/Controller/Stations/Reports/RequestsController.php b/src/Controller/Stations/Reports/RequestsController.php
index f7d1f6c60..ed8d87490 100644
--- a/src/Controller/Stations/Reports/RequestsController.php
+++ b/src/Controller/Stations/Reports/RequestsController.php
@@ -5,16 +5,16 @@ use App\Entity;
use App\Http\Response;
use App\Http\ServerRequest;
use App\Session\Flash;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class RequestsController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected string $csrf_namespace = 'stations_requests';
- public function __construct(EntityManager $em)
+ public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
diff --git a/src/Controller/Stations/Reports/SoundExchangeController.php b/src/Controller/Stations/Reports/SoundExchangeController.php
index 56409481c..b67357326 100644
--- a/src/Controller/Stations/Reports/SoundExchangeController.php
+++ b/src/Controller/Stations/Reports/SoundExchangeController.php
@@ -1,12 +1,12 @@
em = $em;
$this->form_config = $config->get('forms/report/soundexchange');
diff --git a/src/Controller/Stations/StreamersController.php b/src/Controller/Stations/StreamersController.php
index 9a9c29d93..e4e2b543e 100644
--- a/src/Controller/Stations/StreamersController.php
+++ b/src/Controller/Stations/StreamersController.php
@@ -7,19 +7,19 @@ use App\Http\Response;
use App\Http\ServerRequest;
use App\Service\AzuraCastCentral;
use App\Session\Flash;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ResponseInterface;
class StreamersController
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected AzuraCastCentral $ac_central;
protected Entity\Repository\SettingsRepository $settingsRepo;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
AzuraCastCentral $ac_central,
Entity\Repository\SettingsRepository $settingsRepo
) {
diff --git a/src/Doctrine/DecoratedEntityManager.php b/src/Doctrine/DecoratedEntityManager.php
new file mode 100644
index 000000000..ddacd3548
--- /dev/null
+++ b/src/Doctrine/DecoratedEntityManager.php
@@ -0,0 +1,51 @@
+createEm = Closure::fromCallable($createEm);
+ }
+
+ /**
+ * Recreate the underlying EntityManager if it was closed due to a previous exception.
+ */
+ public function open(): void
+ {
+ if (!$this->wrapped->isOpen()) {
+ $this->wrapped = ($this->createEm)();
+ }
+ }
+
+ /**
+ * Fetch a new, managed instance of an entity object, even if the EntityManager has been cleared.
+ *
+ * @template T
+ *
+ * @param T $entity
+ *
+ * @return T
+ */
+ public function refetch($entity)
+ {
+ $metadata = $this->wrapped->getClassMetadata(get_class($entity));
+ $freshValue = $this->wrapped->find($metadata->getName(), $metadata->getIdentifierValues($entity));
+
+ if (!$freshValue) {
+ throw new \InvalidArgumentException(
+ sprintf('Object of class %s cannot be refetched.', get_class($entity))
+ );
+ }
+
+ return $freshValue;
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/Doctrine/Event/AuditLog.php b/src/Doctrine/Event/AuditLog.php
index d7df40c23..7eeedea6e 100644
--- a/src/Doctrine/Event/AuditLog.php
+++ b/src/Doctrine/Event/AuditLog.php
@@ -7,7 +7,7 @@ use App\Annotations\AuditLog\AuditIgnore;
use App\Entity;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\EventSubscriber;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
@@ -219,12 +219,12 @@ class AuditLog implements EventSubscriber
}
/**
- * @param EntityManager $em
+ * @param EntityManagerInterface $em
* @param object|string $class
*
* @return bool
*/
- protected function isEntity(EntityManager $em, $class): bool
+ protected function isEntity(EntityManagerInterface $em, $class): bool
{
if (is_object($class)) {
$class = ($class instanceof Proxy || $class instanceof GhostObjectInterface)
diff --git a/src/Doctrine/Repository.php b/src/Doctrine/Repository.php
index 2a7910f89..fdd8df660 100644
--- a/src/Doctrine/Repository.php
+++ b/src/Doctrine/Repository.php
@@ -5,6 +5,7 @@ use App\Normalizer\DoctrineEntityNormalizer;
use App\Settings;
use Closure;
use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Serializer\Serializer;
@@ -30,13 +31,17 @@ class Repository
protected $logger;
/**
- * @param EntityManager $em
+ * @param EntityManagerInterface $em
* @param Serializer $serializer
* @param Settings $settings
* @param LoggerInterface $logger
*/
- public function __construct(EntityManager $em, Serializer $serializer, Settings $settings, LoggerInterface $logger)
- {
+ public function __construct(
+ EntityManagerInterface $em,
+ Serializer $serializer,
+ Settings $settings,
+ LoggerInterface $logger
+ ) {
$this->em = $em;
$this->serializer = $serializer;
$this->settings = $settings;
diff --git a/src/Entity/Repository/SongHistoryRepository.php b/src/Entity/Repository/SongHistoryRepository.php
index 6c6c28807..936b9edfe 100644
--- a/src/Entity/Repository/SongHistoryRepository.php
+++ b/src/Entity/Repository/SongHistoryRepository.php
@@ -5,7 +5,7 @@ use App\ApiUtilities;
use App\Doctrine\Repository;
use App\Entity;
use App\Settings;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Psr\Http\Message\UriInterface;
use Psr\Log\LoggerInterface;
@@ -16,7 +16,7 @@ class SongHistoryRepository extends Repository
protected ListenerRepository $listenerRepository;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Serializer $serializer,
Settings $settings,
LoggerInterface $logger,
diff --git a/src/Entity/Repository/StationMediaRepository.php b/src/Entity/Repository/StationMediaRepository.php
index c52979a68..65d86592a 100644
--- a/src/Entity/Repository/StationMediaRepository.php
+++ b/src/Entity/Repository/StationMediaRepository.php
@@ -7,7 +7,7 @@ use App\Exception\MediaProcessingException;
use App\Flysystem\Filesystem;
use App\Service\AudioWaveform;
use App\Settings;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMException;
use Exception;
use getID3;
@@ -27,7 +27,7 @@ class StationMediaRepository extends Repository
protected CustomFieldRepository $customFieldRepo;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Serializer $serializer,
Settings $settings,
LoggerInterface $logger,
diff --git a/src/Entity/Repository/StationRepository.php b/src/Entity/Repository/StationRepository.php
index de868a3c4..2014c5205 100644
--- a/src/Entity/Repository/StationRepository.php
+++ b/src/Entity/Repository/StationRepository.php
@@ -9,7 +9,7 @@ use App\Radio\Frontend\AbstractFrontend;
use App\Sync\Task\Media;
use App\Utilities;
use Closure;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Psr\Log\LoggerInterface;
use Psr\SimpleCache\CacheInterface;
@@ -29,7 +29,7 @@ class StationRepository extends Repository
protected CacheInterface $cache;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Serializer $serializer,
\App\Settings $settings,
LoggerInterface $logger,
diff --git a/src/Form/AbstractSettingsForm.php b/src/Form/AbstractSettingsForm.php
index b90133112..72ed01cbb 100644
--- a/src/Form/AbstractSettingsForm.php
+++ b/src/Form/AbstractSettingsForm.php
@@ -5,17 +5,18 @@ use App\Entity;
use App\Http\ServerRequest;
use App\Settings;
use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
abstract class AbstractSettingsForm extends Form
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Entity\Repository\SettingsRepository $settingsRepo;
protected Settings $settings;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
Settings $settings,
array $formConfig
diff --git a/src/Form/ApiKeyForm.php b/src/Form/ApiKeyForm.php
index eee834f0e..cf4f62151 100644
--- a/src/Form/ApiKeyForm.php
+++ b/src/Form/ApiKeyForm.php
@@ -1,16 +1,16 @@
get('forms/custom_field');
parent::__construct($em, $serializer, $validator, $form_config);
-
+
$this->entityClass = Entity\CustomField::class;
}
}
diff --git a/src/Form/EntityForm.php b/src/Form/EntityForm.php
index 68aa650c5..1058bc336 100644
--- a/src/Form/EntityForm.php
+++ b/src/Form/EntityForm.php
@@ -6,8 +6,8 @@ use App\Exception;
use App\Http\ServerRequest;
use App\Normalizer\DoctrineEntityNormalizer;
use App\Settings;
-use Doctrine\ORM\EntityManager;
-use Doctrine\ORM\EntityRepository;
+use Doctrine\ORM\EntityManagerInterface;
+use Doctrine\Persistence\ObjectRepository;
use InvalidArgumentException;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
@@ -23,7 +23,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
*/
class EntityForm extends Form
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Serializer $serializer;
@@ -38,7 +38,7 @@ class EntityForm extends Form
protected ?Station $station = null;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Serializer $serializer,
ValidatorInterface $validator,
array $options = [],
@@ -61,12 +61,12 @@ class EntityForm extends Form
$this->entityClass = $entityClass;
}
- public function getEntityManager(): EntityManager
+ public function getEntityManager(): EntityManagerInterface
{
return $this->em;
}
- public function getEntityRepository(): EntityRepository
+ public function getEntityRepository(): ObjectRepository
{
if (null === $this->entityClass) {
throw new Exception('Entity class name is not specified.');
diff --git a/src/Form/GeoLiteSettingsForm.php b/src/Form/GeoLiteSettingsForm.php
index 96178abe2..747fd8516 100644
--- a/src/Form/GeoLiteSettingsForm.php
+++ b/src/Form/GeoLiteSettingsForm.php
@@ -5,14 +5,14 @@ use App\Config;
use App\Entity;
use App\Settings;
use App\Sync\Task\UpdateGeoLiteDatabase;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
class GeoLiteSettingsForm extends AbstractSettingsForm
{
protected UpdateGeoLiteDatabase $syncTask;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
Settings $settings,
Config $config,
diff --git a/src/Form/PermissionsForm.php b/src/Form/PermissionsForm.php
index 7a1cded84..471375359 100644
--- a/src/Form/PermissionsForm.php
+++ b/src/Form/PermissionsForm.php
@@ -1,10 +1,10 @@
queues = $queues;
$this->producer = $producer;
@@ -120,12 +120,7 @@ class MessageQueue implements EventSubscriberInterface
public function checkEntityManager(): void
{
- // Shut the process manager down if the entity manager isn't open.
- if (!$this->em->isOpen()) {
- exit;
- }
-
- // Clear the EM before running any new tasks.
+ $this->em->open();
$this->em->clear();
}
diff --git a/src/Middleware/ReopenEntityManagerMiddleware.php b/src/Middleware/ReopenEntityManagerMiddleware.php
new file mode 100644
index 000000000..9afddd511
--- /dev/null
+++ b/src/Middleware/ReopenEntityManagerMiddleware.php
@@ -0,0 +1,39 @@
+em = $em;
+ $this->settings = $settings;
+ }
+
+ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
+ {
+ $this->em->open();
+
+ try {
+ return $handler->handle($request);
+ } finally {
+ if (!$this->settings->isTesting()) {
+ $this->em->getConnection()->close();
+ }
+
+ $this->em->clear();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Normalizer/DoctrineEntityNormalizer.php b/src/Normalizer/DoctrineEntityNormalizer.php
index 5fc071002..560bdbd7e 100644
--- a/src/Normalizer/DoctrineEntityNormalizer.php
+++ b/src/Normalizer/DoctrineEntityNormalizer.php
@@ -8,7 +8,7 @@ use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Collections\Collection;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Proxy\Proxy;
use InvalidArgumentException;
@@ -40,21 +40,14 @@ class DoctrineEntityNormalizer extends AbstractNormalizer
/** @var SerializerInterface|NormalizerInterface|DenormalizerInterface */
protected $serializer;
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Reader $annotationReader;
protected Inflector $inflector;
- /**
- * @param EntityManager $em
- * @param Reader|null $annotationReader
- * @param ClassMetadataFactoryInterface|null $classMetadataFactory
- * @param NameConverterInterface|null $nameConverter
- * @param array $defaultContext
- */
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Reader $annotationReader = null,
ClassMetadataFactoryInterface $classMetadataFactory = null,
NameConverterInterface $nameConverter = null,
@@ -397,7 +390,9 @@ class DoctrineEntityNormalizer extends AbstractNormalizer
$first_param = $method->getParameters()[0];
if ($first_param->hasType()) {
- $first_param_type = $first_param->getType()->getName();
+ /** @var \ReflectionNamedType $firstParamTypeObj */
+ $firstParamTypeObj = $first_param->getType();
+ $first_param_type = $firstParamTypeObj->getName();
switch ($first_param_type) {
case 'DateTime':
diff --git a/src/Notification/Manager.php b/src/Notification/Manager.php
index 97889aa7f..7a11a8652 100644
--- a/src/Notification/Manager.php
+++ b/src/Notification/Manager.php
@@ -6,7 +6,7 @@ use App\Entity;
use App\Event\GetNotifications;
use App\Settings;
use Cake\Chronos\Chronos;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Monolog\Logger;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -14,7 +14,7 @@ class Manager implements EventSubscriberInterface
{
protected Acl $acl;
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Logger $logger;
@@ -24,7 +24,7 @@ class Manager implements EventSubscriberInterface
public function __construct(
Acl $acl,
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settings_repo,
Logger $logger,
Settings $app_settings
diff --git a/src/Radio/AbstractAdapter.php b/src/Radio/AbstractAdapter.php
index 1a5cdcb70..b869dc5d7 100644
--- a/src/Radio/AbstractAdapter.php
+++ b/src/Radio/AbstractAdapter.php
@@ -2,28 +2,28 @@
namespace App\Radio;
use App\Entity;
+use App\EventDispatcher;
use App\Exception\Supervisor\AlreadyRunningException;
use App\Exception\Supervisor\BadNameException;
use App\Exception\Supervisor\NotRunningException;
use App\Exception\SupervisorException;
-use App\Settings;
-use App\EventDispatcher;
use App\Logger;
-use Doctrine\ORM\EntityManager;
+use App\Settings;
+use Doctrine\ORM\EntityManagerInterface;
use fXmlRpc\Exception\FaultException;
use Supervisor\Process;
use Supervisor\Supervisor;
abstract class AbstractAdapter
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Supervisor $supervisor;
protected EventDispatcher $dispatcher;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Supervisor $supervisor,
EventDispatcher $dispatcher
) {
diff --git a/src/Radio/AutoDJ.php b/src/Radio/AutoDJ.php
index 01a58e4b0..0c70f43d5 100644
--- a/src/Radio/AutoDJ.php
+++ b/src/Radio/AutoDJ.php
@@ -9,7 +9,7 @@ use App\Flysystem\Filesystem;
use App\Lock\LockManager;
use Cake\Chronos\Chronos;
use DateTimeZone;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Monolog\Logger;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -17,7 +17,7 @@ class AutoDJ implements EventSubscriberInterface
{
protected Adapters $adapters;
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Entity\Repository\SongRepository $songRepo;
@@ -39,7 +39,7 @@ class AutoDJ implements EventSubscriberInterface
public function __construct(
Adapters $adapters,
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SongRepository $songRepo,
Entity\Repository\SongHistoryRepository $songHistoryRepo,
Entity\Repository\StationPlaylistMediaRepository $spmRepo,
diff --git a/src/Radio/Backend/Liquidsoap.php b/src/Radio/Backend/Liquidsoap.php
index e20379c37..a5edf3f38 100644
--- a/src/Radio/Backend/Liquidsoap.php
+++ b/src/Radio/Backend/Liquidsoap.php
@@ -7,7 +7,7 @@ use App\EventDispatcher;
use App\Exception;
use App\Radio\Backend\Liquidsoap\ConfigWriter;
use App\Settings;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\UriInterface;
use Supervisor\Supervisor;
@@ -16,7 +16,7 @@ class Liquidsoap extends AbstractBackend
protected Entity\Repository\StationStreamerRepository $streamerRepo;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Supervisor $supervisor,
EventDispatcher $dispatcher,
Entity\Repository\StationStreamerRepository $streamerRepo
diff --git a/src/Radio/Backend/Liquidsoap/ConfigWriter.php b/src/Radio/Backend/Liquidsoap/ConfigWriter.php
index 2b5d31624..f7d4810ff 100644
--- a/src/Radio/Backend/Liquidsoap/ConfigWriter.php
+++ b/src/Radio/Backend/Liquidsoap/ConfigWriter.php
@@ -9,7 +9,7 @@ use App\Message;
use App\Radio\Adapters;
use App\Radio\Backend\Liquidsoap;
use App\Settings;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ConfigWriter implements EventSubscriberInterface
@@ -24,11 +24,11 @@ class ConfigWriter implements EventSubscriberInterface
public const CROSSFADE_DISABLED = 'none';
public const CROSSFADE_SMART = 'smart';
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Liquidsoap $liquidsoap;
- public function __construct(EntityManager $em, Liquidsoap $liquidsoap)
+ public function __construct(EntityManagerInterface $em, Liquidsoap $liquidsoap)
{
$this->em = $em;
$this->liquidsoap = $liquidsoap;
@@ -175,8 +175,7 @@ class ConfigWriter implements EventSubscriberInterface
// Auto-create an empty default playlist.
$defaultPlaylist = new Entity\StationPlaylist($station);
$defaultPlaylist->setName('default');
-
- /** @var EntityManager $em */
+
$this->em->persist($defaultPlaylist);
$this->em->flush();
@@ -482,7 +481,7 @@ class ConfigWriter implements EventSubscriberInterface
$mediaBaseDir = $station->getRadioMediaDir() . '/';
$playlistFile = [];
-
+
$mediaQuery = $this->em->createQuery(/** @lang DQL */ 'SELECT DISTINCT sm
FROM App\Entity\StationMedia sm
JOIN sm.playlists spm
diff --git a/src/Radio/Configuration.php b/src/Radio/Configuration.php
index 972ac5e70..3ea543eb2 100644
--- a/src/Radio/Configuration.php
+++ b/src/Radio/Configuration.php
@@ -4,7 +4,7 @@ namespace App\Radio;
use App\Entity\Station;
use App\Exception;
use App\Settings;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use fXmlRpc\Exception\FaultException;
use Monolog\Logger;
use RuntimeException;
@@ -15,7 +15,7 @@ class Configuration
public const DEFAULT_PORT_MIN = 8000;
public const DEFAULT_PORT_MAX = 8499;
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Adapters $adapters;
@@ -24,7 +24,7 @@ class Configuration
protected Logger $logger;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Adapters $adapters,
Supervisor $supervisor,
Logger $logger
diff --git a/src/Radio/Frontend/AbstractFrontend.php b/src/Radio/Frontend/AbstractFrontend.php
index 1f2fe8949..4d332b17b 100644
--- a/src/Radio/Frontend/AbstractFrontend.php
+++ b/src/Radio/Frontend/AbstractFrontend.php
@@ -8,7 +8,7 @@ use App\Logger;
use App\Radio\AbstractAdapter;
use App\Settings;
use App\Xml\Reader;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Uri;
use NowPlaying\Adapter\AdapterAbstract;
@@ -28,7 +28,7 @@ abstract class AbstractFrontend extends AbstractAdapter
protected Entity\Repository\StationMountRepository $stationMountRepo;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
Entity\Repository\StationMountRepository $stationMountRepo,
Supervisor $supervisor,
diff --git a/src/Radio/Remote/AbstractRemote.php b/src/Radio/Remote/AbstractRemote.php
index 9ce4b88c9..e7dfed807 100644
--- a/src/Radio/Remote/AbstractRemote.php
+++ b/src/Radio/Remote/AbstractRemote.php
@@ -2,7 +2,7 @@
namespace App\Radio\Remote;
use App\Entity;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Uri;
use Monolog\Logger;
@@ -10,7 +10,7 @@ use NowPlaying\Adapter\AdapterAbstract;
abstract class AbstractRemote
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Entity\Repository\SettingsRepository $settingsRepo;
@@ -19,7 +19,7 @@ abstract class AbstractRemote
protected Logger $logger;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
Client $http_client,
Logger $logger
diff --git a/src/Service/UptimeWait.php b/src/Service/UptimeWait.php
index 676373f1b..d92e51b14 100644
--- a/src/Service/UptimeWait.php
+++ b/src/Service/UptimeWait.php
@@ -2,7 +2,7 @@
namespace App\Service;
use Doctrine\DBAL\Connection;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use InfluxDB;
class UptimeWait
@@ -13,7 +13,7 @@ class UptimeWait
protected InfluxDB\Client $influx;
- public function __construct(EntityManager $em, \Redis $redis, InfluxDB\Database $influx)
+ public function __construct(EntityManagerInterface $em, \Redis $redis, InfluxDB\Database $influx)
{
$this->db = $em->getConnection();
$this->redis = $redis;
diff --git a/src/Sync/Task/AbstractTask.php b/src/Sync/Task/AbstractTask.php
index dee8a66eb..6f9b3e5ba 100644
--- a/src/Sync/Task/AbstractTask.php
+++ b/src/Sync/Task/AbstractTask.php
@@ -2,19 +2,19 @@
namespace App\Sync\Task;
use App\Entity;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
abstract class AbstractTask
{
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
protected Entity\Repository\SettingsRepository $settingsRepo;
protected LoggerInterface $logger;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger
) {
diff --git a/src/Sync/Task/Analytics.php b/src/Sync/Task/Analytics.php
index 5820b3eb7..5097a298e 100644
--- a/src/Sync/Task/Analytics.php
+++ b/src/Sync/Task/Analytics.php
@@ -2,7 +2,7 @@
namespace App\Sync\Task;
use App\Entity;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use InfluxDB\Database;
use Psr\Log\LoggerInterface;
@@ -11,7 +11,7 @@ class Analytics extends AbstractTask
protected Database $influx;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger,
Database $influx
diff --git a/src/Sync/Task/Backup.php b/src/Sync/Task/Backup.php
index b470af2fa..026878606 100644
--- a/src/Sync/Task/Backup.php
+++ b/src/Sync/Task/Backup.php
@@ -6,7 +6,7 @@ use App\Entity;
use App\Message;
use App\MessageQueue;
use Cake\Chronos\Chronos;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
class Backup extends AbstractTask
@@ -18,7 +18,7 @@ class Backup extends AbstractTask
protected Application $console;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger,
MessageQueue $message_queue,
@@ -95,7 +95,7 @@ class Backup extends AbstractTask
if ($last_run <= $threshold) {
// Check if the backup time matches (if it's set).
$backupTimecode = (int)$this->settingsRepo->getSetting(Entity\Settings::BACKUP_TIME);
-
+
if (0 !== $backupTimecode) {
$isWithinTimecode = false;
$backupDt = Entity\StationSchedule::getDateTime($backupTimecode, $now_utc);
diff --git a/src/Sync/Task/BuildQueue.php b/src/Sync/Task/BuildQueue.php
index b0e408018..85e469791 100644
--- a/src/Sync/Task/BuildQueue.php
+++ b/src/Sync/Task/BuildQueue.php
@@ -4,7 +4,7 @@ namespace App\Sync\Task;
use App\Entity;
use App\Lock\LockManager;
use App\Radio\AutoDJ;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
class BuildQueue extends AbstractTask
@@ -14,7 +14,7 @@ class BuildQueue extends AbstractTask
protected LockManager $lockManager;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger,
AutoDJ $autoDJ,
diff --git a/src/Sync/Task/CheckForUpdates.php b/src/Sync/Task/CheckForUpdates.php
index aefdb769b..f5d104af0 100644
--- a/src/Sync/Task/CheckForUpdates.php
+++ b/src/Sync/Task/CheckForUpdates.php
@@ -4,7 +4,7 @@ namespace App\Sync\Task;
use App\Entity;
use App\Service\AzuraCastCentral;
use App\Settings;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use GuzzleHttp\Exception\TransferException;
use Psr\Log\LoggerInterface;
@@ -15,7 +15,7 @@ class CheckForUpdates extends AbstractTask
protected AzuraCastCentral $azuracastCentral;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger,
AzuraCastCentral $azuracastCentral
diff --git a/src/Sync/Task/FolderPlaylists.php b/src/Sync/Task/FolderPlaylists.php
index 02f25092b..8425f7066 100644
--- a/src/Sync/Task/FolderPlaylists.php
+++ b/src/Sync/Task/FolderPlaylists.php
@@ -4,7 +4,7 @@ namespace App\Sync\Task;
use App\Entity;
use App\Flysystem\Filesystem;
use App\MessageQueue;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use DoctrineBatchUtils\BatchProcessing\SimpleBatchIteratorAggregate;
use Psr\Log\LoggerInterface;
@@ -19,7 +19,7 @@ class FolderPlaylists extends AbstractTask
protected MessageQueue $messageQueue;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger,
Entity\Repository\StationPlaylistMediaRepository $spmRepo,
@@ -96,9 +96,8 @@ class FolderPlaylists extends AbstractTask
->execute();
foreach ($mediaInFolder as $media) {
- /** @var Entity\StationMedia $media */
-
foreach ($playlists as $playlist) {
+ /** @var Entity\StationMedia $media */
/** @var Entity\StationPlaylist $playlist */
if (Entity\StationPlaylist::ORDER_SEQUENTIAL !== $playlist->getOrder()
diff --git a/src/Sync/Task/Media.php b/src/Sync/Task/Media.php
index 21eea404e..7794afad0 100644
--- a/src/Sync/Task/Media.php
+++ b/src/Sync/Task/Media.php
@@ -9,7 +9,7 @@ use App\Radio\Quota;
use Bernard\Envelope;
use Brick\Math\BigInteger;
use Doctrine\Common\Persistence\Mapping\MappingException;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use DoctrineBatchUtils\BatchProcessing\SimpleBatchIteratorAggregate;
use Jhofm\FlysystemIterator\Filter\FilterFactory;
use Psr\Log\LoggerInterface;
@@ -26,7 +26,7 @@ class Media extends AbstractTask
protected MessageQueue $messageQueue;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger,
Entity\Repository\StationMediaRepository $mediaRepo,
diff --git a/src/Sync/Task/NowPlaying.php b/src/Sync/Task/NowPlaying.php
index fc33490ce..e5d752ce4 100644
--- a/src/Sync/Task/NowPlaying.php
+++ b/src/Sync/Task/NowPlaying.php
@@ -13,7 +13,7 @@ use App\MessageQueue;
use App\Radio\Adapters;
use App\Radio\AutoDJ;
use App\Settings;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Exception;
use GuzzleHttp\Psr7\Uri;
use InfluxDB\Database;
@@ -52,7 +52,7 @@ class NowPlaying extends AbstractTask implements EventSubscriberInterface
protected string $analytics_level = Entity\Analytics::LEVEL_ALL;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Adapters $adapters,
ApiUtilities $api_utils,
AutoDJ $autodj,
diff --git a/src/Sync/Task/RadioAutomation.php b/src/Sync/Task/RadioAutomation.php
index a4b6835c6..8835eea67 100644
--- a/src/Sync/Task/RadioAutomation.php
+++ b/src/Sync/Task/RadioAutomation.php
@@ -2,10 +2,10 @@
namespace App\Sync\Task;
use App\Entity;
-use App\Radio\Adapters;
use App\Exception;
+use App\Radio\Adapters;
use Cake\Chronos\Chronos;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use DoctrineBatchUtils\BatchProcessing\SimpleBatchIteratorAggregate;
use Psr\Log\LoggerInterface;
@@ -18,7 +18,7 @@ class RadioAutomation extends AbstractTask
protected Adapters $adapters;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger,
Entity\Repository\StationMediaRepository $mediaRepo,
diff --git a/src/Sync/Task/RadioRequests.php b/src/Sync/Task/RadioRequests.php
index 9edc5bc93..bd015b222 100644
--- a/src/Sync/Task/RadioRequests.php
+++ b/src/Sync/Task/RadioRequests.php
@@ -6,7 +6,7 @@ use App\Event\Radio\AnnotateNextSong;
use App\EventDispatcher;
use App\Radio\Adapters;
use App\Radio\Backend\Liquidsoap;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
class RadioRequests extends AbstractTask
@@ -18,7 +18,7 @@ class RadioRequests extends AbstractTask
protected Entity\Repository\StationRequestRepository $requestRepo;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger,
Entity\Repository\StationRequestRepository $requestRepo,
diff --git a/src/Sync/Task/ReactivateStreamer.php b/src/Sync/Task/ReactivateStreamer.php
index fd155a31c..bc9be0508 100644
--- a/src/Sync/Task/ReactivateStreamer.php
+++ b/src/Sync/Task/ReactivateStreamer.php
@@ -2,7 +2,7 @@
namespace App\Sync\Task;
use App\Entity;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
class ReactivateStreamer extends AbstractTask
@@ -10,7 +10,7 @@ class ReactivateStreamer extends AbstractTask
protected Entity\Repository\StationStreamerRepository $streamerRepo;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger,
Entity\Repository\StationStreamerRepository $streamerRepo
diff --git a/src/Sync/Task/RotateLogs.php b/src/Sync/Task/RotateLogs.php
index 495c7c71d..3ab4a6485 100644
--- a/src/Sync/Task/RotateLogs.php
+++ b/src/Sync/Task/RotateLogs.php
@@ -4,7 +4,7 @@ namespace App\Sync\Task;
use App\Entity;
use App\Radio\Adapters;
use App\Settings;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use studio24\Rotate;
use Supervisor\Supervisor;
@@ -17,7 +17,7 @@ class RotateLogs extends AbstractTask
protected Supervisor $supervisor;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger,
Adapters $adapters,
diff --git a/src/Sync/Task/UpdateGeoLiteDatabase.php b/src/Sync/Task/UpdateGeoLiteDatabase.php
index a1288ff4b..8c3538218 100644
--- a/src/Sync/Task/UpdateGeoLiteDatabase.php
+++ b/src/Sync/Task/UpdateGeoLiteDatabase.php
@@ -4,7 +4,7 @@ namespace App\Sync\Task;
use App\Entity;
use App\Service\IpGeolocation;
use App\Service\IpGeolocator\GeoLite;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Psr\Log\LoggerInterface;
@@ -19,7 +19,7 @@ class UpdateGeoLiteDatabase extends AbstractTask
protected IpGeolocation $geoLite;
public function __construct(
- EntityManager $em,
+ EntityManagerInterface $em,
Entity\Repository\SettingsRepository $settingsRepo,
LoggerInterface $logger,
Client $httpClient,
diff --git a/src/Tests/Module.php b/src/Tests/Module.php
index c1a4af728..73e55e36c 100644
--- a/src/Tests/Module.php
+++ b/src/Tests/Module.php
@@ -11,21 +11,17 @@ use Codeception\Configuration;
use Codeception\Lib\Framework;
use Codeception\Lib\Interfaces\DoctrineProvider;
use Codeception\TestInterface;
-use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Container\ContainerInterface;
use Slim\App;
class Module extends Framework implements DoctrineProvider
{
- /** @var ContainerInterface */
- public $container;
+ public ContainerInterface $container;
- /** @var App */
- public $app;
+ public App $app;
- /** @var EntityManagerInterface */
- public $em;
+ public EntityManagerInterface $em;
protected $requiredFields = ['container'];
@@ -42,7 +38,7 @@ class Module extends Framework implements DoctrineProvider
]);
$this->container = $this->app->getContainer();
- $this->em = $this->container->get(EntityManager::class);
+ $this->em = $this->container->get(EntityManagerInterface::class);
parent::_initialize();
}
@@ -61,16 +57,10 @@ class Module extends Framework implements DoctrineProvider
$_POST = [];
$_COOKIE = [];
- $this->em->clear();
- gc_collect_cycles();
-
parent::_after($test);
}
-
- /**
- * @return EntityManagerInterface
- */
- public function _getEntityManager()
+
+ public function _getEntityManager(): EntityManagerInterface
{
return $this->em;
}
diff --git a/src/Webhook/Connector/Twitter.php b/src/Webhook/Connector/Twitter.php
index d061415cd..d419787be 100644
--- a/src/Webhook/Connector/Twitter.php
+++ b/src/Webhook/Connector/Twitter.php
@@ -3,7 +3,7 @@ namespace App\Webhook\Connector;
use App\Entity\StationWebhook;
use App\Event\SendWebhooks;
-use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\TransferException;
use GuzzleHttp\HandlerStack;
@@ -14,9 +14,9 @@ class Twitter extends AbstractConnector
{
public const NAME = 'twitter';
- protected EntityManager $em;
+ protected EntityManagerInterface $em;
- public function __construct(Logger $logger, Client $http_client, EntityManager $em)
+ public function __construct(Logger $logger, Client $http_client, EntityManagerInterface $em)
{
parent::__construct($logger, $http_client);
diff --git a/tests/functional/A04_Frontend_PublicCest.php b/tests/functional/A04_Frontend_PublicCest.php
index f5d041960..974ad62ec 100644
--- a/tests/functional/A04_Frontend_PublicCest.php
+++ b/tests/functional/A04_Frontend_PublicCest.php
@@ -1,4 +1,5 @@
wantTo('Verify that the public page displays.');
- $I->amOnPage('/public/'.$this->test_station->getId());
+ $testStation = $this->getTestStation();
- $I->seeCurrentUrlEquals('/public/'.$this->test_station->getId());
- $I->see($this->test_station->getName());
+ $I->amOnPage('/public/' . $testStation->getId());
+
+ $I->seeCurrentUrlEquals('/public/' . $testStation->getId());
+ $I->see($testStation->getName());
}
}
\ No newline at end of file
diff --git a/tests/functional/C00_Station_ProfileCest.php b/tests/functional/C00_Station_ProfileCest.php
index d23adc652..997fb3b60 100644
--- a/tests/functional/C00_Station_ProfileCest.php
+++ b/tests/functional/C00_Station_ProfileCest.php
@@ -1,4 +1,5 @@
wantTo('View and edit a station profile.');
- $station_id = $this->test_station->getId();
+ $testStation = $this->getTestStation();
+ $station_id = $testStation->getId();
- $I->amOnPage('/station/'.$station_id.'/profile');
+ $I->amOnPage('/station/' . $station_id . '/profile');
$I->see('Functional Test Radio');
$I->wantTo('Edit a station profile.');
$I->click('Edit Profile', '#content');
- $I->seeCurrentUrlEquals('/station/'.$station_id.'/profile/edit');
+ $I->seeCurrentUrlEquals('/station/' . $station_id . '/profile/edit');
$I->submitForm('.form', [
'name' => 'Profile Update Test Radio',
'description' => 'Testing a profile update.',
]);
- $I->seeCurrentUrlEquals('/station/'.$station_id.'/profile');
+ $I->seeCurrentUrlEquals('/station/' . $station_id . '/profile');
$I->see('Profile Update Test Radio');
$I->see('Testing a profile update.');
diff --git a/tests/functional/C02_Station_MediaCest.php b/tests/functional/C02_Station_MediaCest.php
index 9254aa736..8573f5aee 100644
--- a/tests/functional/C02_Station_MediaCest.php
+++ b/tests/functional/C02_Station_MediaCest.php
@@ -12,7 +12,8 @@ class C02_Station_MediaCest extends CestAbstract
{
$I->wantTo('Upload a song to a station.');
- $station_id = $this->test_station->getId();
+ $testStation = $this->getTestStation();
+ $station_id = $testStation->getId();
// Upload test song
$test_song_orig = $this->settings[Settings::BASE_DIR] . '/resources/error.mp3';
diff --git a/tests/functional/C03_Station_MountPointsCest.php b/tests/functional/C03_Station_MountPointsCest.php
index eef0027db..f23b618ad 100644
--- a/tests/functional/C03_Station_MountPointsCest.php
+++ b/tests/functional/C03_Station_MountPointsCest.php
@@ -1,4 +1,5 @@
wantTo('Create a station mount point.');
- $station_id = $this->test_station->getId();
- $I->amOnPage('/station/'.$station_id.'/mounts');
+ $testStation = $this->getTestStation();
+ $station_id = $testStation->getId();
+
+ $I->amOnPage('/station/' . $station_id . '/mounts');
$I->see('Mount Points');
$I->click('add', '#content');
@@ -20,13 +23,13 @@ class C03_Station_MountPointsCest extends CestAbstract
'display_name' => 'Test MP3',
]);
- $I->seeCurrentUrlEquals('/station/'.$station_id.'/mounts');
+ $I->seeCurrentUrlEquals('/station/' . $station_id . '/mounts');
$I->see('Test MP3');
$I->click(\Codeception\Util\Locator::lastElement('.btn-danger'));
- $I->seeCurrentUrlEquals('/station/'.$station_id.'/mounts');
+ $I->seeCurrentUrlEquals('/station/' . $station_id . '/mounts');
$I->dontSee('Test MP3');
}
diff --git a/tests/functional/C03_Station_PlaylistsCest.php b/tests/functional/C03_Station_PlaylistsCest.php
index eb6f3de7b..74f5fce93 100644
--- a/tests/functional/C03_Station_PlaylistsCest.php
+++ b/tests/functional/C03_Station_PlaylistsCest.php
@@ -10,7 +10,9 @@ class C03_Station_PlaylistsCest extends CestAbstract
{
$I->wantTo('Create a station playlist.');
- $station_id = $this->test_station->getId();
+ $testStation = $this->getTestStation();
+ $station_id = $testStation->getId();
+
$I->amOnPage('/station/' . $station_id . '/playlists');
$I->see('Playlists');
diff --git a/tests/functional/C03_Station_RemoteRelaysCest.php b/tests/functional/C03_Station_RemoteRelaysCest.php
index d21be364c..c9dfe597e 100644
--- a/tests/functional/C03_Station_RemoteRelaysCest.php
+++ b/tests/functional/C03_Station_RemoteRelaysCest.php
@@ -1,4 +1,5 @@
wantTo('Create a station remote relay.');
- $station_id = $this->test_station->getId();
- $I->amOnPage('/station/'.$station_id.'/remotes');
+ $testStation = $this->getTestStation();
+ $station_id = $testStation->getId();
+
+ $I->amOnPage('/station/' . $station_id . '/remotes');
$I->see('Remote Relays');
$I->click('add', '#content');
@@ -18,16 +21,16 @@ class C03_Station_RemoteRelaysCest extends CestAbstract
$I->submitForm('.form', [
'type' => 'shoutcast1',
'url' => 'http://test.local',
- 'display_name' => 'Test Relay'
+ 'display_name' => 'Test Relay',
]);
- $I->seeCurrentUrlEquals('/station/'.$station_id.'/remotes');
+ $I->seeCurrentUrlEquals('/station/' . $station_id . '/remotes');
$I->see('Test Relay');
$I->click(\Codeception\Util\Locator::lastElement('.btn-danger'));
- $I->seeCurrentUrlEquals('/station/'.$station_id.'/remotes');
+ $I->seeCurrentUrlEquals('/station/' . $station_id . '/remotes');
$I->dontSee('Test Relay');
}
diff --git a/tests/functional/C04_Station_ReportsCest.php b/tests/functional/C04_Station_ReportsCest.php
index 85d034717..03e4c200f 100644
--- a/tests/functional/C04_Station_ReportsCest.php
+++ b/tests/functional/C04_Station_ReportsCest.php
@@ -10,7 +10,8 @@ class C04_Station_ReportsCest extends CestAbstract
{
$I->wantTo('View station reports.');
- $station_id = $this->test_station->getId();
+ $testStation = $this->getTestStation();
+ $station_id = $testStation->getId();
$I->amOnPAge('/station/' . $station_id . '/reports/overview');
diff --git a/tests/functional/C05_Station_AutomationCest.php b/tests/functional/C05_Station_AutomationCest.php
index 33cf131d5..8202c3f17 100644
--- a/tests/functional/C05_Station_AutomationCest.php
+++ b/tests/functional/C05_Station_AutomationCest.php
@@ -13,11 +13,13 @@ class C05_Station_AutomationCest extends CestAbstract
$I->wantTo('Test station automation.');
// Set up automation preconditions.
+ $testStation = $this->getTestStation();
+
$song_src = '/var/azuracast/www/resources/error.mp3';
- $song_dest = $this->test_station->getRadioMediaDir() . '/test.mp3';
+ $song_dest = $testStation->getRadioMediaDir() . '/test.mp3';
copy($song_src, $song_dest);
- $playlist = new Entity\StationPlaylist($this->test_station);
+ $playlist = new Entity\StationPlaylist($testStation);
$playlist->setName('Test Playlist');
$playlist->setIncludeInAutomation(true);
@@ -26,7 +28,7 @@ class C05_Station_AutomationCest extends CestAbstract
/** @var Entity\Repository\StationMediaRepository $media_repo */
$media_repo = $this->di->get(Entity\Repository\StationMediaRepository::class);
- $media = new Entity\StationMedia($this->test_station, 'test.mp3');
+ $media = new Entity\StationMedia($testStation, 'test.mp3');
$media_repo->loadFromFile($media, $song_dest);
$this->em->persist($media);
@@ -36,12 +38,10 @@ class C05_Station_AutomationCest extends CestAbstract
$this->em->flush();
- $this->em->refresh($this->test_station);
- $this->em->refresh($playlist);
+ $station_id = $testStation->getId();
+ $this->em->clear();
// Attempt to enable and run automation.
- $station_id = $this->test_station->getId();
-
$I->amOnPage('/station/' . $station_id . '/automation');
$I->submitForm('.form', [
diff --git a/tests/functional/CestAbstract.php b/tests/functional/CestAbstract.php
index c6124ae71..c1ef00520 100644
--- a/tests/functional/CestAbstract.php
+++ b/tests/functional/CestAbstract.php
@@ -6,55 +6,47 @@ use Psr\Container\ContainerInterface;
abstract class CestAbstract
{
- /** @var ContainerInterface */
- protected $di;
+ protected ContainerInterface $di;
- /** @var \App\Settings */
- protected $settings;
+ protected App\Settings $settings;
- /** @var Entity\Repository\SettingsRepository */
- protected $settingsRepo;
+ protected Entity\Repository\SettingsRepository $settingsRepo;
- /** @var Entity\Repository\StationRepository */
- protected $stationRepo;
+ protected Entity\Repository\StationRepository $stationRepo;
- /** @var EntityManagerInterface */
- protected $em;
+ protected EntityManagerInterface $em;
- protected function _inject(\App\Tests\Module $tests_module)
+ protected function _inject(App\Tests\Module $tests_module)
{
$this->di = $tests_module->container;
$this->em = $tests_module->em;
$this->settingsRepo = $this->di->get(Entity\Repository\SettingsRepository::class);
$this->stationRepo = $this->di->get(Entity\Repository\StationRepository::class);
- $this->settings = $this->di->get(\App\Settings::class);
+ $this->settings = $this->di->get(App\Settings::class);
}
public function _after(FunctionalTester $I)
{
- /** @var \App\Auth $auth */
- $auth = $this->di->get(\App\Auth::class);
+ /** @var App\Auth $auth */
+ $auth = $this->di->get(App\Auth::class);
$auth->logout();
$this->em->clear();
- if ($this->test_station instanceof Entity\Station) {
- $this->test_station = $this->em->find(Entity\Station::class, $this->test_station->getId());
+ if (null !== $this->test_station) {
+ $testStation = $this->getTestStation();
- $this->stationRepo->destroy($this->test_station);
+ $this->stationRepo->destroy($testStation);
$this->test_station = null;
$this->em->clear();
}
}
- protected $login_username = 'azuracast@azuracast.com';
- protected $login_password = 'AzuraCastFunctionalTests!';
- protected $login_cookie = null;
-
- /** @var Entity\Station|null */
- protected $test_station = null;
+ protected string $login_username = 'azuracast@azuracast.com';
+ protected string $login_password = 'AzuraCastFunctionalTests!';
+ private ?Entity\Station $test_station = null;
protected function setupIncomplete(FunctionalTester $I)
{
@@ -71,9 +63,7 @@ abstract class CestAbstract
// Create administrator account.
$role = new Entity\Role;
$role->setName('Super Administrator');
-
$this->em->persist($role);
- $this->em->flush();
$rha = new Entity\RolePermission($role);
$rha->setActionName('administer all');
@@ -84,19 +74,18 @@ abstract class CestAbstract
$user->setName('AzuraCast Test User');
$user->setEmail($this->login_username);
$user->setNewPassword($this->login_password);
-
$user->getRoles()->add($role);
$this->em->persist($user);
$this->em->flush();
- $this->di->get(\App\Acl::class)->reload();
+ $this->di->get(App\Acl::class)->reload();
$test_station = new Entity\Station();
$test_station->setName('Functional Test Radio');
$test_station->setDescription('Test radio station.');
- $test_station->setFrontendType(\App\Radio\Adapters::DEFAULT_FRONTEND);
- $test_station->setBackendType(\App\Radio\Adapters::DEFAULT_BACKEND);
+ $test_station->setFrontendType(App\Radio\Adapters::DEFAULT_FRONTEND);
+ $test_station->setBackendType(App\Radio\Adapters::DEFAULT_BACKEND);
$this->test_station = $this->stationRepo->create($test_station);
@@ -105,6 +94,20 @@ abstract class CestAbstract
$this->settingsRepo->setSetting('base_url', 'localhost');
}
+ protected function getTestStation(): Entity\Station
+ {
+ if ($this->test_station instanceof Entity\Station) {
+ $testStation = $this->em->find(Entity\Station::class, $this->test_station->getId());
+ if ($testStation instanceof Entity\Station) {
+ return $testStation;
+ }
+
+ $this->test_station = null;
+ }
+
+ throw new RuntimeException('Test station is not established.');
+ }
+
protected function _cleanTables()
{
$clean_tables = [
@@ -117,8 +120,8 @@ abstract class CestAbstract
$this->em->createQuery('DELETE FROM ' . $clean_table . ' t')->execute();
}
- /** @var \App\Auth $auth */
- $auth = $this->di->get(\App\Auth::class);
+ /** @var App\Auth $auth */
+ $auth = $this->di->get(App\Auth::class);
$auth->logout();
}
@@ -136,16 +139,4 @@ abstract class CestAbstract
$I->seeInSource('Logged in');
}
-
- protected function logout(FunctionalTester $I)
- {
- if (!empty($this->login_cookie)) {
- $I->wantTo('Log out of the application.');
-
- $I->amOnPage('/logout');
- $I->seeInCurrentUrl('/login');
-
- $this->login_cookie = null;
- }
- }
}
diff --git a/tests/functional/D01_Api_StationsCest.php b/tests/functional/D01_Api_StationsCest.php
index adf10724d..bd981ae30 100644
--- a/tests/functional/D01_Api_StationsCest.php
+++ b/tests/functional/D01_Api_StationsCest.php
@@ -1,4 +1,5 @@
wantTo('Check station API endpoints.');
+ $testStation = $this->getTestStation();
+ $station_id = $testStation->getId();
+
$I->sendGET('/api/stations');
$I->seeResponseContainsJson([
- 'name' => $this->test_station->getName(),
+ 'name' => $testStation->getName(),
]);
- $I->sendGET('/api/station/'.$this->test_station->getId());
+ $I->sendGET('/api/station/' . $station_id);
$I->seeResponseContainsJson([
- 'name' => $this->test_station->getName(),
+ 'name' => $testStation->getName(),
]);
}
}
diff --git a/tests/functional/D02_Api_RequestsCest.php b/tests/functional/D02_Api_RequestsCest.php
index 23703bfe8..8d8d2598f 100644
--- a/tests/functional/D02_Api_RequestsCest.php
+++ b/tests/functional/D02_Api_RequestsCest.php
@@ -12,16 +12,19 @@ class D02_Api_RequestsCest extends CestAbstract
$I->wantTo('Check request API endpoints.');
// Enable requests on station.
- $this->test_station->setEnableRequests(true);
- $this->em->persist($this->test_station);
+ $testStation = $this->getTestStation();
+ $station_id = $testStation->getId();
+
+ $testStation->setEnableRequests(true);
+ $this->em->persist($testStation);
$this->em->flush();
// Upload a test song.
$song_src = '/var/azuracast/www/resources/error.mp3';
- $song_dest = $this->test_station->getRadioMediaDir() . '/test.mp3';
+ $song_dest = $testStation->getRadioMediaDir() . '/test.mp3';
copy($song_src, $song_dest);
- $playlist = new Entity\StationPlaylist($this->test_station);
+ $playlist = new Entity\StationPlaylist($testStation);
$playlist->setName('Test Playlist');
$this->em->persist($playlist);
@@ -29,7 +32,7 @@ class D02_Api_RequestsCest extends CestAbstract
/** @var Entity\Repository\StationMediaRepository $media_repo */
$media_repo = $this->di->get(Entity\Repository\StationMediaRepository::class);
- $media = new Entity\StationMedia($this->test_station, 'test.mp3');
+ $media = new Entity\StationMedia($testStation, 'test.mp3');
$media_repo->loadFromFile($media, $song_dest);
$this->em->persist($media);
@@ -38,11 +41,7 @@ class D02_Api_RequestsCest extends CestAbstract
$this->em->persist($spm);
$this->em->flush();
-
- $this->em->refresh($media);
- $this->em->refresh($playlist);
-
- $station_id = $this->test_station->getId();
+ $this->em->clear();
$I->sendGET('/api/station/' . $station_id . '/requests');