function system_update_1005 in Drupal 5
Related topics
File
- modules/
system/ system.install, line 3166
Code
function system_update_1005() {
// Add ability to create dynamic node types like the CCK module
$ret = array();
// The node_type table may already exist for anyone who ever used CCK in 4.7,
// even if CCK is no longer installed. We need to make sure any previously
// created table gets renamed before we create the new node_type table in
// order to ensure that the new table gets created without errors.
// TODO: This check should be removed for Drupal 6.
if (db_table_exists('node_type')) {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql('RENAME TABLE {node_type} TO {node_type_content}');
break;
case 'pgsql':
$ret[] = update_sql('ALTER TABLE {node_type} RENAME TO {node_type_content}');
break;
}
}
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
// Create node_type table
$ret[] = update_sql("CREATE TABLE {node_type} (\n type varchar(32) NOT NULL,\n name varchar(255) NOT NULL,\n module varchar(255) NOT NULL,\n description mediumtext NOT NULL,\n help mediumtext NOT NULL,\n has_title tinyint unsigned NOT NULL,\n title_label varchar(255) NOT NULL default '',\n has_body tinyint unsigned NOT NULL,\n body_label varchar(255) NOT NULL default '',\n min_word_count smallint unsigned NOT NULL,\n custom tinyint NOT NULL DEFAULT '0',\n modified tinyint NOT NULL DEFAULT '0',\n locked tinyint NOT NULL DEFAULT '0',\n orig_type varchar(255) NOT NULL default '',\n PRIMARY KEY (type)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
// add new unsigned types for pgsql
$ret[] = update_sql("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)");
$ret[] = update_sql("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)");
$ret[] = update_sql("CREATE DOMAIN bigint_unsigned bigint CHECK (VALUE >= 0)");
$ret[] = update_sql("CREATE TABLE {node_type} (\n type varchar(32) NOT NULL,\n name varchar(255) NOT NULL,\n module varchar(255) NOT NULL,\n description text NOT NULL,\n help text NOT NULL,\n has_title smallint_unsigned NOT NULL,\n title_label varchar(255) NOT NULL default '',\n has_body smallint_unsigned NOT NULL,\n body_label varchar(255) NOT NULL default '',\n min_word_count smallint_unsigned NOT NULL,\n custom smallint NOT NULL DEFAULT '0',\n modified smallint NOT NULL DEFAULT '0',\n locked smallint NOT NULL DEFAULT '0',\n orig_type varchar(255) NOT NULL default '',\n PRIMARY KEY (type)\n );");
break;
}
// Insert default user-defined node types into the database.
$types = array(
array(
'type' => 'page',
'name' => t('Page'),
'module' => 'node',
'description' => t('If you want to add a static page, like a contact page or an about page, use a page.'),
'custom' => TRUE,
'modified' => TRUE,
'locked' => FALSE,
),
array(
'type' => 'story',
'name' => t('Story'),
'module' => 'node',
'description' => t('Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extended by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.'),
'custom' => TRUE,
'modified' => TRUE,
'locked' => FALSE,
),
);
foreach ($types as $type) {
$type = (object) _node_type_set_defaults($type);
node_type_save($type);
}
cache_clear_all();
system_modules();
menu_rebuild();
node_types_rebuild();
// Migrate old values for 'minimum_x_size' variables to the node_type table.
$query = db_query('SELECT type FROM {node_type}');
while ($result = db_fetch_object($query)) {
$variable_name = 'minimum_' . $result->type . '_size';
if ($value = db_fetch_object(db_query("SELECT value FROM {variable} WHERE name = '%s'", $variable_name))) {
$value = (int) unserialize($value->value);
db_query("UPDATE {node_type} SET min_word_count = %d, modified = %d WHERE type = '%s'", $value, 1, $result->type);
variable_del($variable_name);
}
}
node_types_rebuild();
return $ret;
}