Ejemplo n.º 1
0
 /**
  * Generate the following table in the database, modifying whatever already exists
  * as necessary.
  * @param string $table The name of the table
  * @param string $fieldSchema A list of the fields to create, in the same form as DataObject::$db
  * @param string $indexSchema A list of indexes to create.  The keys of the array are the names of the index.
  * The values of the array can be one of:
  *   - true: Create a single column index on the field named the same as the index.
  *   - array('fields' => array('A','B','C'), 'type' => 'index/unique/fulltext'): This gives you full
  *     control over the index.
  */
 function requireTable($table, $fieldSchema = null, $indexSchema = null)
 {
     if (!isset($this->tableList[strtolower($table)])) {
         $this->transCreateTable($table);
         Database::alteration_message("Table {$table}: created", "created");
     } else {
         $this->checkAndRepairTable($table);
     }
     $this->requireField($table, "ID", "int(11) not null auto_increment");
     // Create custom fields
     if ($fieldSchema) {
         foreach ($fieldSchema as $fieldName => $fieldSpec) {
             $fieldObj = eval(ViewableData::castingObjectCreator($fieldSpec));
             $fieldObj->setTable($table);
             $fieldObj->requireField();
         }
     }
     // Create custom indexes
     if ($indexSchema) {
         foreach ($indexSchema as $indexName => $indexDetails) {
             $this->requireIndex($table, $indexName, $indexDetails);
         }
     }
 }