From b04a1ab41c4051923e9d9a9af5dedfa5a3ef67d8 Mon Sep 17 00:00:00 2001 From: James Pluck Date: Mon, 14 Aug 2017 15:22:19 +1200 Subject: [PATCH 1/2] Fix Truncate Error Issue when using views in a Unittest. When using a view in a SilverStripe project, whenever the tear down scripts for the Unittests are run the following error occurs: Couldn't run query: TRUNCATE "ActivityPoints_view" Table 'ss_tmpdb2391727.ActivityPoints_view' doesn't exist This was due to the MySQLSchemaManager::tableList() function assuming that all records in the TABLES were actual tables containing data. This small tweak fixes the issue by modifying the SQL to filter out views from the list before truncating. --- model/connect/MySQLSchemaManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/connect/MySQLSchemaManager.php b/model/connect/MySQLSchemaManager.php index 8bb0f4424..ef9bf6ed7 100644 --- a/model/connect/MySQLSchemaManager.php +++ b/model/connect/MySQLSchemaManager.php @@ -336,7 +336,7 @@ class MySQLSchemaManager extends DBSchemaManager { public function tableList() { $tables = array(); - foreach ($this->query("SHOW TABLES") as $record) { + foreach ($this->query("SHOW FULL TABLES WHERE Table_Type != 'VIEW'") as $record) { $table = reset($record); $tables[strtolower($table)] = $table; } From 7b200a2a642a78bffcf0a2f417a4757fb216ecfb Mon Sep 17 00:00:00 2001 From: Christopher Joe Date: Tue, 29 Aug 2017 10:34:50 +1200 Subject: [PATCH 2/2] Fix add combinedFiles to clear logic --- view/Requirements.php | 45 ++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/view/Requirements.php b/view/Requirements.php index 971b943e4..a39d0e998 100644 --- a/view/Requirements.php +++ b/view/Requirements.php @@ -744,25 +744,24 @@ class Requirements_Backend { * @param string|int $fileOrID */ public function clear($fileOrID = null) { - if($fileOrID) { - foreach(array('javascript','css', 'customScript', 'customCSS', 'customHeadTags') as $type) { - if(isset($this->{$type}[$fileOrID])) { + $types = array( + 'javascript', + 'css', + 'customScript', + 'customCSS', + 'customHeadTags', + 'combine_files', + ); + foreach ($types as $type) { + if ($fileOrID) { + if (isset($this->{$type}[$fileOrID])) { $this->disabled[$type][$fileOrID] = $this->{$type}[$fileOrID]; unset($this->{$type}[$fileOrID]); } + } else { + $this->disabled[$type] = $this->{$type}; + $this->{$type} = array(); } - } else { - $this->disabled['javascript'] = $this->javascript; - $this->disabled['css'] = $this->css; - $this->disabled['customScript'] = $this->customScript; - $this->disabled['customCSS'] = $this->customCSS; - $this->disabled['customHeadTags'] = $this->customHeadTags; - - $this->javascript = array(); - $this->css = array(); - $this->customScript = array(); - $this->customCSS = array(); - $this->customHeadTags = array(); } } @@ -770,11 +769,17 @@ class Requirements_Backend { * Restore requirements cleared by call to Requirements::clear */ public function restore() { - $this->javascript = $this->disabled['javascript']; - $this->css = $this->disabled['css']; - $this->customScript = $this->disabled['customScript']; - $this->customCSS = $this->disabled['customCSS']; - $this->customHeadTags = $this->disabled['customHeadTags']; + $types = array( + 'javascript', + 'css', + 'customScript', + 'customCSS', + 'customHeadTags', + 'combine_files', + ); + foreach ($types as $type) { + $this->{$type} = $this->disabled[$type]; + } } /** * Block inclusion of a specific file