View source
<?php
include_once dirname(__FILE__) . '/content.module';
function content_types_install() {
$module_field_types = $module_widgets = array();
foreach (module_list() as $module) {
if ($field_type = module_invoke($module, 'field_info')) {
$module_field_types[$module] = $field_type;
}
if ($widget_type = module_invoke($module, 'widget_info')) {
$module_widgets[$module] = $widget_type;
}
}
$fields = array();
$db_result = db_query("SELECT * FROM {" . content_instance_tablename() . "} nfi " . " LEFT JOIN {" . content_field_tablename() . "} nf ON nf.field_name = nfi.field_name");
while ($field = db_fetch_array($db_result)) {
unset($field['module']);
unset($field['widget_module']);
$field['columns'] = $field['db_columns'];
unset($field['db_columns']);
foreach ($module_field_types as $module => $types) {
foreach ($types as $type_name => $type) {
if ($field['type'] == $type_name) {
$field['module'] = $module;
}
}
}
foreach ($module_widgets as $module => $types) {
foreach ($types as $type_name => $type) {
if ($field['widget_type'] == $type_name) {
$field['widget_module'] = $module;
}
}
}
if (!empty($field['module']) && !empty($field['widget_module'])) {
$field['widget_settings'] = unserialize($field['widget_settings']);
$field['display_settings'] = unserialize($field['display_settings']);
$field['columns'] = module_invoke($field['module'], 'field_settings', 'database columns', $field);
$fields[$field['type_name']][$field['field_name']] = $field;
}
}
return $fields;
}
function content_install() {
variable_set('content_schema_version', 6002);
drupal_install_schema('content');
}
function content_uninstall() {
variable_del('content_schema_version');
drupal_uninstall_schema('content');
}
function content_enable() {
cache_clear_all('*', 'cache_content', TRUE);
content_clear_type_cache(TRUE);
}
function content_disable() {
cache_clear_all('*', 'cache_content', TRUE);
content_clear_type_cache(TRUE);
}
function content_schema() {
$schema['content_node_field'] = array(
'fields' => array(
'field_name' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'type' => array(
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
'default' => '',
),
'global_settings' => array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
'serialize' => TRUE,
),
'required' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'multiple' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'db_storage' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 1,
),
'module' => array(
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
'default' => '',
),
'db_columns' => array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
'serialize' => TRUE,
),
'active' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'field_name',
),
);
$schema['content_node_field_instance'] = array(
'fields' => array(
'field_name' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'type_name' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'label' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'widget_type' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'widget_settings' => array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
'serialize' => TRUE,
),
'display_settings' => array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
'serialize' => TRUE,
),
'description' => array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
),
'widget_module' => array(
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
'default' => '',
),
'widget_active' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'field_name',
'type_name',
),
);
$schema['cache_content'] = drupal_get_schema_unprocessed('system', 'cache');
if (!db_table_exists('content_node_field') || !db_table_exists('content_node_field_instance')) {
return $schema;
}
$db_result = db_query("SELECT * FROM {" . content_instance_tablename() . "} nfi " . " LEFT JOIN {" . content_field_tablename() . "} nf ON nf.field_name = nfi.field_name WHERE nf.active = 1 AND nfi.widget_active = 1");
while ($field = db_fetch_array($db_result)) {
$field['columns'] = unserialize($field['db_columns']);
unset($field['db_columns']);
$content_table = _content_tablename($field['type_name'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
$field_table = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD);
if (!isset($schema[$content_table])) {
$schema[$content_table] = content_table_schema();
}
$base_schema = content_table_schema($field);
if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) {
if (!isset($schema[$field_table])) {
$schema[$field_table] = $base_schema;
}
}
else {
$schema[$content_table]['fields'] = array_merge($schema[$content_table]['fields'], $base_schema['fields']);
$schema[$content_table]['content fields'] = array_merge($schema[$content_table]['content fields'], $base_schema['content fields']);
}
}
return $schema;
}
function content_update_last_removed() {
return 1008;
}
function content_update_6000() {
$ret = array();
if (db_column_exists(content_field_tablename(), 'active')) {
return $ret;
}
db_add_field($ret, content_field_tablename(), 'module', array(
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
'default' => '',
));
db_add_field($ret, content_field_tablename(), 'db_columns', array(
'type' => 'text',
'not null' => TRUE,
'default' => '',
));
db_add_field($ret, content_field_tablename(), 'active', array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
));
db_add_field($ret, content_instance_tablename(), 'widget_module', array(
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
'default' => '',
));
db_add_field($ret, content_instance_tablename(), 'widget_active', array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
));
foreach (module_list() as $module) {
content_associate_fields($module);
}
if (db_table_exists('cache_content')) {
db_drop_table($ret, 'cache_content');
}
db_create_table($ret, 'cache_content', drupal_get_schema_unprocessed('system', 'cache'));
variable_set('content_schema_version', 6000);
$ret[] = update_sql('DELETE FROM {cache}');
return $ret;
}
function content_update_6001() {
$ret = array();
if (db_table_exists('content_node_field')) {
return $ret;
}
db_rename_table($ret, 'node_field', 'content_node_field');
db_rename_table($ret, 'node_field_instance', 'content_node_field_instance');
variable_set('content_schema_version', 6001);
content_clear_type_cache(TRUE);
return $ret;
}
function content_update_6002() {
$ret = array();
$db_types = content_types_install();
$field_types = array();
$result = db_query("SELECT DISTINCT type_name FROM {" . content_instance_tablename() . "}");
while ($type = db_fetch_array($result)) {
$field_types[] = $type['type_name'];
}
foreach ($db_types as $content_type => $content_info) {
if (!in_array($content_type, $field_types)) {
$table = _content_tablename($content_type, CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
if (db_table_exists($table)) {
db_drop_table($ret, $table);
}
}
}
variable_set('content_schema_version', 6002);
content_clear_type_cache(TRUE);
return $ret;
}
function content_update_6003() {
$ret = array();
if (db_column_exists('content_node_field', 'columns')) {
db_change_field($ret, 'content_node_field', 'columns', 'db_columns', array(
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
));
}
return $ret;
}