-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathCacheClear.php
More file actions
70 lines (64 loc) · 1.92 KB
/
CacheClear.php
File metadata and controls
70 lines (64 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
namespace Migrations\Command\Phinx;
use Migrations\Util\SchemaTrait;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class CacheClear extends BaseCommand
{
use SchemaTrait;
/**
* Configures the current command.
*
* @return void
*/
protected function configure(): void
{
$this
->setName('orm-cache-clear')
->setDescription(
'Clear all metadata caches for the connection. ' .
'If a table name is provided, only that table will be removed.'
)
->addOption(
'connection',
null,
InputOption::VALUE_OPTIONAL,
'The connection to build/clear metadata cache data for.',
'default'
)
->addArgument(
'name',
InputArgument::OPTIONAL,
'A specific table you want to clear/refresh cached data for.'
);
}
/**
* @inheritDoc
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$schema = $this->_getSchema($input, $output);
/** @var string $name */
$name = $input->getArgument('name');
if (!$schema) {
return static::CODE_ERROR;
}
$tables = [$name];
if (!$name) {
$tables = $schema->listTables();
}
$cacher = $schema->getCacher();
foreach ($tables as $table) {
$output->writeln(sprintf(
'Clearing metadata cache for %s',
$table
));
$cacher->delete($table);
}
$output->writeln('<info>Cache clear complete<info>');
return static::CODE_SUCCESS;
}
}