@@ -36,15 +36,10 @@ class OrmCacheShell extends Shell {
36
36
* @return boolean
37
37
*/
38
38
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 ) {
45
41
return false ;
46
42
}
47
- $ schema = $ source ->schemaCollection ();
48
43
if (!$ schema ->cacheMetadata ()) {
49
44
$ this ->_io ->verbose ('Metadata cache was disabled in config. Enabling to write cache. ' );
50
45
$ schema ->cacheMetadata (true );
@@ -64,11 +59,13 @@ public function build($name = null) {
64
59
* Clear metadata.
65
60
*
66
61
* @param $name string
67
- * @return void
62
+ * @return boolean
68
63
*/
69
64
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
+ }
72
69
$ tables = [$ name ];
73
70
if (empty ($ name )) {
74
71
$ tables = $ schema ->listTables ();
@@ -91,6 +88,23 @@ public function clear($name = null) {
91
88
$ this ->out ('<success>Cache clear complete</success> ' );
92
89
}
93
90
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
+
94
108
/**
95
109
* Get the option parser for this shell.
96
110
*
0 commit comments