Code Duplication    Length = 72-73 lines in 3 locations

lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php 1 location

@@ 40-112 (lines=73) @@
37
 * @author  Jonathan Wage <[email protected]>
38
 * @author  Roman Borschel <[email protected]>
39
 */
40
class MetadataCommand extends Command
41
{
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function configure()
46
    {
47
        $this->setName('orm:clear-cache:metadata')
48
             ->setDescription('Clear all metadata cache of the various cache drivers')
49
             ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')
50
             ->setHelp(<<<EOT
51
The <info>%command.name%</info> command is meant to clear the metadata cache of associated Entity Manager.
52
It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider
53
instance completely.
54
55
The execution type differ on how you execute the command.
56
If you want to invalidate the entries (and not delete from cache instance), this command would do the work:
57
58
<info>%command.name%</info>
59
60
Alternatively, if you want to flush the cache provider using this command:
61
62
<info>%command.name% --flush</info>
63
64
Finally, be aware that if <info>--flush</info> option is passed, not all cache providers are able to flush entries,
65
because of a limitation of its execution nature.
66
EOT
67
             );
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    protected function execute(InputInterface $input, OutputInterface $output)
74
    {
75
        $ui = new SymfonyStyle($input, $output);
76
77
        $em = $this->getHelper('em')->getEntityManager();
78
        $cacheDriver = $em->getConfiguration()->getMetadataCacheImpl();
79
80
        if ( ! $cacheDriver) {
81
            throw new \InvalidArgumentException('No Metadata cache driver is configured on given EntityManager.');
82
        }
83
84
        if ($cacheDriver instanceof ApcCache) {
85
            throw new \LogicException("Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
86
        }
87
88
        if ($cacheDriver instanceof XcacheCache) {
89
            throw new \LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
90
        }
91
92
        $ui->comment('Clearing <info>all</info> Metadata cache entries');
93
94
        $result  = $cacheDriver->deleteAll();
95
        $message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
96
97
        if (true === $input->getOption('flush')) {
98
            $result  = $cacheDriver->flushAll();
99
            $message = ($result) ? 'Successfully flushed cache entries.' : $message;
100
        }
101
102
        if ( ! $result) {
103
            $ui->error($message);
104
105
            return 1;
106
        }
107
108
        $ui->success($message);
109
110
        return 0;
111
    }
112
}
113

lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php 1 location

@@ 40-111 (lines=72) @@
37
 * @author  Jonathan Wage <[email protected]>
38
 * @author  Roman Borschel <[email protected]>
39
 */
40
class QueryCommand extends Command
41
{
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function configure()
46
    {
47
        $this->setName('orm:clear-cache:query')
48
             ->setDescription('Clear all query cache of the various cache drivers')
49
             ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')
50
             ->setHelp(<<<EOT
51
The <info>%command.name%</info> command is meant to clear the query cache of associated Entity Manager.
52
It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider
53
instance completely.
54
55
The execution type differ on how you execute the command.
56
If you want to invalidate the entries (and not delete from cache instance), this command would do the work:
57
58
<info>%command.name%</info>
59
60
Alternatively, if you want to flush the cache provider using this command:
61
62
<info>%command.name% --flush</info>
63
64
Finally, be aware that if <info>--flush</info> option is passed, not all cache providers are able to flush entries,
65
because of a limitation of its execution nature.
66
EOT
67
             );
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    protected function execute(InputInterface $input, OutputInterface $output)
74
    {
75
        $ui = new SymfonyStyle($input, $output);
76
77
        $em = $this->getHelper('em')->getEntityManager();
78
        $cacheDriver = $em->getConfiguration()->getQueryCacheImpl();
79
80
        if ( ! $cacheDriver) {
81
            throw new \InvalidArgumentException('No Query cache driver is configured on given EntityManager.');
82
        }
83
84
        if ($cacheDriver instanceof ApcCache) {
85
            throw new \LogicException("Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
86
        }
87
        if ($cacheDriver instanceof XcacheCache) {
88
            throw new \LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
89
        }
90
91
        $ui->comment('Clearing <info>all</info> Query cache entries');
92
93
        $result  = $cacheDriver->deleteAll();
94
        $message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
95
96
        if (true === $input->getOption('flush')) {
97
            $result  = $cacheDriver->flushAll();
98
            $message = ($result) ? 'Successfully flushed cache entries.' : $message;
99
        }
100
101
        if ( ! $result) {
102
            $ui->error($message);
103
104
            return 1;
105
        }
106
107
        $ui->success($message);
108
109
        return 0;
110
    }
111
}
112

lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php 1 location

@@ 40-112 (lines=73) @@
37
 * @author  Jonathan Wage <[email protected]>
38
 * @author  Roman Borschel <[email protected]>
39
 */
40
class ResultCommand extends Command
41
{
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function configure()
46
    {
47
        $this->setName('orm:clear-cache:result')
48
             ->setDescription('Clear all result cache of the various cache drivers')
49
             ->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')
50
             ->setHelp(<<<EOT
51
The <info>%command.name%</info> command is meant to clear the result cache of associated Entity Manager.
52
It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider
53
instance completely.
54
55
The execution type differ on how you execute the command.
56
If you want to invalidate the entries (and not delete from cache instance), this command would do the work:
57
58
<info>%command.name%</info>
59
60
Alternatively, if you want to flush the cache provider using this command:
61
62
<info>%command.name% --flush</info>
63
64
Finally, be aware that if <info>--flush</info> option is passed, not all cache providers are able to flush entries,
65
because of a limitation of its execution nature.
66
EOT
67
             );
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    protected function execute(InputInterface $input, OutputInterface $output)
74
    {
75
        $ui = new SymfonyStyle($input, $output);
76
77
        $em = $this->getHelper('em')->getEntityManager();
78
        $cacheDriver = $em->getConfiguration()->getResultCacheImpl();
79
80
        if ( ! $cacheDriver) {
81
            throw new \InvalidArgumentException('No Result cache driver is configured on given EntityManager.');
82
        }
83
84
        if ($cacheDriver instanceof ApcCache) {
85
            throw new \LogicException("Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
86
        }
87
88
        if ($cacheDriver instanceof XcacheCache) {
89
            throw new \LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
90
        }
91
92
        $ui->comment('Clearing <info>all</info> Result cache entries');
93
94
        $result  = $cacheDriver->deleteAll();
95
        $message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
96
97
        if (true === $input->getOption('flush')) {
98
            $result  = $cacheDriver->flushAll();
99
            $message = ($result) ? 'Successfully flushed cache entries.' : $message;
100
        }
101
102
        if ( ! $result) {
103
            $ui->error($message);
104
105
            return 1;
106
        }
107
108
        $ui->success($message);
109
110
        return 0;
111
    }
112
}
113