Skip to content

Commit

Permalink
Extract helper method.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed May 20, 2014
1 parent 038f1fb commit 5c6b44c
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/Console/Command/OrmCacheShell.php
Expand Up @@ -36,15 +36,10 @@ class OrmCacheShell extends Shell {
* @return boolean
*/
public function build($name = null) {
$source = ConnectionManager::get($this->params['connection']);
if (!method_exists($source, 'schemaCollection')) {
$msg = sprintf('The "%s" connection is not compatible with orm caching, ' .
'as it does not implement a "schemaCollection()" method.',
$this->params['connection']);
$this->error($msg);
$schema = $this->_getSchema();
if (!$schema) {
return false;
}
$schema = $source->schemaCollection();
if (!$schema->cacheMetadata()) {
$this->_io->verbose('Metadata cache was disabled in config. Enabling to write cache.');
$schema->cacheMetadata(true);
Expand All @@ -64,11 +59,13 @@ public function build($name = null) {
* Clear metadata.
*
* @param $name string
* @return void
* @return boolean
*/
public function clear($name = null) {
$source = ConnectionManager::get($this->params['connection']);
$schema = $source->schemaCollection();
$schema = $this->_getSchema();
if (!$schema) {
return false;
}
$tables = [$name];
if (empty($name)) {
$tables = $schema->listTables();
Expand All @@ -91,6 +88,23 @@ public function clear($name = null) {
$this->out('<success>Cache clear complete</success>');
}

/**
* Helper method to get the schema collection.
*
* @return \Cake\Database\Schema\Collection
*/
protected function _getSchema() {
$source = ConnectionManager::get($this->params['connection']);
if (!method_exists($source, 'schemaCollection')) {
$msg = sprintf('The "%s" connection is not compatible with orm caching, ' .
'as it does not implement a "schemaCollection()" method.',
$this->params['connection']);
$this->error($msg);
return false;
}
return $source->schemaCollection();
}

/**
* Get the option parser for this shell.
*
Expand Down

0 comments on commit 5c6b44c

Please sign in to comment.