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 @@ 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();

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) {
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();

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

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.');
}

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.');
}

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)
));
}
}

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

$result = $cache ? $cache->clear() : $cacheDriver->deleteAll();
if ($cache) {
$result = $cache->clear();
} else {
assert($cacheDriver !== null);
greg0ire marked this conversation as resolved.
Show resolved Hide resolved
$result = $cacheDriver->deleteAll();
}

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

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