View source
<?php
function wysiwyg_template_schema() {
$schema['wysiwyg_templates'] = array(
'fields' => array(
'name' => array(
'description' => 'The machine name for the template.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'title' => array(
'description' => 'The title of the Wysiwyg template',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'description' => array(
'description' => 'The description of the Wysiwyg template',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'fid' => array(
'description' => 'The {file_managed}.fid of the image.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'body' => array(
'description' => 'The Wysiwyg template HTML',
'type' => 'text',
),
'format' => array(
'description' => 'The text format used for body field.',
'type' => 'varchar',
'length' => 255,
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The weight of this template in listings and the user interface.',
),
),
'primary key' => array(
'name',
),
'indexes' => array(
'weight' => array(
'weight',
),
),
);
$schema['wysiwyg_templates_default'] = array(
'fields' => array(
'name' => array(
'description' => 'The machine name for the template.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'type' => array(
'description' => 'The {node_type}.type of this node.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array(
'type',
),
'indexes' => array(
'name' => array(
'name',
),
),
);
$schema['wysiwyg_templates_content_types'] = array(
'fields' => array(
'name' => array(
'description' => 'The machine name for the template.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'type' => array(
'description' => 'The {node_type}.type of this node.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array(
'name',
'type',
),
'indexes' => array(
'name' => array(
'name',
),
'type' => array(
'type',
),
),
);
return $schema;
}
function wysiwyg_template_update_7200() {
$templates = db_select('wysiwyg_templates', 't')
->fields('t', array(
'tid',
'title',
))
->execute()
->fetchAllKeyed(0, 1);
db_change_field('wysiwyg_templates', 'tid', 'tid', array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
));
db_drop_primary_key('wysiwyg_templates');
db_add_field('wysiwyg_templates', 'name', array(
'description' => 'The machine name for the template.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
));
foreach ($templates as $tid => $title) {
$new_name = strtolower(trim(substr($title, 0, 128)));
$new_name = preg_replace('/[^a-z0-9_]+/', '_', $new_name);
if (wysiwyg_template_name_exists($new_name)) {
$tmp_name = $new_name;
$i = 0;
do {
$unique_suffix = '_' . $i;
$new_name = truncate_utf8($tmp_name, 128 - drupal_strlen($unique_suffix, TRUE)) . $unique_suffix;
$i++;
} while (wysiwyg_template_name_exists($new_name));
}
db_update('wysiwyg_templates')
->fields(array(
'name' => $new_name,
))
->condition('tid', $tid)
->execute();
}
db_add_primary_key('wysiwyg_templates', array(
'name',
));
db_drop_field('wysiwyg_templates', 'tid');
}
function wysiwyg_template_update_7201() {
db_add_field('wysiwyg_templates', 'fid', array(
'description' => 'The {file_managed}.fid of the image.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
));
}
function wysiwyg_template_update_7202() {
if (!db_table_exists('wysiwyg_templates_default')) {
$schema = wysiwyg_template_schema();
db_create_table('wysiwyg_templates_default', $schema['wysiwyg_templates_default']);
}
}
function wysiwyg_template_update_7203() {
if (!db_field_exists('wysiwyg_templates', 'weight')) {
$schema = wysiwyg_template_schema();
db_add_field('wysiwyg_templates', 'weight', $schema['wysiwyg_templates']['fields']['weight']);
db_add_index('wysiwyg_templates', 'weight', $schema['wysiwyg_templates']['indexes']['weight']);
}
}
function wysiwyg_template_update_7204() {
if (!db_table_exists('wysiwyg_templates_content_types')) {
$schema = wysiwyg_template_schema();
db_create_table('wysiwyg_templates_content_types', $schema['wysiwyg_templates_content_types']);
}
}
function wysiwyg_template_update_7205() {
$schema = wysiwyg_template_schema();
db_add_field('wysiwyg_templates', 'format', $schema['wysiwyg_templates']['fields']['format']);
}