Commit 35e7c83d authored by Dries's avatar Dries

- Patch #914458 by Damien Tournoud, chx: remove the format delete reassignment 'feature'.

parent f94b014c
......@@ -954,16 +954,6 @@ function block_user_role_delete($role) {
->execute();
}
/**
* Implements hook_filter_format_delete().
*/
function block_filter_format_delete($format, $fallback) {
db_update('block_custom')
->fields(array('format' => $fallback->format))
->condition('format', $format->format)
->execute();
}
/**
* Implements hook_menu_delete().
*/
......
......@@ -600,16 +600,13 @@ function text_field_prepare_translation($entity_type, $entity, $field, $instance
/**
* Implements hook_filter_format_update().
*/
function text_filter_format_update() {
function text_filter_format_update($format) {
field_cache_clear();
}
/**
* Implements hook_filter_format_delete().
*
* @todo D8: Properly update filter format references in all fields. See
* http://drupal.org/node/556022 for details.
* Implements hook_filter_format_disable().
*/
function text_filter_format_delete() {
function text_filter_format_disable($format) {
field_cache_clear();
}
......@@ -163,11 +163,11 @@ class TextFieldTestCase extends DrupalWebTestCase {
field_create_instance($this->instance);
$langcode = LANGUAGE_NONE;
// Delete all text formats besides the plain text fallback format.
// Disable all text formats besides the plain text fallback format.
$this->drupalLogin($this->admin_user);
foreach (filter_formats() as $format) {
if ($format->format != filter_fallback_format()) {
$this->drupalPost('admin/config/content/formats/' . $format->format . '/delete', array(), t('Delete'));
$this->drupalPost('admin/config/content/formats/' . $format->format . '/disable', array(), t('Disable'));
}
}
$this->drupalLogin($this->web_user);
......
......@@ -20,7 +20,7 @@ function filter_admin_overview($form) {
$form['#tree'] = TRUE;
foreach ($formats as $id => $format) {
// Check whether this is the fallback text format. This format is available
// to all roles and cannot be deleted via the admin interface.
// to all roles and cannot be disabled via the admin interface.
$form['formats'][$id]['#is_fallback'] = ($id == $fallback_format);
if ($form['formats'][$id]['#is_fallback']) {
$form['formats'][$id]['name'] = array('#markup' => drupal_placeholder($format->name));
......@@ -33,7 +33,7 @@ function filter_admin_overview($form) {
}
$form['formats'][$id]['roles'] = array('#markup' => $roles_markup);
$form['formats'][$id]['configure'] = array('#type' => 'link', '#title' => t('configure'), '#href' => 'admin/config/content/formats/' . $id);
$form['formats'][$id]['delete'] = array('#type' => 'link', '#title' => t('delete'), '#href' => 'admin/config/content/formats/' . $id . '/delete', '#access' => !$form['formats'][$id]['#is_fallback']);
$form['formats'][$id]['disable'] = array('#type' => 'link', '#title' => t('disable'), '#href' => 'admin/config/content/formats/' . $id . '/disable', '#access' => !$form['formats'][$id]['#is_fallback']);
$form['formats'][$id]['weight'] = array('#type' => 'weight', '#default_value' => $format->weight);
}
$form['actions'] = array('#type' => 'actions');
......@@ -76,7 +76,7 @@ function theme_filter_admin_overview($variables) {
drupal_render($form['formats'][$id]['roles']),
drupal_render($form['formats'][$id]['weight']),
drupal_render($form['formats'][$id]['configure']),
drupal_render($form['formats'][$id]['delete']),
drupal_render($form['formats'][$id]['disable']),
),
'class' => array('draggable'),
);
......@@ -317,40 +317,26 @@ function filter_admin_format_form_submit($form, &$form_state) {
* Menu callback; confirm deletion of a format.
*
* @ingroup forms
* @see filter_admin_delete_submit()
* @see filter_admin_disable_submit()
*/
function filter_admin_delete($form, &$form_state, $format) {
function filter_admin_disable($form, &$form_state, $format) {
$form['#format'] = $format;
$fallback_options = array();
foreach (filter_formats() as $id => $fallback_format) {
if ($id != $format->format) {
$fallback_options[$id] = $fallback_format->name;
}
}
$form['fallback'] = array(
'#type' => 'select',
'#title' => t('Replacement text format'),
'#options' => $fallback_options,
'#default_value' => filter_fallback_format(),
'#description' => t('Content assigned to the deleted text format will be reassigned to the chosen one.'),
);
return confirm_form($form,
t('Are you sure you want to delete the text format %format?', array('%format' => $format->name)),
t('Are you sure you want to disable the text format %format?', array('%format' => $format->name)),
'admin/config/content/formats',
NULL,
t('Delete')
t('This action cannot be undone.'),
t('Disable')
);
}
/**
* Process filter delete form submission.
* Process filter disable form submission.
*/
function filter_admin_delete_submit($form, &$form_state) {
function filter_admin_disable_submit($form, &$form_state) {
$format = $form['#format'];
filter_format_delete($format, $form_state['values']['fallback']);
drupal_set_message(t('Deleted text format %format.', array('%format' => $format->name)));
filter_format_disable($format);
drupal_set_message(t('Disabled text format %format.', array('%format' => $format->name)));
$form_state['redirect'] = 'admin/config/content/formats';
}
......
......@@ -209,7 +209,7 @@ function hook_filter_info_alter(&$info) {
* The format object of the format being updated.
*
* @see hook_filter_format_update()
* @see hook_filter_format_delete()
* @see hook_filter_format_disable()
*/
function hook_filter_format_insert($format) {
mymodule_cache_rebuild();
......@@ -226,34 +226,23 @@ function hook_filter_format_insert($format) {
* The format object of the format being updated.
*
* @see hook_filter_format_insert()
* @see hook_filter_format_delete()
* @see hook_filter_format_disable()
*/
function hook_filter_format_update($format) {
mymodule_cache_rebuild();
}
/**
* Perform actions when a text format has been deleted.
*
* All modules storing references to text formats have to implement this hook.
*
* When a text format is deleted, all content that previously had that format
* assigned needs to be switched to the passed fallback format.
* Perform actions when a text format has been disabled.
*
* @param $format
* The format object of the format being deleted.
* @param $fallback
* The format object of the format to use as replacement.
* The format object of the format being disabled.
*
* @see hook_filter_format_insert()
* @see hook_filter_format_update()
*/
function hook_filter_format_delete($format, $fallback) {
// Replace the deleted format with the fallback format.
db_update('my_module_table')
->fields(array('format' => $fallback->format))
->condition('format', $format->format)
->execute();
function hook_filter_format_disable($format) {
mymodule_cache_rebuild();
}
/**
......
......@@ -81,19 +81,27 @@ function filter_schema() {
'size' => 'tiny',
'description' => 'Flag to indicate whether format is cacheable. (1 = cacheable, 0 = not cacheable)',
),
'status' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
'size' => 'tiny',
'description' => 'The status of the text format. (1 = enabled, 0 = disabled)',
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Weight of text format to use when listing.',
)
),
),
'primary key' => array('format'),
'unique keys' => array(
'name' => array('name'),
),
'indexes' => array(
'weight' => array('weight'),
'status_weight' => array('status', 'weight'),
),
);
......@@ -162,7 +170,15 @@ function filter_update_dependencies() {
function filter_update_7000() {
db_rename_table('filter_formats', 'filter_format');
// Add a new filter_format.weight column.
// Add the new {filter_format}.status and {filter_format}.weight column.
db_add_field('filter_format', 'status', array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
'size' => 'tiny',
'description' => 'The status of the text format. (1 = enabled, 0 = disabled)',
));
db_add_field('filter_format', 'weight', array(
'type' => 'int',
'not null' => TRUE,
......@@ -170,7 +186,7 @@ function filter_update_7000() {
'description' => 'Weight of text format to use when listing.',
), array(
'indexes' => array(
'weight' => array('weight'),
'status_weight' => array('status', 'weight'),
),
));
}
......@@ -367,6 +383,7 @@ function filter_update_7005() {
'name' => $format_name,
'cache' => 1,
'weight' => 1,
'status' => 1,
))
->execute();
......
......@@ -122,11 +122,11 @@ function filter_menu() {
'access arguments' => array('administer filters'),
'file' => 'filter.admin.inc',
);
$items['admin/config/content/formats/%filter_format/delete'] = array(
'title' => 'Delete text format',
$items['admin/config/content/formats/%filter_format/disable'] = array(
'title' => 'Disable text format',
'page callback' => 'drupal_get_form',
'page arguments' => array('filter_admin_delete', 4),
'access callback' => '_filter_delete_format_access',
'page arguments' => array('filter_admin_disable', 4),
'access callback' => '_filter_disable_format_access',
'access arguments' => array(4),
'type' => MENU_CALLBACK,
'file' => 'filter.admin.inc',
......@@ -140,11 +140,11 @@ function filter_menu() {
* @param $format
* A text format object.
* @return
* TRUE if the text format can be deleted by the current user, FALSE
* TRUE if the text format can be disabled by the current user, FALSE
* otherwise.
*/
function _filter_delete_format_access($format) {
// The fallback format can never be deleted.
function _filter_disable_format_access($format) {
// The fallback format can never be disabled.
return user_access('administer filters') && ($format->format != filter_fallback_format());
}
......@@ -187,6 +187,7 @@ function filter_format_load($format_id) {
function filter_format_save(&$format) {
$format->name = trim($format->name);
$format->cache = _filter_format_is_cacheable($format);
$format->status = 1;
// Programmatic saves may not contain any filters.
if (!isset($format->filters)) {
$format->filters = array();
......@@ -256,31 +257,26 @@ function filter_format_save(&$format) {
}
/**
* Delete a text format.
* Disable a text format.
*
* There is no core facility to re-enable a disabled format. It is not deleted
* to keep information for contrib and to make sure the format auto increment
* id is never reused. As there might be content using the disabled format,
* this would lead to data corruption.
*
* @param $format
* The text format object to be deleted.
* @param $fallback_id
* (optional) The ID of the text format to use to reassign content that is
* currently using $format. If omitted, the currently stored
* filter_fallback_format() is used.
* The text format object to be disabled.
*/
function filter_format_delete($format, $fallback_id = NULL) {
db_delete('filter_format')
->condition('format', $format->format)
->execute();
db_delete('filter')
function filter_format_disable($format) {
db_update('filter_format')
->fields(array('status' => 0))
->condition('format', $format->format)
->execute();
// Allow modules to react on text format deletion.
if (empty($fallback_id)) {
$fallback_id = filter_fallback_format();
}
$fallback = filter_format_load($fallback_id);
module_invoke_all('filter_format_delete', $format, $fallback);
module_invoke_all('filter_format_disable', $format);
// Clear the filter cache whenever a text format is deleted.
// Clear the filter cache whenever a text format is disabled.
filter_formats_reset();
cache_clear_all($format->format . ':', 'cache_filter', TRUE);
}
......@@ -381,6 +377,7 @@ function filter_formats($account = NULL) {
$formats['all'] = db_select('filter_format', 'ff')
->addTag('translatable')
->fields('ff')
->condition('status', 1)
->orderBy('weight')
->execute()
->fetchAllAssoc('format');
......@@ -488,7 +485,7 @@ function filter_default_format($account = NULL) {
*
* The fallback text format is a regular text format in every respect, except
* it does not participate in the filter permission system and cannot be
* deleted. It needs to exist because any user who has permission to create
* disabled. It needs to exist because any user who has permission to create
* formatted content must always have at least one text format they can use.
*
* Because the fallback format is available to all users, it should always be
......@@ -503,15 +500,19 @@ function filter_default_format($account = NULL) {
* the fallback format's weight determines its placement with respect to the
* user's other formats.
*
* @see hook_filter_format_delete()
* Any modules implementing a format deletion functionality must not delete
* this format.
*
* @see hook_filter_format_disable()
* @see filter_default_format()
*/
function filter_fallback_format() {
// This variable is automatically set in the database for all installations
// of Drupal. In the event that it gets deleted somehow, there is no safe
// default to return, since we do not want to risk making an existing (and
// potentially unsafe) text format on the site automatically available to all
// users. Returning NULL at least guarantees that this cannot happen.
// of Drupal. In the event that it gets disabled or deleted somehow, there
// is no safe default to return, since we do not want to risk making an
// existing (and potentially unsafe) text format on the site automatically
// available to all users. Returning NULL at least guarantees that this
// cannot happen.
return variable_get('filter_fallback_format');
}
......
......@@ -57,14 +57,13 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
$this->verifyTextFormat($format);
$this->verifyFilters($format);
// Delete the text format.
filter_format_delete($format);
// Disable the text format.
filter_format_disable($format);
$db_format = db_query("SELECT * FROM {filter_format} WHERE format = :format", array(':format' => $format->format))->fetchObject();
$this->assertFalse($db_format, t('Database: Deleted text format no longer exists.'));
$db_filters = db_query("SELECT * FROM {filter} WHERE format = :format", array(':format' => $format->format))->fetchObject();
$this->assertFalse($db_filters, t('Database: Filters for deleted text format no longer exist.'));
$this->assertFalse($db_format->status, t('Database: Disabled text format is marked as disabled.'));
$formats = filter_formats();
$this->assertTrue(!isset($formats[$format->format]), t('filter_formats: Deleted text format no longer exists.'));
$this->assertTrue(!isset($formats[$format->format]), t('filter_formats: Disabled text format no longer exists.'));
}
/**
......@@ -196,15 +195,15 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$this->drupalGet('admin/config/content/formats/' . $format->format);
$this->drupalPost(NULL, array(), t('Save configuration'));
// Delete text format.
// Disable text format.
$this->drupalGet('admin/config/content/formats');
$this->assertRaw('admin/config/content/formats/' . $format->format . '/delete');
$this->drupalGet('admin/config/content/formats/' . $format->format . '/delete');
$this->drupalPost(NULL, array(), t('Delete'));
$this->assertRaw('admin/config/content/formats/' . $format->format . '/disable');
$this->drupalGet('admin/config/content/formats/' . $format->format . '/disable');
$this->drupalPost(NULL, array(), t('Disable'));
// Verify that deleted text format no longer exists.
// Verify that disabled text format no longer exists.
$this->drupalGet('admin/config/content/formats/' . $format->format);
$this->assertResponse(404, t('Deleted text format no longer exists.'));
$this->assertResponse(404, t('Disabled text format no longer exists.'));
}
/**
......@@ -218,12 +217,12 @@ class FilterAdminTestCase extends DrupalWebTestCase {
list($filtered, $full, $plain) = $this->checkFilterFormats();
// Check that the fallback format exists and cannot be deleted.
// Check that the fallback format exists and cannot be disabled.
$this->assertTrue(!empty($plain) && $plain == filter_fallback_format(), t('The fallback format is set to plain text.'));
$this->drupalGet('admin/config/content/formats');
$this->assertNoRaw('admin/config/content/formats/' . $plain . '/delete', t('Delete link for the fallback format not found.'));
$this->drupalGet('admin/config/content/formats/' . $plain . '/delete');
$this->assertResponse(403, t('The fallback format cannot be deleted.'));
$this->assertNoRaw('admin/config/content/formats/' . $plain . '/disable', t('Disable link for the fallback format not found.'));
$this->drupalGet('admin/config/content/formats/' . $plain . '/disable');
$this->assertResponse(403, t('The fallback format cannot be disabled.'));
// Verify access permissions to Full HTML format.
$this->assertTrue(filter_access(filter_format_load($full), $this->admin_user), t('Admin user may use Full HTML.'));
......@@ -283,9 +282,9 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$this->assertFieldByName('filters[' . $second_filter . '][status]', '', t('Line break filter found.'));
$this->assertFieldByName('filters[' . $first_filter . '][status]', '', t('Url filter found.'));
// Delete new filter.
$this->drupalPost('admin/config/content/formats/' . $format->format . '/delete', array(), t('Delete'));
$this->assertRaw(t('Deleted text format %format.', array('%format' => $edit['name'])), t('Format successfully deleted.'));
// Disable new filter.
$this->drupalPost('admin/config/content/formats/' . $format->format . '/disable', array(), t('Disable'));
$this->assertRaw(t('Disabled text format %format.', array('%format' => $edit['name'])), t('Format successfully disabled.'));
// Allow authenticated users on full HTML.
$format = filter_format_load($full);
......@@ -530,8 +529,8 @@ class FilterFormatAccessTestCase extends DrupalWebTestCase {
$this->assertText($new_edit['title'], t('New title found.'));
$this->assertText($edit[$body_value_key], t('Old body found.'));
// Delete the Full HTML text format.
filter_format_delete($this->full_html_format);
// Disable the Full HTML text format.
filter_format_disable($this->full_html_format);
$this->resetFilterCaches();
// Verify that body field can be edited and a new format can be selected.
......@@ -679,8 +678,8 @@ class FilterSecurityTestCase extends DrupalWebTestCase {
$this->assertNoText($body_raw, t('Node body not found.'));
$this->assertText('Filter: Testing filter', t('Testing filter output found.'));
// Delete the text format entirely.
$this->drupalPost('admin/config/content/formats/' . $format_id . '/delete', array(), t('Delete'));
// Disable the text format entirely.
$this->drupalPost('admin/config/content/formats/' . $format_id . '/disable', array(), t('Disable'));
// Verify that the content is empty, because the text format does not exist.
$this->drupalGet('node/' . $node->nid);
......@@ -1587,7 +1586,7 @@ class FilterHooksTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Filter format hooks',
'description' => 'Test hooks for text formats insert/update/delete.',
'description' => 'Test hooks for text formats insert/update/disable.',
'group' => 'Filter',
);
}
......@@ -1634,18 +1633,10 @@ class FilterHooksTestCase extends DrupalWebTestCase {
$bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
$this->assertNotNull($bid, t('New block found in database'));
// Delete the text format.
$this->drupalPost('admin/config/content/formats/' . $format_id . '/delete', array(), t('Delete'));
$this->assertRaw(t('Deleted text format %format.', array('%format' => $name)), t('Format successfully deleted.'));
$this->assertText('hook_filter_format_delete invoked.', t('hook_filter_format_delete() was invoked.'));
// Verify that the deleted format was replaced with the fallback format.
$current_format = db_select('block_custom', 'b')
->fields('b', array('format'))
->condition('bid', $bid)
->execute()
->fetchField();
$this->assertEqual($current_format, filter_fallback_format(), t('Deleted text format replaced with the fallback format.'));
// Disable the text format.
$this->drupalPost('admin/config/content/formats/' . $format_id . '/disable', array(), t('Disable'));
$this->assertRaw(t('Disabled text format %format.', array('%format' => $name)), t('Format successfully disabled.'));
$this->assertText('hook_filter_format_disable invoked.', t('hook_filter_format_disable() was invoked.'));
}
}
......@@ -21,10 +21,10 @@ function filter_test_filter_format_update($format) {
}
/**
* Implements hook_filter_format_delete().
* Implements hook_filter_format_disable().
*/
function filter_test_filter_format_delete($format, $default) {
drupal_set_message('hook_filter_format_delete invoked.');
function filter_test_filter_format_disable($format) {
drupal_set_message('hook_filter_format_disable invoked.');
}
/**
......
......@@ -3597,16 +3597,6 @@ function user_modules_uninstalled($modules) {
->execute();
}
/**
* Implements hook_filter_format_delete().
*/
function user_filter_format_delete($format, $fallback) {
db_update('users')
->fields(array('signature_format' => $fallback->format))
->condition('signature_format', $format->format)
->execute();
}
/**
* Helper function to rewrite the destination to avoid redirecting to login page after login.
*
......
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