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 3a5d22d
Show file tree
Hide file tree
Showing 2 changed files with 24 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
39 changes: 23 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,34 @@ 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.');
}
if (! $cache) {
$cacheDriver = $em->getConfiguration()->getQueryCacheImpl();

Check warning on line 74 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-L74

Added lines #L73 - L74 were not covered by tests

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

Check warning on line 77 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#L76-L77

Added lines #L76 - L77 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 81 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#L80-L81

Added lines #L80 - L81 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 85 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#L84-L85

Added lines #L84 - L85 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 92 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#L88-L92

Added lines #L88 - L92 were not covered by tests
}
}

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

0 comments on commit 3a5d22d

Please sign in to comment.