diff --git a/modules/block/block.install b/modules/block/block.install index b45c5e5e2d5013c0d148ef7f5b68460af0ee28de..7567499f3ddbf26d20a6c7b6d56364bd5f22dbeb 100644 --- a/modules/block/block.install +++ b/modules/block/block.install @@ -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. diff --git a/modules/field/field.install b/modules/field/field.install index 91b0d210fd0d17097f1a3f4f29df0ded4235b807..34afd5ad107edc09e5f33106b21e44b70863be30 100644 --- a/modules/field/field.install +++ b/modules/field/field.install @@ -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']; diff --git a/modules/field/modules/text/text.install b/modules/field/modules/text/text.install index 29cd07b87af342c297c1d2378a3230fc578b47cb..3854e5688634fba01fae6ecd40b234ed60ddeefc 100644 --- a/modules/field/modules/text/text.install +++ b/modules/field/modules/text/text.install @@ -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); + } +} diff --git a/modules/field/modules/text/text.test b/modules/field/modules/text/text.test index bfc9156e5386a1e8c68449e5aca634432236ad4d..5f4b0c19df557468618ff115d4dc27c0c2422d84 100644 --- a/modules/field/modules/text/text.test +++ b/modules/field/modules/text/text.test @@ -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))); diff --git a/modules/filter/filter.admin.inc b/modules/filter/filter.admin.inc index 1f98751d0502ce7bd1205aa816f28437e564d224..2c40e287a6c16c1bf288be37db9c200d1aeed4b6 100644 --- a/modules/filter/filter.admin.inc +++ b/modules/filter/filter.admin.inc @@ -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')); diff --git a/modules/filter/filter.install b/modules/filter/filter.install index a027121409f5e7d7108185d129e7d0000458592f..8238473beef23ad1750d7c7f72b51a9fa124e06a 100644 --- a/modules/filter/filter.install +++ b/modules/filter/filter.install @@ -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. diff --git a/modules/filter/filter.module b/modules/filter/filter.module index bbfda2aaea5958aa3455d783f6fb31946af88838..e64bee41dea2caf772c761101646b6bfe07979a1 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -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. diff --git a/modules/filter/filter.test b/modules/filter/filter.test index 6f98dd941c6719a11e9e0f9bac212b3203f9d14c..8500846c417eb668be888c8b468c9ceca6e45f22 100644 --- a/modules/filter/filter.test +++ b/modules/filter/filter.test @@ -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')); diff --git a/modules/php/php.install b/modules/php/php.install index 15c8784033c7ab156b7ea9a9071f2d3ac4d8ec75..e37c56c8fea9b35c38a7b40581250af2845e37dc 100644 --- a/modules/php/php.install +++ b/modules/php/php.install @@ -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 diff --git a/modules/search/search.test b/modules/search/search.test index f0d3a6a4b4fa770f1ecd14479713c604a9396957..040465103d08f23be0328383c5b9569f89b64784 100644 --- a/modules/search/search.test +++ b/modules/search/search.test @@ -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, diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module index 0e704d25cbcb3e0b240b6f355cec0254ee805283..fbeb6de4544cf2ce31cb091d380fba36c0fe04ab 100644 --- a/modules/simpletest/tests/form_test.module +++ b/modules/simpletest/tests/form_test.module @@ -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', ), ); diff --git a/modules/taxonomy/taxonomy.install b/modules/taxonomy/taxonomy.install index 9cd500deb4728cb148e2a1c1a3b2a461b12cc5d2..dd97edde478a25f2e77c2220e70040cac70386ae 100644 --- a/modules/taxonomy/taxonomy.install +++ b/modules/taxonomy/taxonomy.install @@ -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.', ), diff --git a/modules/user/user.install b/modules/user/user.install index 9d5256e6239498be07dc546c4390aed471966c82..615743b8b67a69de33218de1babcdd9bdb948826 100644 --- a/modules/user/user.install +++ b/modules/user/user.install @@ -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. diff --git a/profiles/standard/standard.install b/profiles/standard/standard.install index 74b66a2524fa151128ddae33f7c360c32cdab09e..1d7bb2f555c15a1460e8bd3933ed8b615031e50f 100644 --- a/profiles/standard/standard.install +++ b/profiles/standard/standard.install @@ -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(