Skip to content

Commit

Permalink
Get rid of the remainder of doctrine deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Oct 24, 2023
1 parent b8353f9 commit e2c72ec
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 27 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4",
"phpstan/phpstan": "^1.9.2",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-doctrine": "^1",
"phpstan/phpstan-symfony": "^1.1",
"phpstan/phpstan-webmozart-assert": "^1.2",
Expand Down
50 changes: 49 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ includes:
- vendor/phpstan/phpstan-symfony/rules.neon
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
- vendor/staabm/phpstan-dba/config/dba.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon

parameters:
level: 8
Expand Down
5 changes: 3 additions & 2 deletions src/Command/IndexPackagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use App\Model\DownloadManager;
use App\Model\FavoriteManager;
use Composer\Pcre\Preg;
use Doctrine\DBAL\ArrayParameterType;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -320,7 +321,7 @@ private function updateIndexedAt(array $idsToUpdate, string $time): void
'ids' => $idsToUpdate,
'indexed' => $time,
],
['ids' => Connection::PARAM_INT_ARRAY]
['ids' => ArrayParameterType::INTEGER]
);

// make sure that packages where crawledAt is set in far future do not get indexed repeatedly
Expand All @@ -330,7 +331,7 @@ private function updateIndexedAt(array $idsToUpdate, string $time): void
'ids' => $idsToUpdate,
'tomorrow' => date('Y-m-d H:i:s', strtotime('+1day')),
],
['ids' => Connection::PARAM_INT_ARRAY]
['ids' => ArrayParameterType::INTEGER]
);
} catch (\Exception $e) {
if (!$retries) {
Expand Down
3 changes: 2 additions & 1 deletion src/Entity/JobRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace App\Entity;

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\Persistence\ManagerRegistry;

Expand Down Expand Up @@ -91,7 +92,7 @@ public function findLatestExecutedJob(int $packageId, string $type): ?Job
'statuses' => [Job::STATUS_COMPLETED, Job::STATUS_ERRORED, Job::STATUS_FAILED],
'type' => $type,
],
['statuses' => Connection::PARAM_STR_ARRAY]
['statuses' => ArrayParameterType::STRING]
);
if ($id) {
return $this->find($id);
Expand Down
9 changes: 5 additions & 4 deletions src/Entity/SecurityAdvisoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use App\SecurityAdvisory\FriendsOfPhpSecurityAdvisoriesSource;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\Persistence\ManagerRegistry;
use Predis\Client;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function getPackageAdvisoriesWithSources(array $packageNames, string $sou
->innerJoin('a.sources', 's')
->innerJoin('a.sources', 'query')
->where('query.source = :source OR a.packageName IN (:packageNames)')
->setParameter('packageNames', $packageNames, Connection::PARAM_STR_ARRAY)
->setParameter('packageNames', $packageNames, ArrayParameterType::STRING)
->setParameter('source', $sourceName)
->getQuery()
->getResult();
Expand Down Expand Up @@ -130,7 +131,7 @@ public function searchSecurityAdvisories(array $packageNames, int $updatedSince)
$types = [];
if ($filterByNames) {
$params['packageNames'] = $packageNames;
$types['packageNames'] = Connection::PARAM_STR_ARRAY;
$types['packageNames'] = ArrayParameterType::STRING;
}

$result = $this->getEntityManager()->getConnection()->fetchAllAssociative($sql, $params, $types);
Expand Down Expand Up @@ -173,12 +174,12 @@ public function getAdvisoryIdsAndVersions(array $packageNames): array
ORDER BY s.id DESC';

$params['packageNames'] = $packageNames;
$types['packageNames'] = Connection::PARAM_STR_ARRAY;
$types['packageNames'] = ArrayParameterType::STRING;

$rows = $this->getEntityManager()->getConnection()->fetchAllAssociative(
$sql,
['packageNames' => $packageNames],
['packageNames' => Connection::PARAM_STR_ARRAY]
['packageNames' => ArrayParameterType::STRING]
);

$results = [];
Expand Down
14 changes: 7 additions & 7 deletions src/Entity/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Version
/**
* @var Collection<int, Tag>&Selectable<int, Tag>
*/
#[ORM\ManyToMany(targetEntity: Tag::class, inversedBy: 'versions')]
#[ORM\ManyToMany(targetEntity: Tag::class, inversedBy: 'versions', cascade: ['persist', 'detach'])]
#[ORM\JoinTable(name: 'version_tag')]
#[ORM\JoinColumn(name: 'version_id', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
Expand Down Expand Up @@ -122,37 +122,37 @@ class Version
/**
* @var Collection<int, RequireLink>&Selectable<int, RequireLink>
*/
#[ORM\OneToMany(targetEntity: 'App\Entity\RequireLink', mappedBy: 'version')]
#[ORM\OneToMany(targetEntity: 'App\Entity\RequireLink', mappedBy: 'version', cascade: ['persist', 'detach'])]
private Collection $require;

/**
* @var Collection<int, ReplaceLink>&Selectable<int, ReplaceLink>
*/
#[ORM\OneToMany(targetEntity: 'App\Entity\ReplaceLink', mappedBy: 'version')]
#[ORM\OneToMany(targetEntity: 'App\Entity\ReplaceLink', mappedBy: 'version', cascade: ['persist', 'detach'])]
private Collection $replace;

/**
* @var Collection<int, ConflictLink>&Selectable<int, ConflictLink>
*/
#[ORM\OneToMany(targetEntity: 'App\Entity\ConflictLink', mappedBy: 'version')]
#[ORM\OneToMany(targetEntity: 'App\Entity\ConflictLink', mappedBy: 'version', cascade: ['persist', 'detach'])]
private Collection $conflict;

/**
* @var Collection<int, ProvideLink>&Selectable<int, ProvideLink>
*/
#[ORM\OneToMany(targetEntity: 'App\Entity\ProvideLink', mappedBy: 'version')]
#[ORM\OneToMany(targetEntity: 'App\Entity\ProvideLink', mappedBy: 'version', cascade: ['persist', 'detach'])]
private Collection $provide;

/**
* @var Collection<int, DevRequireLink>&Selectable<int, DevRequireLink>
*/
#[ORM\OneToMany(targetEntity: 'App\Entity\DevRequireLink', mappedBy: 'version')]
#[ORM\OneToMany(targetEntity: 'App\Entity\DevRequireLink', mappedBy: 'version', cascade: ['persist', 'detach'])]
private Collection $devRequire;

/**
* @var Collection<int, SuggestLink>&Selectable<int, SuggestLink>
*/
#[ORM\OneToMany(targetEntity: 'App\Entity\SuggestLink', mappedBy: 'version')]
#[ORM\OneToMany(targetEntity: 'App\Entity\SuggestLink', mappedBy: 'version', cascade: ['persist', 'detach'])]
private Collection $suggest;

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Entity/VersionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace App\Entity;

use App\Model\VersionIdCache;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -139,7 +140,7 @@ public function getVersionData(array $versionIds): array
$rows = $this->getEntityManager()->getConnection()->fetchAllAssociative(
'SELECT version_id, packageName name, packageVersion version FROM '.$table.' WHERE version_id IN (:ids)',
['ids' => $versionIds],
['ids' => Connection::PARAM_INT_ARRAY]
['ids' => ArrayParameterType::INTEGER]
);
foreach ($rows as $row) {
$result[$row['version_id']][$link][] = $row;
Expand All @@ -149,7 +150,7 @@ public function getVersionData(array $versionIds): array
$rows = $this->getEntityManager()->getConnection()->fetchAllAssociative(
'SELECT vt.version_id, name FROM tag t JOIN version_tag vt ON vt.tag_id = t.id WHERE vt.version_id IN (:ids)',
['ids' => $versionIds],
['ids' => Connection::PARAM_INT_ARRAY]
['ids' => ArrayParameterType::INTEGER]
);
foreach ($rows as $row) {
$versionId = $row['version_id'];
Expand Down
3 changes: 2 additions & 1 deletion src/EventListener/SecurityAdvisoryUpdateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Entity\SecurityAdvisory;
use App\Util\DoctrineTrait;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
use Doctrine\Persistence\Event\LifecycleEventArgs;
Expand Down Expand Up @@ -67,7 +68,7 @@ public function flushChangesToPackages(): void
$pkg = $this->getEM()->getConnection()->executeStatement(
'UPDATE package SET dumpedAtV2 = null WHERE name IN (:names)',
['names' => $packageNames],
['names' => Connection::PARAM_STR_ARRAY]
['names' => ArrayParameterType::STRING]
);

$this->packagesToMarkStale = [];
Expand Down
3 changes: 2 additions & 1 deletion src/Model/DownloadManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace App\Model;

use Composer\Pcre\Preg;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\DBAL\Connection;
use App\Entity\Package;
Expand Down Expand Up @@ -212,7 +213,7 @@ public function transferDownloadsToDb(int $packageId, array $keys, DateTimeImmut
$versionIds = $this->getEM()->getConnection()->fetchFirstColumn(
'SELECT id FROM package_version WHERE id IN (:ids)',
['ids' => array_keys($versionsWithDownloads)],
['ids' => Connection::PARAM_INT_ARRAY]
['ids' => ArrayParameterType::INTEGER]
);
$versionIds = array_map('intval', $versionIds);
unset($versionsWithDownloads);
Expand Down
3 changes: 2 additions & 1 deletion src/Package/SymlinkDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace App\Package;

use Composer\Pcre\Preg;
use Doctrine\DBAL\ArrayParameterType;
use Seld\Signal\SignalHandler;
use Symfony\Component\Filesystem\Filesystem;
use Composer\Util\Filesystem as ComposerFilesystem;
Expand Down Expand Up @@ -430,7 +431,7 @@ public function dump(array $packageIds, bool $force = false, bool $verbose = fal
'ids' => $ids,
'dumped' => $dt,
],
['ids' => Connection::PARAM_INT_ARRAY]
['ids' => ArrayParameterType::INTEGER]
);
break;
} catch (\Exception $e) {
Expand Down
8 changes: 5 additions & 3 deletions src/Package/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use App\Entity\SuggestLink;
use App\Model\ProviderManager;
use App\Model\VersionIdCache;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\DBAL\Connection;
use App\Service\VersionCache;
Expand Down Expand Up @@ -183,8 +184,9 @@ public function update(IOInterface $io, Config $config, Package $package, VcsRep
if ($result['updated']) {
assert($result['object'] instanceof Version);
$em->flush();
$em->clear();
$package = $em->merge($package);

// detach version once flushed to avoid gathering lots of data in memory
$em->detach($result['object']);

$this->versionIdCache->insertVersion($package, $result['object']);
$versionId = $result['object']->getId();
Expand Down Expand Up @@ -213,7 +215,7 @@ public function update(IOInterface $io, Config $config, Package $package, VcsRep
$em->getConnection()->executeStatement(
'UPDATE package_version SET updatedAt = :now, softDeletedAt = NULL WHERE id IN (:ids) AND softDeletedAt IS NOT NULL',
['now' => date('Y-m-d H:i:s'), 'ids' => $idsToMarkUpdated],
['ids' => Connection::PARAM_INT_ARRAY]
['ids' => ArrayParameterType::INTEGER]
);

// remove outdated versions
Expand Down
3 changes: 2 additions & 1 deletion src/Package/V2Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use App\Entity\SecurityAdvisory;
use Composer\Pcre\Preg;
use Doctrine\DBAL\ArrayParameterType;
use Symfony\Component\Filesystem\Filesystem;
use Composer\MetadataMinifier\MetadataMinifier;
use Doctrine\Persistence\ManagerRegistry;
Expand Down Expand Up @@ -159,7 +160,7 @@ public function dump(array $packageIds, bool $force = false, bool $verbose = fal
'ids' => $ids,
'dumped' => $dt,
],
['ids' => Connection::PARAM_INT_ARRAY]
['ids' => ArrayParameterType::INTEGER]
);
break;
} catch (\Exception $e) {
Expand Down
1 change: 0 additions & 1 deletion src/Service/UpdaterWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ public function process(Job $job, SignalHandler $signal): array
// perform the actual update (fetch and re-scan the repository's source)
$package = $this->updater->update($io, $config, $package, $repository, $flags, $existingVersions, $versionCache);

$emptyRefCache = $em->merge($emptyRefCache);
$emptyRefCache->setEmptyReferences($repository->getEmptyReferences());
$em->persist($emptyRefCache);
$em->flush();
Expand Down
4 changes: 2 additions & 2 deletions src/Twig/PackagistExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public function generateGravatarHash(string $email): string
public function sortLinks(array $links): array
{
usort($links, static function (PackageLink $a, PackageLink $b) {
$aPlatform = Preg::isMatch(PlatformRepository::PLATFORM_PACKAGE_REGEX, $a->getPackageName());
$bPlatform = Preg::isMatch(PlatformRepository::PLATFORM_PACKAGE_REGEX, $b->getPackageName());
$aPlatform = PlatformRepository::isPlatformPackage($a->getPackageName());
$bPlatform = PlatformRepository::isPlatformPackage($b->getPackageName());

if ($aPlatform !== $bPlatform) {
return $aPlatform ? -1 : 1;
Expand Down

0 comments on commit e2c72ec

Please sign in to comment.