Created
March 28, 2014 03:45
-
-
Save xurizaemon/9824872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = Filter Cleanup | |
description = | |
package = | |
core = 7.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_menu(). | |
*/ | |
function filter_cleanup_menu() { | |
$items['admin/reports/format_cleanup'] = array( | |
'page callback' => 'filter_cleanup_page_format_cleanup', | |
'access arguments' => array('administer site configuration'), | |
'title' => 'Text Format Cleanup', | |
); | |
return $items; | |
} | |
/** | |
* Page callback that replaces all existing filter formats. | |
*/ | |
function filter_cleanup_page_format_cleanup() { | |
$schema = drupal_get_schema(); | |
$excluded = array('filter', 'date_format', 'filter_format'); | |
$to_update = array(); | |
$formats = array( | |
'1' => 'filtered_html', | |
'2' => 'full_html', | |
'3' => 'plain_text', | |
); | |
foreach ($schema as $table_name => $table) { | |
foreach ($table['fields'] as $field_name => $field) { | |
if (stristr($field_name, 'format')) { | |
$to_update[$table_name][] = $field_name; | |
} | |
} | |
} | |
foreach ($formats as $from => $to) { | |
$targs = array( | |
'@from' => $from, | |
'@to' => $to, | |
); | |
$updated = db_update('filter') | |
->fields(array('format' => $to)) | |
->condition('format', $from, '=') | |
->execute(); | |
dpm($updated, 'filter:format'); | |
$updated = db_update('filter_format') | |
->fields(array('format' => $to)) | |
->condition('format', $from, '=') | |
->execute(); | |
dpm($updated, 'filter_format:format'); | |
//$sql[] = t("UPDATE filter_format SET format = '@to' WHERE format = '@from';", $targs); | |
//$sql[] = t("UPDATE filter SET format = '@to' WHERE format = '@from';", $targs); | |
foreach ($to_update as $table_name => $table) { | |
if (!in_array($table_name, $excluded)) { | |
foreach ($table as $field_name) { | |
$targs = array( | |
'@table_name' => $table_name, | |
'@field_name' => $field_name, | |
'@from' => $from, | |
'@to' => $to, | |
); | |
//$sql[] = t("UPDATE @table_name SET @field_name = '@to' WHERE @field_name = '@from';", $targs); | |
//$sql[] = t('SELECT DISTINCT @field_name FROM @table_name;', $targs); | |
$updated = db_update($table_name) | |
->fields(array($field_name => $to)) | |
->condition($field_name, $from, '=') | |
->execute(); | |
} | |
} | |
} | |
} | |
ksort($to_update); | |
//dpm($schema, 'schema'); | |
//dpm($to_update, 'to_update'); | |
//return '<pre>' . implode("\n", $sql) . '</pre>'; | |
return 'Filters updated.'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment