diff options
Diffstat (limited to 'modules/field')
-rw-r--r-- | modules/field/field.install | 16 | ||||
-rw-r--r-- | modules/field/modules/text/text.install | 36 | ||||
-rw-r--r-- | modules/field/modules/text/text.test | 29 |
3 files changed, 67 insertions, 14 deletions
diff --git a/modules/field/field.install b/modules/field/field.install index 91b0d210f..34afd5ad1 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 29cd07b87..3854e5688 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 bfc9156e5..5f4b0c19d 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))); |