Skip to content

Commit 5c6b44c

Browse files
committed
Extract helper method.
1 parent 038f1fb commit 5c6b44c

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/Console/Command/OrmCacheShell.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,10 @@ class OrmCacheShell extends Shell {
3636
* @return boolean
3737
*/
3838
public function build($name = null) {
39-
$source = ConnectionManager::get($this->params['connection']);
40-
if (!method_exists($source, 'schemaCollection')) {
41-
$msg = sprintf('The "%s" connection is not compatible with orm caching, ' .
42-
'as it does not implement a "schemaCollection()" method.',
43-
$this->params['connection']);
44-
$this->error($msg);
39+
$schema = $this->_getSchema();
40+
if (!$schema) {
4541
return false;
4642
}
47-
$schema = $source->schemaCollection();
4843
if (!$schema->cacheMetadata()) {
4944
$this->_io->verbose('Metadata cache was disabled in config. Enabling to write cache.');
5045
$schema->cacheMetadata(true);
@@ -64,11 +59,13 @@ public function build($name = null) {
6459
* Clear metadata.
6560
*
6661
* @param $name string
67-
* @return void
62+
* @return boolean
6863
*/
6964
public function clear($name = null) {
70-
$source = ConnectionManager::get($this->params['connection']);
71-
$schema = $source->schemaCollection();
65+
$schema = $this->_getSchema();
66+
if (!$schema) {
67+
return false;
68+
}
7269
$tables = [$name];
7370
if (empty($name)) {
7471
$tables = $schema->listTables();
@@ -91,6 +88,23 @@ public function clear($name = null) {
9188
$this->out('<success>Cache clear complete</success>');
9289
}
9390

91+
/**
92+
* Helper method to get the schema collection.
93+
*
94+
* @return \Cake\Database\Schema\Collection
95+
*/
96+
protected function _getSchema() {
97+
$source = ConnectionManager::get($this->params['connection']);
98+
if (!method_exists($source, 'schemaCollection')) {
99+
$msg = sprintf('The "%s" connection is not compatible with orm caching, ' .
100+
'as it does not implement a "schemaCollection()" method.',
101+
$this->params['connection']);
102+
$this->error($msg);
103+
return false;
104+
}
105+
return $source->schemaCollection();
106+
}
107+
94108
/**
95109
* Get the option parser for this shell.
96110
*

0 commit comments

Comments
 (0)