Skip to content

Commit

Permalink
Other solution
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jul 26, 2023
1 parent ddc7d95 commit a5161e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function setResultCache(CacheItemPoolInterface $cache): void
*/
public function getQueryCacheImpl()
{
Deprecation::triggerIfCalledFromOutside(
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/9002',
'Method %s() is deprecated and will be removed in Doctrine ORM 3.0. Use getQueryCache() instead.',
Expand Down
40 changes: 24 additions & 16 deletions lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,35 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();

$em = $this->getEntityManager($input);
$cache = $em->getConfiguration()->getQueryCache();
$cacheDriver = $em->getConfiguration()->getQueryCacheImpl();
$em = $this->getEntityManager($input);
$cache = $em->getConfiguration()->getQueryCache();

Check warning on line 67 in lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php

View check run for this annotation

Codecov / codecov/patch

lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php#L66-L67

Added lines #L66 - L67 were not covered by tests

if (! $cacheDriver) {
throw new InvalidArgumentException('No Query cache driver is configured on given EntityManager.');
}

if ($cacheDriver instanceof ApcCache || $cache instanceof ApcuAdapter) {
if ($cache instanceof ApcuAdapter) {

Check warning on line 69 in lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php

View check run for this annotation

Codecov / codecov/patch

lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php#L69

Added line #L69 was not covered by tests
throw new LogicException('Cannot clear APCu Cache from Console, it\'s shared in the Webserver memory and not accessible from the CLI.');
}

if ($cacheDriver instanceof XcacheCache) {
throw new LogicException('Cannot clear XCache Cache from Console, it\'s shared in the Webserver memory and not accessible from the CLI.');
}
$cacheDriver = null;
if (! $cache) {
$cacheDriver = $em->getConfiguration()->getQueryCacheImpl();

Check warning on line 75 in lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php

View check run for this annotation

Codecov / codecov/patch

lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php#L73-L75

Added lines #L73 - L75 were not covered by tests

if (! $cacheDriver) {
throw new InvalidArgumentException('No Query cache driver is configured on given EntityManager.');

Check warning on line 78 in lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php

View check run for this annotation

Codecov / codecov/patch

lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php#L77-L78

Added lines #L77 - L78 were not covered by tests
}

if ($cacheDriver instanceof ApcCache) {
throw new LogicException('Cannot clear APCu Cache from Console, it\'s shared in the Webserver memory and not accessible from the CLI.');

Check warning on line 82 in lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php

View check run for this annotation

Codecov / codecov/patch

lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php#L81-L82

Added lines #L81 - L82 were not covered by tests
}

if (! ($cacheDriver instanceof ClearableCache)) {
throw new LogicException(sprintf(
'Can only clear cache when ClearableCache interface is implemented, %s does not implement.',
get_debug_type($cacheDriver)
));
if ($cacheDriver instanceof XcacheCache) {
throw new LogicException('Cannot clear XCache Cache from Console, it\'s shared in the Webserver memory and not accessible from the CLI.');

Check warning on line 86 in lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php

View check run for this annotation

Codecov / codecov/patch

lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php#L85-L86

Added lines #L85 - L86 were not covered by tests
}

if (! ($cacheDriver instanceof ClearableCache)) {
throw new LogicException(sprintf(
'Can only clear cache when ClearableCache interface is implemented, %s does not implement.',
get_debug_type($cacheDriver)
));

Check warning on line 93 in lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php

View check run for this annotation

Codecov / codecov/patch

lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php#L89-L93

Added lines #L89 - L93 were not covered by tests
}
}

$ui->comment('Clearing <info>all</info> Query cache entries');
Expand Down

0 comments on commit a5161e9

Please sign in to comment.