From 9459b44022215bbd7dfc59a3b252f5a21b3c0865 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Thu, 14 Nov 2013 19:27:21 +0200 Subject: [PATCH] Composite primary key support removed from Sphinx schema. --- extensions/sphinx/IndexSchema.php | 27 ++------------------------- extensions/sphinx/Schema.php | 8 ++++---- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/extensions/sphinx/IndexSchema.php b/extensions/sphinx/IndexSchema.php index 81ba075..3ce090d 100644 --- a/extensions/sphinx/IndexSchema.php +++ b/extensions/sphinx/IndexSchema.php @@ -29,9 +29,9 @@ class IndexSchema extends Object */ public $name; /** - * @var string[] primary keys of this index. + * @var string primary key of this index. */ - public $primaryKey = []; + public $primaryKey; /** * @var ColumnSchema[] column metadata of this index. Each array element is a [[ColumnSchema]] object, indexed by column names. */ @@ -56,27 +56,4 @@ class IndexSchema extends Object { return array_keys($this->columns); } - - /** - * Manually specifies the primary key for this table. - * @param string|array $keys the primary key (can be composite) - * @throws InvalidParamException if the specified key cannot be found in the table. - */ - public function fixPrimaryKey($keys) - { - if (!is_array($keys)) { - $keys = [$keys]; - } - $this->primaryKey = $keys; - foreach ($this->columns as $column) { - $column->isPrimaryKey = false; - } - foreach ($keys as $key) { - if (isset($this->columns[$key])) { - $this->columns[$key]->isPrimaryKey = true; - } else { - throw new InvalidParamException("Primary key '$key' cannot be found in index '{$this->name}'."); - } - } - } } \ No newline at end of file diff --git a/extensions/sphinx/Schema.php b/extensions/sphinx/Schema.php index 558f071..20675b2 100644 --- a/extensions/sphinx/Schema.php +++ b/extensions/sphinx/Schema.php @@ -70,7 +70,7 @@ class Schema extends Object * @param string $name index name * @return IndexSchema driver dependent index metadata. Null if the index does not exist. */ - protected function loadTableSchema($name) + protected function loadIndexSchema($name) { $index = new IndexSchema; $this->resolveIndexNames($index, $name); @@ -119,7 +119,7 @@ class Schema extends Object if ($cache instanceof Cache) { $key = $this->getCacheKey($name); if ($refresh || ($index = $cache->get($key)) === false) { - $index = $this->loadTableSchema($realName); + $index = $this->loadIndexSchema($realName); if ($index !== null) { $cache->set($key, $index, $db->schemaCacheDuration, new GroupDependency($this->getCacheGroup())); } @@ -127,7 +127,7 @@ class Schema extends Object return $this->_indexes[$name] = $index; } } - return $this->_indexes[$name] = $index = $this->loadTableSchema($realName); + return $this->_indexes[$name] = $index = $this->loadIndexSchema($realName); } /** @@ -424,7 +424,7 @@ class Schema extends Object $column = $this->loadColumnSchema($info); $index->columns[$column->name] = $column; if ($column->isPrimaryKey) { - $index->primaryKey[] = $column->name; + $index->primaryKey = $column->name; } } return true;