コード例 #1
0
ファイル: Table.php プロジェクト: michaelnavarro/zc
 /**
  * Add index to table
  * 
  * @param Index $indexCandidate
  * @return Table
  */
 protected function _addIndex(Index $indexCandidate)
 {
     // check for duplicates
     foreach ($this->_indexes as $existingIndex) {
         if ($indexCandidate->isFullfilledBy($existingIndex)) {
             return $this;
         }
     }
     $indexName = $indexCandidate->getName();
     $indexName = strtolower($indexName);
     if (isset($this->_indexes[$indexName]) || $this->_primaryKeyName != false && $indexCandidate->isPrimary()) {
         throw SchemaException::indexAlreadyExists($indexName, $this->_name);
     }
     // remove overruled indexes
     foreach ($this->_indexes as $idxKey => $existingIndex) {
         if ($indexCandidate->overrules($existingIndex)) {
             unset($this->_indexes[$idxKey]);
         }
     }
     if ($indexCandidate->isPrimary()) {
         $this->_primaryKeyName = $indexName;
     }
     $this->_indexes[$indexName] = $indexCandidate;
     return $this;
 }
コード例 #2
0
ファイル: Table.php プロジェクト: andreia/doctrine
 /**
  * Add index to table
  * 
  * @param Index $index
  * @return Table
  */
 protected function _addIndex(Index $index)
 {
     // check for duplicates
     $c = new Comparator();
     foreach ($this->_indexes as $existingIndex) {
         if ($c->diffIndex($index, $existingIndex) == false) {
             return $this;
         }
     }
     $indexName = $index->getName();
     $indexName = strtolower($indexName);
     if (isset($this->_indexes[$indexName]) || $this->_primaryKeyName != false && $index->isPrimary()) {
         throw SchemaException::indexAlreadyExists($indexName);
     }
     if ($index->isPrimary()) {
         $this->_primaryKeyName = $indexName;
     }
     $this->_indexes[$indexName] = $index;
     return $this;
 }
コード例 #3
0
ファイル: Table.php プロジェクト: BozzaCoon/SPHERE-Framework
 /**
  * Renames an index.
  *
  * @param string      $oldIndexName The name of the index to rename from.
  * @param string|null $newIndexName The name of the index to rename to.
  *                                  If null is given, the index name will be auto-generated.
  *
  * @return self This table instance.
  *
  * @throws SchemaException if no index exists for the given current name
  *                         or if an index with the given new name already exists on this table.
  */
 public function renameIndex($oldIndexName, $newIndexName = null)
 {
     $oldIndexName = $this->normalizeIdentifier($oldIndexName);
     $normalizedNewIndexName = $this->normalizeIdentifier($newIndexName);
     if ($oldIndexName === $normalizedNewIndexName) {
         return $this;
     }
     if (!$this->hasIndex($oldIndexName)) {
         throw SchemaException::indexDoesNotExist($oldIndexName, $this->_name);
     }
     if ($this->hasIndex($normalizedNewIndexName)) {
         throw SchemaException::indexAlreadyExists($normalizedNewIndexName, $this->_name);
     }
     $oldIndex = $this->_indexes[$oldIndexName];
     if ($oldIndex->isPrimary()) {
         $this->dropPrimaryKey();
         return $this->setPrimaryKey($oldIndex->getColumns(), $newIndexName);
     }
     unset($this->_indexes[$oldIndexName]);
     if ($oldIndex->isUnique()) {
         return $this->addUniqueIndex($oldIndex->getColumns(), $newIndexName);
     }
     return $this->addIndex($oldIndex->getColumns(), $newIndexName, $oldIndex->getFlags());
 }
コード例 #4
0
 /**
  * Adds an index to the table.
  *
  * @param Index $indexCandidate
  *
  * @return self
  *
  * @throws SchemaException
  */
 protected function _addIndex(Index $indexCandidate)
 {
     $indexName = $indexCandidate->getName();
     $indexName = $this->normalizeIdentifier($indexName);
     $replacedImplicitIndexes = array();
     foreach ($this->implicitIndexes as $name => $implicitIndex) {
         if ($implicitIndex->isFullfilledBy($indexCandidate) && isset($this->_indexes[$name])) {
             $replacedImplicitIndexes[] = $name;
         }
     }
     if (isset($this->_indexes[$indexName]) && !in_array($indexName, $replacedImplicitIndexes, true) || $this->_primaryKeyName != false && $indexCandidate->isPrimary()) {
         throw SchemaException::indexAlreadyExists($indexName, $this->_name);
     }
     foreach ($replacedImplicitIndexes as $name) {
         unset($this->_indexes[$name], $this->implicitIndexes[$name]);
     }
     if ($indexCandidate->isPrimary()) {
         $this->_primaryKeyName = $indexName;
     }
     $this->_indexes[$indexName] = $indexCandidate;
     return $this;
 }