ENHANCEMENT Automatic checking of fulltext support by looking into the sys.databases table for MSSQLDatabase

This commit is contained in:
Sean Harvey 2010-02-03 08:11:31 +00:00
parent 7d67d25402
commit adef3ced70

View File

@ -36,12 +36,6 @@ class MSSQLDatabase extends SS_Database {
*/ */
protected $database; protected $database;
/**
* Does this database have full-text support?
* @var boolean
*/
protected $fullTextEnabled = true;
/** /**
* If true, use the mssql_... functions. * If true, use the mssql_... functions.
* If false use the sqlsrv_... functions * If false use the sqlsrv_... functions
@ -116,6 +110,17 @@ class MSSQLDatabase extends SS_Database {
} }
} }
/**
* Checks whether the current database as fulltext
* support enabled or not by looking into the
* system database table.
*
* @return boolean
*/
public function fullTextEnabled() {
return (boolean) DB::query("SELECT is_fulltext_enabled FROM sys.databases WHERE name = '$this->database'");
}
/** /**
* Throw a database error * Throw a database error
*/ */
@ -139,7 +144,7 @@ class MSSQLDatabase extends SS_Database {
* TODO: VERY IMPORTANT: move this so it only gets called upon a dev/build action * TODO: VERY IMPORTANT: move this so it only gets called upon a dev/build action
*/ */
function createFullTextCatalog(){ function createFullTextCatalog(){
if($this->fullTextEnabled) { if($this->fullTextEnabled()) {
$this->query("exec sp_fulltext_database 'enable';"); $this->query("exec sp_fulltext_database 'enable';");
$result = $this->query("SELECT name FROM sys.fulltext_catalogs WHERE name = 'ftCatalog';")->value(); $result = $this->query("SELECT name FROM sys.fulltext_catalogs WHERE name = 'ftCatalog';")->value();
if(!$result) $this->query("CREATE FULLTEXT CATALOG ftCatalog AS DEFAULT;"); if(!$result) $this->query("CREATE FULLTEXT CATALOG ftCatalog AS DEFAULT;");
@ -678,7 +683,7 @@ class MSSQLDatabase extends SS_Database {
} else { } else {
//create a type-specific index //create a type-specific index
if($indexSpec['type'] == 'fulltext') { if($indexSpec['type'] == 'fulltext') {
if($this->fullTextEnabled) { if($this->fullTextEnabled()) {
//Enable full text search. //Enable full text search.
$this->createFullTextCatalog(); $this->createFullTextCatalog();
@ -748,7 +753,7 @@ class MSSQLDatabase extends SS_Database {
} }
//Now we need to check to see if we have any fulltext indexes attached to this table: //Now we need to check to see if we have any fulltext indexes attached to this table:
if($this->fullTextEnabled) { if($this->fullTextEnabled()) {
$result=DB::query('EXEC sp_help_fulltext_columns;'); $result=DB::query('EXEC sp_help_fulltext_columns;');
$columns=''; $columns='';
foreach($result as $row){ foreach($result as $row){
@ -1147,7 +1152,7 @@ class MSSQLDatabase extends SS_Database {
*/ */
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false) { public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false) {
$searchResults = new DataObjectSet(); $searchResults = new DataObjectSet();
if(!$this->fullTextEnabled) { if(!$this->fullTextEnabled()) {
return $searchResults; return $searchResults;
} }
@ -1228,7 +1233,7 @@ class MSSQLDatabase extends SS_Database {
*/ */
function fulltextIndexExists($tableName) { function fulltextIndexExists($tableName) {
// Special case for no full text index support // Special case for no full text index support
if(!$this->fullTextEnabled) return null; if(!$this->fullTextEnabled()) return null;
return (bool) $this->query(" return (bool) $this->query("
SELECT 1 FROM sys.fulltext_indexes i SELECT 1 FROM sys.fulltext_indexes i
JOIN sys.objects o ON i.object_id = o.object_id JOIN sys.objects o ON i.object_id = o.object_id