Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1'
Browse files Browse the repository at this point in the history
# Conflicts:
#	code/MSSQLDatabase.php
#	code/MSSQLSchemaManager.php
#	composer.json
  • Loading branch information
Damian Mooyman committed Dec 7, 2017
2 parents 6a25ac4 + aa21b10 commit 2b6a70e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions code/MSSQLDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ public function random()
*/
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false)
{
$start = (int)$start;
$pageLength = (int)$pageLength;
$results = new ArrayList();

if (!$this->fullTextEnabled()) {
Expand Down
13 changes: 9 additions & 4 deletions code/MSSQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,10 @@ protected function alterTableAlterColumn($tableName, $colName, $colSpec)
// drop *ALL* indexes on a table before proceeding
// this won't drop primary keys, though
$indexes = $this->indexNames($tableName);
$indexes = array_filter($indexes);

foreach ($indexes as $indexName) {
$alterQueries[] = "DROP INDEX \"$indexName\" ON \"$tableName\";";
$alterQueries[] = "IF EXISTS (SELECT name FROM sys.indexes WHERE name = '$indexName' AND object_id = object_id(SCHEMA_NAME() + '.$tableName')) DROP INDEX \"$indexName\" ON \"$tableName\";";
}

$prefix = "ALTER TABLE \"$tableName\" ";
Expand Down Expand Up @@ -607,10 +609,13 @@ protected function getIndexSqlDefinition($tableName, $indexName, $indexSpec)
// Consolidate/Cleanup spec into array format
$indexSpec = $this->parseIndexSpec($indexName, $indexSpec);

$drop = "IF EXISTS (SELECT name FROM sys.indexes WHERE name = '$index') DROP INDEX $index ON \"$tableName\";";
$drop = "IF EXISTS (SELECT name FROM sys.indexes WHERE name = '$index' AND object_id = object_id(SCHEMA_NAME() + '.$tableName')) DROP INDEX $index ON \"$tableName\";";

// create a type-specific index
if ($indexSpec['type'] == 'fulltext' && $this->database->fullTextEnabled()) {
if ($indexSpec['type'] == 'fulltext') {
if(!$this->database->fullTextEnabled()) {
return '';
}
// enable fulltext on this table
$this->createFullTextCatalog();
$primary_key = $this->getPrimaryKey($tableName);
Expand Down Expand Up @@ -700,7 +705,7 @@ public function indexNames($tableName)
return $this->preparedQuery('
SELECT ind.name FROM sys.indexes ind
INNER JOIN sys.tables t ON ind.object_id = t.object_id
WHERE is_primary_key = 0 AND t.name = ?',
WHERE is_primary_key = 0 AND t.name = ? AND ind.name IS NOT NULL',
array($tableName)
)->column();
}
Expand Down

0 comments on commit 2b6a70e

Please sign in to comment.