Browse Source

Fix orm_cache tool when metadata cache is disabled.

Fix error from when metadata cache was refactored. Add missing tests.

Refs #5061
Mark Story 11 years ago
parent
commit
5d60a08037
2 changed files with 33 additions and 8 deletions
  1. 5 8
      src/Shell/OrmCacheShell.php
  2. 28 0
      tests/TestCase/Shell/OrmCacheShellTest.php

+ 5 - 8
src/Shell/OrmCacheShell.php

@@ -40,10 +40,6 @@ class OrmCacheShell extends Shell {
 		if (!$schema) {
 			return false;
 		}
-		if (!$schema->cacheMetadata()) {
-			$this->_io->verbose('Metadata cache was disabled in config. Enabling to write cache.');
-			$schema->cacheMetadata(true);
-		}
 		$tables = [$name];
 		if (empty($name)) {
 			$tables = $schema->listTables();
@@ -71,10 +67,6 @@ class OrmCacheShell extends Shell {
 		if (empty($name)) {
 			$tables = $schema->listTables();
 		}
-		if (!$schema->cacheMetadata()) {
-			$this->_io->verbose('Metadata cache was disabled in config. Enabling to clear cache.');
-			$schema->cacheMetadata(true);
-		}
 		$configName = $schema->cacheMetadata();
 
 		foreach ($tables as $table) {
@@ -104,6 +96,11 @@ class OrmCacheShell extends Shell {
 			$this->error($msg);
 			return false;
 		}
+		$config = $source->config();
+		if (empty($config['cacheMetadata'])) {
+			$this->_io->verbose('Metadata cache was disabled in config. Enabling to clear cache.');
+			$source->cacheMetadata(true);
+		}
 		return $source->schemaCollection();
 	}
 

+ 28 - 0
tests/TestCase/Shell/OrmCacheShellTest.php

@@ -65,6 +65,34 @@ class OrmCacheShellTest extends TestCase {
 	}
 
 /**
+ * Test that clear enables the cache if it was disabled.
+ *
+ * @return void
+ */
+	public function testClearEnablesMetadataCache() {
+		$ds = ConnectionManager::get('test');
+		$ds->cacheMetadata(false);
+
+		$this->shell->params['connection'] = 'test';
+		$this->shell->clear();
+		$this->assertInstanceOf('Cake\Database\Schema\CachedCollection', $ds->schemaCollection());
+	}
+
+/**
+ * Test that build enables the cache if it was disabled.
+ *
+ * @return void
+ */
+	public function testBuildEnablesMetadataCache() {
+		$ds = ConnectionManager::get('test');
+		$ds->cacheMetadata(false);
+
+		$this->shell->params['connection'] = 'test';
+		$this->shell->build();
+		$this->assertInstanceOf('Cake\Database\Schema\CachedCollection', $ds->schemaCollection());
+	}
+
+/**
  * Test build() with no args.
  *
  * @return void