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

Fix/Self deprecation with getQueryCacheImpl #10856

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

use function assert;
use function get_debug_type;
use function sprintf;

Expand Down Expand Up @@ -63,32 +64,46 @@
{
$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 68 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#L67-L68

Added lines #L67 - L68 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 70 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#L70

Added line #L70 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 76 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#L74-L76

Added lines #L74 - L76 were not covered by tests

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

Check warning on line 79 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#L78-L79

Added lines #L78 - L79 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 83 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#L82-L83

Added lines #L82 - L83 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 87 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#L86-L87

Added lines #L86 - L87 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 94 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#L90-L94

Added lines #L90 - L94 were not covered by tests
}
}

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

$result = $cache ? $cache->clear() : $cacheDriver->deleteAll();
if ($cache) {
$result = $cache->clear();

Check warning on line 101 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#L100-L101

Added lines #L100 - L101 were not covered by tests
} else {
assert($cacheDriver !== null);
greg0ire marked this conversation as resolved.
Show resolved Hide resolved
$result = $cacheDriver->deleteAll();

Check warning on line 104 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#L103-L104

Added lines #L103 - L104 were not covered by tests
}

$message = $result ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';

if ($input->getOption('flush') === true && ! $cache) {
Expand Down