Commit cb1f9443 authored by Dries's avatar Dries

- Patch #934050 by sun, alex_b: change format into string.

parent 11289d69
......@@ -155,8 +155,8 @@ function block_schema() {
'description' => 'Block description.',
),
'format' => array(
'type' => 'int',
'unsigned' => TRUE,
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'The {filter_format}.format of the block body.',
),
......@@ -196,6 +196,11 @@ function block_update_dependencies() {
$dependencies['block'][7005] = array(
'filter' => 7000,
);
// Ensure that format columns are only changed after Filter module has changed
// the primary records.
$dependencies['block'][7007] = array(
'filter' => 7010,
);
return $dependencies;
}
......@@ -444,6 +449,18 @@ function block_update_7006() {
db_create_table('cache_block', $schema);
}
/**
* Change {block_custom}.format into varchar.
*/
function block_update_7007() {
db_change_field('block_custom', 'format', 'format', array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'The {filter_format}.format of the block body.',
));
}
/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.
......
......@@ -309,11 +309,21 @@ function _update_7000_field_delete_instance($field_name, $entity_type, $bundle)
/**
* Utility function: fetch all the field definitions from the database.
*
* @param $conditions
* An array of conditions to limit the select query to.
*/
function _update_7000_field_read_fields() {
function _update_7000_field_read_fields(array $conditions = array()) {
$fields = array();
$results = db_query('SELECT * FROM {field_config} WHERE deleted = 0', array(), array('fetch' => PDO::FETCH_ASSOC));
foreach ($results as $record) {
$query = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
->fields('fc')
->condition('deleted', 0);
if (!empty($conditions)) {
foreach ($conditions as $column => $value) {
$query->condition($column, $value);
}
}
foreach ($query->execute() as $record) {
$field = unserialize($record['data']);
$field['id'] = $record['id'];
$field['field_name'] = $record['field_name'];
......
......@@ -48,8 +48,8 @@ function text_field_schema($field) {
}
$columns += array(
'format' => array(
'type' => 'int',
'unsigned' => TRUE,
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
);
......@@ -66,3 +66,35 @@ function text_field_schema($field) {
),
);
}
/**
* Implements hook_update_dependencies().
*/
function text_update_dependencies() {
// Ensure that format columns are only changed after Filter module has changed
// the primary records.
$dependencies['text'][7000] = array(
'filter' => 7010,
);
return $dependencies;
}
/**
* Change text field 'format' columns into varchar.
*/
function text_update_7000() {
$spec = array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
);
$fields = _update_7000_field_read_fields(array('module' => 'text', 'storage_type' => 'field_sql_storage'));
foreach ($fields as $field_name => $field) {
$table = _field_sql_storage_tablename($prior_field);
$revision_table = _field_sql_storage_revision_tablename($prior_field);
$field_name = _field_sql_storage_columnname($field['field_name'], 'format');
db_change_field($table, $field_name, $field_name, $spec);
db_change_field($revision_table, $field_name, $field_name, $spec);
}
}
......@@ -198,12 +198,16 @@ class TextFieldTestCase extends DrupalWebTestCase {
// Create a new text format that does not escape HTML, and grant the user
// access to it.
$this->drupalLogin($this->admin_user);
$edit = array('name' => $this->randomName());
$edit = array(
'format' => drupal_strtolower($this->randomName()),
'name' => $this->randomName(),
);
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
filter_formats_reset();
$this->checkPermissions(array(), TRUE);
$format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
$permission = filter_permission_name(filter_format_load($format_id));
$format = filter_format_load($edit['format']);
$format_id = $format->format;
$permission = filter_permission_name($format);
$rid = max(array_keys($this->web_user->roles));
user_role_grant_permissions($rid, array($permission));
$this->drupalLogin($this->web_user);
......@@ -360,8 +364,8 @@ class TextSummaryTestCase extends DrupalWebTestCase {
// Test text_summary() for different sizes.
for ($i = 0; $i <= 37; $i++) {
$this->callTextSummary($text, $expected[$i], NULL, $i);
$this->callTextSummary($text, $expected_lb[$i], 1, $i);
$this->callTextSummary($text, $expected_lb[$i], 2, $i);
$this->callTextSummary($text, $expected_lb[$i], 'plain_text', $i);
$this->callTextSummary($text, $expected_lb[$i], 'filtered_html', $i);
}
}
......@@ -386,8 +390,15 @@ class TextTranslationTestCase extends DrupalWebTestCase {
function setUp() {
parent::setUp('locale', 'translation');
$this->format = 3;
$this->admin = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages', 'bypass node access', "use text format $this->format"));
$full_html_format = filter_format_load('full_html');
$this->format = $full_html_format->format;
$this->admin = $this->drupalCreateUser(array(
'administer languages',
'administer content types',
'access administration pages',
'bypass node access',
filter_permission_name($full_html_format),
));
$this->translator = $this->drupalCreateUser(array('create article content', 'edit own article content', 'translate content'));
// Enable an additional language.
......@@ -456,11 +467,11 @@ class TextTranslationTestCase extends DrupalWebTestCase {
// Populate the body field: the first item gets the "Full HTML" input
// format, the second one "Filtered HTML".
$format = $this->format;
$formats = array('full_html', 'filtered_html');
foreach ($body as $delta => $value) {
$edit = array(
"body[$langcode][$delta][value]" => $value,
"body[$langcode][$delta][format]" => $format--,
"body[$langcode][$delta][format]" => array_shift($formats),
);
$this->drupalPost('node/1/edit', $edit, t('Save'));
$this->assertText($body[$delta], t('The body field with delta @delta has been saved.', array('@delta' => $delta)));
......
......@@ -96,7 +96,10 @@ function theme_filter_admin_overview($variables) {
function filter_admin_format_page($format = NULL) {
if (!isset($format->name)) {
drupal_set_title(t('Add text format'));
$format = (object) array('name' => '', 'format' => 0);
$format = (object) array(
'format' => NULL,
'name' => '',
);
}
return drupal_get_form('filter_admin_format_form', $format);
}
......@@ -122,6 +125,16 @@ function filter_admin_format_form($form, &$form_state, $format) {
'#default_value' => $format->name,
'#required' => TRUE,
);
$form['format'] = array(
'#type' => 'machine_name',
'#required' => TRUE,
'#default_value' => $format->format,
'#maxlength' => 255,
'#machine_name' => array(
'exists' => 'filter_format_load',
),
'#disabled' => !empty($format->format),
);
// Add user role access selection.
$form['roles'] = array(
......@@ -227,9 +240,6 @@ function filter_admin_format_form($form, &$form_state, $format) {
}
}
if (!empty($format->format)) {
$form['format'] = array('#type' => 'value', '#value' => $format->format);
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
......
......@@ -14,9 +14,9 @@ function filter_schema() {
'description' => 'Table that maps filters (HTML corrector) to text formats (Filtered HTML).',
'fields' => array(
'format' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.',
),
'module' => array(
......@@ -62,9 +62,10 @@ function filter_schema() {
'description' => 'Stores text formats: custom groupings of filters, such as Filtered HTML.',
'fields' => array(
'format' => array(
'type' => 'serial',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Primary Key: Unique ID for format.',
'description' => 'Primary Key: Unique machine name of the format.',
),
'name' => array(
'type' => 'varchar',
......@@ -120,6 +121,7 @@ function filter_install() {
// plain text format with very basic formatting, but it can be modified by
// installation profiles to have other properties.
$plain_text_format = array(
'format' => 'plain_text',
'name' => 'Plain text',
'weight' => 10,
'filters' => array(
......@@ -469,6 +471,28 @@ function filter_update_7009() {
db_create_table('cache_filter', $schema);
}
/**
* Change {filter_format}.format and {filter}.format into varchar.
*/
function filter_update_7010() {
// Remove the unique index for 'name'. Text formats have sufficient uniqueness
// through machine names.
db_drop_unique_key('filter_format', 'name');
db_change_field('filter_format', 'format', 'format', array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Primary Key: Unique machine name of the format.',
));
db_change_field('filter', 'format', 'format', array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.',
));
}
/**
* @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000.
......
......@@ -182,23 +182,31 @@ function filter_format_load($format_id) {
* - 'settings': (optional) An array of configured settings for the filter.
* See hook_filter_info() for details.
*/
function filter_format_save(&$format) {
function filter_format_save($format) {
$format->name = trim($format->name);
$format->cache = _filter_format_is_cacheable($format);
$format->status = 1;
if (!isset($format->status)) {
$format->status = 1;
}
if (!isset($format->weight)) {
$format->weight = 0;
}
// Insert or update the text format.
$return = db_merge('filter_format')
->key(array('format' => $format->format))
->fields(array(
'name' => $format->name,
'cache' => (int) $format->cache,
'status' => (int) $format->status,
'weight' => (int) $format->weight,
))
->execute();
// Programmatic saves may not contain any filters.
if (!isset($format->filters)) {
$format->filters = array();
}
// Add a new text format.
if (empty($format->format)) {
$return = drupal_write_record('filter_format', $format);
}
else {
$return = drupal_write_record('filter_format', $format, 'format');
}
$filter_info = filter_get_filters();
foreach ($filter_info as $name => $filter) {
// Add new filters without weight to the bottom.
......@@ -241,8 +249,8 @@ function filter_format_save(&$format) {
module_invoke_all('filter_format_update', $format);
// Explicitly indicate that the format was updated. We need to do this
// since if the filters were updated but the format object itself was not,
// the call to drupal_write_record() above would not return an indication
// that anything had changed.
// the merge query above would not return an indication that anything had
// changed.
$return = SAVED_UPDATED;
// Clear the filter cache whenever a text format is updated.
......
......@@ -23,6 +23,7 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
function testTextFormatCRUD() {
// Add a text format with minimum data only.
$format = new stdClass();
$format->format = 'empty_format';
$format->name = 'Empty format';
filter_format_save($format);
$this->verifyTextFormat($format);
......@@ -30,6 +31,7 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
// Add another text format specifying all possible properties.
$format = new stdClass();
$format->format = 'custom_format';
$format->name = 'Custom format';
$format->filters = array(
'filter_url' => array(
......@@ -184,6 +186,7 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$this->drupalGet('admin/config/content/formats');
$this->clickLink('Add text format');
$edit = array(
'format' => drupal_strtolower($this->randomName()),
'name' => $this->randomName(),
);
$this->drupalPost(NULL, $edit, t('Save configuration'));
......@@ -268,6 +271,7 @@ class FilterAdminTestCase extends DrupalWebTestCase {
// Add format.
$edit = array();
$edit['format'] = drupal_strtolower($this->randomName());
$edit['name'] = $this->randomName();
$edit['roles[2]'] = 1;
$edit['filters[' . $second_filter . '][status]'] = TRUE;
......@@ -424,7 +428,10 @@ class FilterFormatAccessTestCase extends DrupalWebTestCase {
$this->drupalLogin($this->filter_admin_user);
$formats = array();
for ($i = 0; $i < 2; $i++) {
$edit = array('name' => $this->randomName());
$edit = array(
'format' => drupal_strtolower($this->randomName()),
'name' => $this->randomName(),
);
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
$this->resetFilterCaches();
$format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
......@@ -656,7 +663,10 @@ class FilterDefaultFormatTestCase extends DrupalWebTestCase {
$this->drupalLogin($admin_user);
$formats = array();
for ($i = 0; $i < 2; $i++) {
$edit = array('name' => $this->randomName());
$edit = array(
'format' => drupal_strtolower($this->randomName()),
'name' => $this->randomName(),
);
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
$this->resetFilterCaches();
$format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
......@@ -1684,6 +1694,7 @@ class FilterHooksTestCase extends DrupalWebTestCase {
// Add a text format.
$name = $this->randomName();
$edit = array();
$edit['format'] = drupal_strtolower($this->randomName());
$edit['name'] = $name;
$edit['roles[1]'] = 1;
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
......
......@@ -17,6 +17,7 @@ function php_enable() {
// subsequent clean installs.
if (!$format_exists) {
$php_format = array(
'format' => 'php_code',
'name' => 'PHP code',
// 'Plain text' format is installed with a weight of 10 by default. Use a
// higher weight here to ensure that this format will not be the default
......
......@@ -370,7 +370,11 @@ class SearchRankingTestCase extends DrupalWebTestCase {
// Create nodes for testing.
foreach ($node_ranks as $node_rank) {
$settings = array('type' => 'page', 'title' => array(LANGUAGE_NONE => array(array('value' => 'Drupal rocks'))), 'body' => array(LANGUAGE_NONE => array(array('value' => "Drupal's search rocks"))));
$settings = array(
'type' => 'page',
'title' => 'Drupal rocks',
'body' => array(LANGUAGE_NONE => array(array('value' => "Drupal's search rocks"))),
);
foreach (array(0, 1) as $num) {
if ($num == 1) {
switch ($node_rank) {
......@@ -444,18 +448,18 @@ class SearchRankingTestCase extends DrupalWebTestCase {
shuffle($shuffled_tags);
$settings = array(
'type' => 'page',
'title' => array(LANGUAGE_NONE => array(array('value' => 'Simple node'))),
'title' => 'Simple node',
);
foreach ($shuffled_tags as $tag) {
switch ($tag) {
case 'a':
$settings['body'] = array(LANGUAGE_NONE => array(array('value' => l('Drupal Rocks', 'node'), 'format' => 3)));
$settings['body'] = array(LANGUAGE_NONE => array(array('value' => l('Drupal Rocks', 'node'), 'format' => 'full_html')));
break;
case 'notag':
$settings['body'] = array(LANGUAGE_NONE => array(array('value' => 'Drupal Rocks')));
break;
default:
$settings['body'] = array(LANGUAGE_NONE => array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 3)));
$settings['body'] = array(LANGUAGE_NONE => array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 'full_html')));
break;
}
$nodes[$tag] = $this->drupalCreateNode($settings);
......@@ -488,7 +492,7 @@ class SearchRankingTestCase extends DrupalWebTestCase {
// Test tags with the same weight against the sorted tags.
$unsorted_tags = array('u', 'b', 'i', 'strong', 'em');
foreach ($unsorted_tags as $tag) {
$settings['body'] = array(LANGUAGE_NONE => array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 3)));
$settings['body'] = array(LANGUAGE_NONE => array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 'full_html')));
$node = $this->drupalCreateNode($settings);
// Update the search index.
......@@ -523,7 +527,7 @@ class SearchRankingTestCase extends DrupalWebTestCase {
// See testRankings() above - build a node that will rank high for sticky.
$settings = array(
'type' => 'page',
'title' => array(LANGUAGE_NONE => array(array('value' => 'Drupal rocks'))),
'title' => 'Drupal rocks',
'body' => array(LANGUAGE_NONE => array(array('value' => "Drupal's search rocks"))),
'sticky' => 1,
);
......@@ -712,9 +716,9 @@ class SearchCommentTestCase extends DrupalWebTestCase {
// Enable check_plain() for 'Filtered HTML' text format.
$filtered_html_format_id = db_query_range('SELECT format FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Filtered HTML'))->fetchField();
$edit = array(
'filters[filter_html_escape][status]' => $filtered_html_format_id,
'filters[filter_html_escape][status]' => TRUE,
);
$this->drupalPost('admin/config/content/formats/1', $edit, t('Save configuration'));
$this->drupalPost('admin/config/content/formats/' . $filtered_html_format_id, $edit, t('Save configuration'));
// Allow anonymous users to search content.
$edit = array(
DRUPAL_ANONYMOUS_RID . '[search content]' => 1,
......
......@@ -999,14 +999,14 @@ function _form_test_disabled_elements($form, &$form_state) {
'#title' => 'Text format',
'#disabled' => TRUE,
'#default_value' => 'Text value',
'#format' => 1,
'#format' => 'plain_text',
'#expected_value' => array(
'value' => 'Text value',
'format' => 1,
'format' => 'plain_text',
),
'#test_hijack_value' => array(
'value' => 'HIJACK',
'format' => 2,
'format' => 'filtered_html',
),
);
......
......@@ -51,8 +51,8 @@ function taxonomy_schema() {
'translatable' => TRUE,
),
'format' => array(
'type' => 'int',
'unsigned' => TRUE,
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'The {filter_format}.format of the description.',
),
......
......@@ -167,8 +167,8 @@ function user_schema() {
'description' => "User's signature.",
),
'signature_format' => array(
'type' => 'int',
'unsigned' => TRUE,
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'The {filter_format}.format of the signature.',
),
......@@ -355,6 +355,11 @@ function user_update_dependencies() {
$dependencies['user'][7013] = array(
'system' => 7059,
);
// Ensure that format columns are only changed after Filter module has changed
// the primary records.
$dependencies['user'][7015] = array(
'filter' => 7010,
);
return $dependencies;
}
......@@ -837,6 +842,18 @@ function user_update_7014() {
return t("Renamed the 'post comments without approval' permission to 'skip comment approval'.");
}
/**
* Change {users}.signature_format into varchar.
*/
function user_update_7015() {
db_change_field('users', 'signature_format', 'signature_format', array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'The {filter_format}.format of the signature.',
));
}
/**
* @} End of "defgroup user-updates-6.x-to-7.x"
* The next series of updates should start at 8000.
......
......@@ -9,6 +9,7 @@
function standard_install() {
// Add text formats.
$filtered_html_format = array(
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(
......@@ -38,6 +39,7 @@ function standard_install() {
filter_format_save($filtered_html_format);
$full_html_format = array(
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment