From f976af78be805e1a359288fd17bc1db329e81b82 Mon Sep 17 00:00:00 2001 From: Simon Welsh Date: Sat, 29 Oct 2011 16:47:18 +1300 Subject: [PATCH 1/2] BUGFIX: Apply engine changes only if there is no existing FulltextSearch index on the table, and apply them before column index changes. --- model/MySQLDatabase.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/model/MySQLDatabase.php b/model/MySQLDatabase.php index 535c740a7..9ebfaa614 100644 --- a/model/MySQLDatabase.php +++ b/model/MySQLDatabase.php @@ -258,17 +258,35 @@ class MySQLDatabase extends SS_Database { $alterList[] .= "DROP INDEX \"$k\""; $alterList[] .= "ADD ". $this->getIndexSqlDefinition($k, $v); } + + if($alteredOptions && isset($alteredOptions[get_class($this)])) { + if(!isset($this->indexList[$tableName])) { + $this->indexList[$tableName] = $this->indexList($tableName); + } + + $skip = false; + foreach($this->indexList[$tableName] as $index) { + if(strpos($index, 'fulltext ') === 0) { + $skip = true; + break; + } + } + if($skip) { + DB::alteration_message( + sprintf("Table %s options not changed to %s due to fulltextsearch index", $tableName, $alteredOptions[get_class($this)]), + "changed" + ); + } else { + $this->query(sprintf("ALTER TABLE \"%s\" %s", $tableName, $alteredOptions[get_class($this)])); + DB::alteration_message( + sprintf("Table %s options changed: %s", $tableName, $alteredOptions[get_class($this)]), + "changed" + ); + } + } $alterations = implode(",\n", $alterList); $this->query("ALTER TABLE \"$tableName\" $alterations"); - - if($alteredOptions && isset($alteredOptions[get_class($this)])) { - $this->query(sprintf("ALTER TABLE \"%s\" %s", $tableName, $alteredOptions[get_class($this)])); - DB::alteration_message( - sprintf("Table %s options changed: %s", $tableName, $alteredOptions[get_class($this)]), - "changed" - ); - } } public function isView($tableName) { From 25602811f274cbe2f8870fbdb8f36c4adb9a00c9 Mon Sep 17 00:00:00 2001 From: Simon Welsh Date: Sat, 29 Oct 2011 16:48:09 +1300 Subject: [PATCH 2/2] BUGFIX: FulltextSearchable::enable() needs to replace the static on the decorated class iff the database engine is for MySQL --- search/FulltextSearchable.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/search/FulltextSearchable.php b/search/FulltextSearchable.php index eaa786a5f..d18e0d8ea 100644 --- a/search/FulltextSearchable.php +++ b/search/FulltextSearchable.php @@ -49,6 +49,9 @@ class FulltextSearchable extends DataExtension { if(!class_exists($class)) continue; if(isset($defaultColumns[$class])) { + if(DB::getConn()->getDatabaseServer() == 'mysql') { + Object::add_static_var($class, 'create_table_options', array('MySQLDatabase' => 'ENGINE=MyISAM'), true); + } Object::add_extension($class, "FulltextSearchable('{$defaultColumns[$class]}')"); } else { throw new Exception("FulltextSearchable::enable() I don't know the default search columns for class '$class'");