You are here

public function DataTable::adopt in Data 6

Same name and namespace in other branches
  1. 7 includes/DataTable.inc \DataTable::adopt()

Let Data manage a table that already exists in the database.

Uses the $name property of the object to determine which database table to adopt.

Return value

TRUE if the table was successfully adopted; FALSE if the table was already known to Data, if the query failed, or if Schema isn't available.

File

includes/DataTable.inc, line 143
Contains class definition for DataTable.

Class

DataTable
Manages data access and manipulation for a single data table. Use data_create_table() or data_get_table() to instantiate an object from this class.

Code

public function adopt() {
  if ($this
    ->defined() || !module_exists('schema')) {
    return FALSE;
  }
  $schema = schema_invoke('inspect', $this->name);
  if (isset($schema[$this->name])) {
    $table = array(
      'name' => $this->name,
      'title' => data_natural_name($this->name),
      'table_schema' => $schema[$this->name],
    );
    if (drupal_write_record('data_tables', $table)) {
      return TRUE;
    }
  }
  return FALSE;
}