You are here

function content_update_4 in Content Construction Kit (CCK) 5

Add tables for content types to store their data.

File

./content.install, line 157

Code

function content_update_4() {
  $ret = array();

  // Figure out what table to update. If node_type exists and node_type_content does not, this update is
  // being done by an early version of core that did not rename the node_type table, so use the original name, node_type.
  // If both table names exist, core has renamed the table, so use the renamed table name, node_type_content.
  if (!db_table_exists('node_type_content')) {
    $result = db_query("SELECT type_name FROM {node_type}");
  }
  else {
    $result = db_query("SELECT type_name FROM {node_type_content}");
  }
  while ($type = db_fetch_object($result)) {
    switch ($GLOBALS['db_type']) {
      case 'mysql':
      case 'mysqli':
        $ret[] = update_sql("CREATE TABLE {node_" . strtr($type->type_name, '-', '_') . "} (\n            vid int unsigned NOT NULL default '0',\n            nid int unsigned NOT NULL default '0',\n            PRIMARY KEY (vid)\n          ) /*!40100 DEFAULT CHARACTER SET utf8 */");
        break;
      case 'pgsql':
        $ret[] = update_sql("CREATE TABLE {node_" . strtr($type->type_name, '-', '_') . "} (\n            vid int_unsigned NOT NULL default '0',\n            nid int_unsigned NOT NULL default '0',\n            PRIMARY KEY (vid)\n          )");
        break;
    }
  }
  return $ret;
}