Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added condition to check that we have an active connection #474

Open
wants to merge 3 commits into
base: 3.3.x
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 23 additions & 18 deletions Collector/MigrationsCollector.php
Expand Up @@ -10,6 +10,10 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Throwable;

use function count;
use function get_class;

class MigrationsCollector extends DataCollector
{
Expand All @@ -21,17 +25,22 @@ class MigrationsCollector extends DataCollector
public function __construct(DependencyFactory $dependencyFactory, MigrationsFlattener $migrationsFlattener)
{
$this->dependencyFactory = $dependencyFactory;
$this->flattener = $migrationsFlattener;
$this->flattener = $migrationsFlattener;
}

public function collect(Request $request, Response $response, \Throwable $exception = null)
public function collect(Request $request, Response $response, ?Throwable $exception = null)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that running phpcbf is adding return type.

{
if (!empty($this->data)) {
if (! empty($this->data)) {
return;
}

$connection = $this->dependencyFactory->getConnection();
if (! $connection->isConnected()) {
return;
}

$metadataStorage = $this->dependencyFactory->getMetadataStorage();
$planCalculator = $this->dependencyFactory->getMigrationPlanCalculator();
$planCalculator = $this->dependencyFactory->getMigrationPlanCalculator();

try {
$executedMigrations = $metadataStorage->getExecutedMigrations();
Expand All @@ -46,33 +55,29 @@ public function collect(Request $request, Response $response, \Throwable $except

$availableMigrations = $planCalculator->getMigrations();

$this->data['available_migrations_count'] = count($availableMigrations);
$unavailableMigrations = $executedMigrations->unavailableSubset($availableMigrations);
$this->data['available_migrations_count'] = count($availableMigrations);
$unavailableMigrations = $executedMigrations->unavailableSubset($availableMigrations);
$this->data['unavailable_migrations_count'] = count($unavailableMigrations);

$newMigrations = $availableMigrations->newSubset($executedMigrations);
$this->data['new_migrations'] = $this->flattener->flattenAvailableMigrations($newMigrations);
$newMigrations = $availableMigrations->newSubset($executedMigrations);
$this->data['new_migrations'] = $this->flattener->flattenAvailableMigrations($newMigrations);
$this->data['executed_migrations'] = $this->flattener->flattenExecutedMigrations($executedMigrations, $availableMigrations);

$this->data['storage'] = get_class($metadataStorage);
$configuration = $this->dependencyFactory->getConfiguration();
$storage = $configuration->getMetadataStorageConfiguration();
$configuration = $this->dependencyFactory->getConfiguration();
$storage = $configuration->getMetadataStorageConfiguration();
if ($storage instanceof TableMetadataStorageConfiguration) {
$this->data['table'] = $storage->getTableName();
$this->data['table'] = $storage->getTableName();
$this->data['column'] = $storage->getVersionColumnName();
}

$connection = $this->dependencyFactory->getConnection();
$this->data['driver'] = get_class($connection->getDriver());
$this->data['name'] = $connection->getDatabase();
$this->data['name'] = $connection->getDatabase();

$this->data['namespaces'] = $configuration->getMigrationDirectories();
}

/**
* @return string
*/
public function getName()
public function getName(): string
{
return 'doctrine_migrations';
}
Expand All @@ -82,7 +87,7 @@ public function getData()
return $this->data;
}

public function reset()
public function reset(): void
{
$this->data = [];
}
Expand Down