Skip to content

Commit

Permalink
Revert "Add MySQL FULLTEXT support."
Browse files Browse the repository at this point in the history
This reverts commit 36c99a3.
  • Loading branch information
markstory committed Sep 21, 2012
1 parent f4a639c commit a975026
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 64 deletions.
35 changes: 22 additions & 13 deletions lib/Cake/Model/Datasource/Database/Mysql.php
Expand Up @@ -425,21 +425,17 @@ public function index($model) {
$table = $this->fullTableName($model);
$old = version_compare($this->getVersion(), '4.1', '<=');
if ($table) {
$indexes = $this->_execute('SHOW INDEX FROM ' . $table);
$indices = $this->_execute('SHOW INDEX FROM ' . $table);
// @codingStandardsIgnoreStart
// MySQL columns don't match the cakephp conventions.
while ($idx = $indexes->fetch(PDO::FETCH_OBJ)) {
while ($idx = $indices->fetch(PDO::FETCH_OBJ)) {
if ($old) {
$idx = (object)current((array)$idx);
}
if (!isset($index[$idx->Key_name]['column'])) {
$col = array();
$index[$idx->Key_name]['column'] = $idx->Column_name;
if ($idx->Index_type === 'FULLTEXT') {
$index[$idx->Key_name]['type'] = strtolower($idx->Index_type);
} else {
$index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0);
}
$index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0);
} else {
if (!empty($index[$idx->Key_name]['column']) && !is_array($index[$idx->Key_name]['column'])) {
$col[] = $index[$idx->Key_name]['column'];
Expand All @@ -449,7 +445,7 @@ public function index($model) {
}
}
// @codingStandardsIgnoreEnd
$indexes->closeCursor();
$indices->closeCursor();
}
return $index;
}
Expand Down Expand Up @@ -559,18 +555,31 @@ protected function _alterIndexes($table, $indexes) {
if (isset($indexes['drop'])) {
foreach ($indexes['drop'] as $name => $value) {
$out = 'DROP ';
if ($name === 'PRIMARY') {
if ($name == 'PRIMARY') {
$out .= 'PRIMARY KEY';
} else {
$out .= 'KEY ' . $this->startQuote . $name . $this->endQuote;
$out .= 'KEY ' . $name;
}
$alter[] = $out;
}
}
if (isset($indexes['add'])) {
$add = $this->buildIndex($indexes['add']);
foreach ($add as $index) {
$alter[] = 'ADD ' . $index;
foreach ($indexes['add'] as $name => $value) {
$out = 'ADD ';
if ($name == 'PRIMARY') {
$out .= 'PRIMARY ';
$name = null;
} else {
if (!empty($value['unique'])) {
$out .= 'UNIQUE ';
}
}
if (is_array($value['column'])) {
$out .= 'KEY ' . $name . ' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
} else {
$out .= 'KEY ' . $name . ' (' . $this->name($value['column']) . ')';
}
$alter[] = $out;
}
}
return $alter;
Expand Down
4 changes: 1 addition & 3 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -3113,7 +3113,7 @@ protected function _buildFieldParameters($columnString, $columnData, $position)
}

/**
* Format indexes for create table.
* Format indexes for create table
*
* @param array $indexes
* @param string $table
Expand All @@ -3129,8 +3129,6 @@ public function buildIndex($indexes, $table = null) {
} else {
if (!empty($value['unique'])) {
$out .= 'UNIQUE ';
} elseif (!empty($value['type']) && strtoupper($value['type']) === 'FULLTEXT') {
$out .= 'FULLTEXT ';
}
$name = $this->startQuote . $name . $this->endQuote;
}
Expand Down
17 changes: 0 additions & 17 deletions lib/Cake/Test/Case/Model/CakeSchemaTest.php
Expand Up @@ -762,23 +762,6 @@ public function testGenerateTable() {
);
$result = $this->Schema->generateTable('posts', $posts);
$this->assertRegExp('/public \$posts/', $result);

$posts = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false),
'body' => array('type' => 'text', 'null' => true, 'default' => null),
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true),
'MyFtIndex' => array('column' => array('title', 'body'), 'type' => 'fulltext')
)
);
$result = $this->Schema->generateTable('fields', $posts);
$this->assertRegExp('/public \$fields/', $result);
$this->assertPattern('/\'type\' \=\> \'fulltext\'/', $result);
}

/**
Expand Down
45 changes: 14 additions & 31 deletions lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -313,16 +313,6 @@ public function testIndexDetection() {
$result = $this->Dbo->index('with_multiple_compound_keys', false);
$this->Dbo->rawQuery('DROP TABLE ' . $name);
$this->assertEquals($expected, $result);

$name = $this->Dbo->fullTableName('with_fulltext');
$this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, name varchar(255), description text, primary key(id), FULLTEXT KEY `MyFtIndex` ( `name`, `description` )) ENGINE=MyISAM;');
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'MyFtIndex' => array('column' => array('name', 'description'), 'type' => 'fulltext')
);
$result = $this->Dbo->index('with_fulltext', false);
$this->Dbo->rawQuery('DROP TABLE ' . $name);
$this->assertEquals($expected, $result);
}

/**
Expand Down Expand Up @@ -558,9 +548,9 @@ public function testAlterSchemaIndexes() {

$result = $this->Dbo->alterSchema($schemaB->compare($schemaA));
$this->assertContains("ALTER TABLE $table", $result);
$this->assertContains('ADD KEY `name_idx` (`name`),', $result);
$this->assertContains('ADD KEY `group_idx` (`group1`),', $result);
$this->assertContains('ADD KEY `compound_idx` (`group1`, `group2`),', $result);
$this->assertContains('ADD KEY name_idx (`name`),', $result);
$this->assertContains('ADD KEY group_idx (`group1`),', $result);
$this->assertContains('ADD KEY compound_idx (`group1`, `group2`),', $result);
$this->assertContains('ADD PRIMARY KEY (`id`);', $result);

//Test that the string is syntactically correct
Expand All @@ -586,13 +576,13 @@ public function testAlterSchemaIndexes() {
$result = $this->Dbo->alterSchema($schemaC->compare($schemaB));
$this->assertContains("ALTER TABLE $table", $result);
$this->assertContains('DROP PRIMARY KEY,', $result);
$this->assertContains('DROP KEY `name_idx`,', $result);
$this->assertContains('DROP KEY `group_idx`,', $result);
$this->assertContains('DROP KEY `compound_idx`,', $result);
$this->assertContains('ADD KEY `id_name_idx` (`id`, `name`),', $result);
$this->assertContains('ADD UNIQUE KEY `name_idx` (`name`),', $result);
$this->assertContains('ADD KEY `group_idx` (`group2`),', $result);
$this->assertContains('ADD KEY `compound_idx` (`group2`, `group1`);', $result);
$this->assertContains('DROP KEY name_idx,', $result);
$this->assertContains('DROP KEY group_idx,', $result);
$this->assertContains('DROP KEY compound_idx,', $result);
$this->assertContains('ADD KEY id_name_idx (`id`, `name`),', $result);
$this->assertContains('ADD UNIQUE KEY name_idx (`name`),', $result);
$this->assertContains('ADD KEY group_idx (`group2`),', $result);
$this->assertContains('ADD KEY compound_idx (`group2`, `group1`);', $result);

$query = $this->Dbo->getConnection()->prepare($result);
$this->assertEquals($query->queryString, $result);
Expand All @@ -604,10 +594,10 @@ public function testAlterSchemaIndexes() {
$result = $this->Dbo->alterSchema($schemaA->compare($schemaC));

$this->assertContains("ALTER TABLE $table", $result);
$this->assertContains('DROP KEY `name_idx`,', $result);
$this->assertContains('DROP KEY `group_idx`,', $result);
$this->assertContains('DROP KEY `compound_idx`,', $result);
$this->assertContains('DROP KEY `id_name_idx`;', $result);
$this->assertContains('DROP KEY name_idx,', $result);
$this->assertContains('DROP KEY group_idx,', $result);
$this->assertContains('DROP KEY compound_idx,', $result);
$this->assertContains('DROP KEY id_name_idx;', $result);

$query = $this->Dbo->getConnection()->prepare($result);
$this->assertEquals($query->queryString, $result);
Expand Down Expand Up @@ -2866,13 +2856,6 @@ public function testBuildIndex() {
$result = $this->Dbo->buildIndex($data);
$expected = array('UNIQUE KEY `MyIndex` (`id`, `name`)');
$this->assertEquals($expected, $result);

$data = array(
'MyFtIndex' => array('column' => array('name', 'description'), 'type' => 'fulltext')
);
$result = $this->Dbo->buildIndex($data);
$expected = array('FULLTEXT KEY `MyFtIndex` (`name`, `description`)');
$this->assertEquals($expected, $result);
}

/**
Expand Down

0 comments on commit a975026

Please sign in to comment.