Merge pull request #92 from simonwelsh/fulltextsearch-fix

BUGFIX fulltext fixes.
This commit is contained in:
Will Rossiter 2011-10-28 21:00:42 -07:00
commit 3c16af3aca
2 changed files with 29 additions and 8 deletions

View File

@ -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) {

View File

@ -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]}')");
Object::add_static_var($class, 'create_table_options', array('MySQLDatabase' => 'ENGINE=MyISAM'));
} else {