Commit 25fad504 authored by Dries's avatar Dries

- Patch #394146 by ksenzee, csevb10, dropcube: converted to the new database abstraction layer.

parent fb5d44bc
......@@ -50,7 +50,10 @@ function filter_admin_overview_submit($form, &$form_state) {
foreach ($form_state['values'] as $id => $data) {
if (is_array($data) && isset($data['weight'])) {
// Only update if this is a form element with weight.
db_query("UPDATE {filter_format} SET weight = %d WHERE format = %d", $data['weight'], $id);
db_update('filter_format')
->fields(array('weight' => $data['weight']))
->condition('format', $id)
->execute();
}
}
drupal_set_message(t('The text format ordering has been saved.'));
......@@ -239,7 +242,14 @@ function filter_admin_format_form_submit($form, &$form_state) {
$roles = ',' . implode(',', $roles) . ',';
}
db_query("UPDATE {filter_format} SET cache = %d, name='%s', roles = '%s' WHERE format = %d", $cache, $name, $roles, $format);
db_update('filter_format')
->fields(array(
'cache' => $cache,
'name' => $name,
'roles' => $roles,
))
->condition('format', $format)
->execute();
cache_clear_all($format . ':', 'cache_filter', TRUE);
......@@ -260,7 +270,7 @@ function filter_admin_format_form_submit($form, &$form_state) {
*/
function filter_admin_delete() {
$format = arg(4);
$format = db_fetch_object(db_query('SELECT * FROM {filter_format} WHERE format = %d', $format));
$format = db_query('SELECT * FROM {filter_format} WHERE format = :format', array(':format' => $format))->fetchObject();
if ($format) {
if ($format->format != variable_get('filter_default_format', 1)) {
......@@ -283,14 +293,31 @@ function filter_admin_delete() {
* Process filter delete form submission.
*/
function filter_admin_delete_submit($form, &$form_state) {
db_query("DELETE FROM {filter_format} WHERE format = %d", $form_state['values']['format']);
db_query("DELETE FROM {filter} WHERE format = %d", $form_state['values']['format']);
db_delete('filter_format')
->condition('format', $form_state['values']['format'])
->execute();
db_delete('filter')
->condition('format', $form_state['values']['format'])
->execute();
$default = variable_get('filter_default_format', 1);
// Replace existing instances of the deleted format with the default format.
db_query("UPDATE {node_revision} SET format = %d WHERE format = %d", $default, $form_state['values']['format']);
db_query("UPDATE {comment} SET format = %d WHERE format = %d", $default, $form_state['values']['format']);
db_query("UPDATE {box} SET format = %d WHERE format = %d", $default, $form_state['values']['format']);
db_update('node_revision')
->fields(array('format' => $default))
->condition('format', $form_state['values']['format'])
->execute();
if (db_table_exists('comment')) {
db_update('comment')
->fields(array('format' => $default))
->condition('format', $form_state['values']['format'])
->execute();
}
if (db_table_exists('box')) {
db_update('box')
->fields(array('format' => $default))
->condition('format', $form_state['values']['format'])
->execute();
}
cache_clear_all($form_state['values']['format'] . ':', 'cache_filter', TRUE);
drupal_set_message(t('Deleted text format %format.', array('%format' => $form_state['values']['name'])));
......@@ -404,7 +431,12 @@ function theme_filter_admin_order($form) {
function filter_admin_order_submit($form, &$form_state) {
foreach ($form_state['values']['weights'] as $id => $weight) {
list($module, $delta) = explode('/', $id);
db_query("UPDATE {filter} SET weight = %d WHERE format = %d AND module = '%s' AND delta = %d", $weight, $form_state['values']['format'], $module, $delta);
db_update('filter')
->fields(array('weight' => $weight))
->condition('format', $form_state['values']['format'])
->condition('module', $module)
->condition('delta', $delta)
->execute();
}
drupal_set_message(t('The filter ordering has been saved.'));
......
......@@ -113,7 +113,7 @@ function filter_update_7000() {
function filter_update_7001() {
$ret = array();
$result = db_query("SELECT format FROM {filter_formats}");
while ($format = db_fetch_object($result)) {
foreach ($result as $format) {
// Deprecated constants FILTER_HTML_STRIP = 1 and FILTER_HTML_ESCAPE = 2.
if (variable_get('filter_html_' . $format->format, 1) == 2) {
$ret[] = update_sql("INSERT INTO {filters} (format, module, delta, weight) VALUES (" . $format->format . ", 'filter', 4, 0)");
......
......@@ -364,7 +364,7 @@ function filter_format_allowcache($format) {
static $cache = array();
$format = filter_resolve_format($format);
if (!isset($cache[$format])) {
$cache[$format] = db_result(db_query('SELECT cache FROM {filter_format} WHERE format = %d', $format));
$cache[$format] = db_query('SELECT cache FROM {filter_format} WHERE format = :format', array(':format' => $format))->fetchField();
}
return $cache[$format];
}
......@@ -377,8 +377,8 @@ function filter_list_format($format) {
if (!isset($filters[$format])) {
$filters[$format] = array();
$result = db_query("SELECT * FROM {filter} WHERE format = %d ORDER BY weight, module, delta", $format);
while ($filter = db_fetch_object($result)) {
$result = db_query("SELECT * FROM {filter} WHERE format = :format ORDER BY weight, module, delta", array(':format' => $format));
foreach ($result as $filter) {
$list = module_invoke($filter->module, 'filter', 'list');
if (isset($list) && is_array($list) && isset($list[$filter->delta])) {
$filter->name = $list[$filter->delta];
......@@ -549,7 +549,7 @@ function _filter_tips($format, $long = FALSE) {
$formats = filter_formats();
}
else {
$formats = array(db_fetch_object(db_query("SELECT * FROM {filter_format} WHERE format = %d", $format)));
$formats = array(db_query("SELECT * FROM {filter_format} WHERE format = :format", array(':format' => $format))->fetchObject());
}
$tips = array();
......
......@@ -41,7 +41,7 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$this->assertRaw(htmlentities($edit['allowed_html_1']), t('Tag displayed.'));
$result = db_fetch_object(db_query('SELECT * FROM {cache_filter}'));
$result = db_query('SELECT * FROM {cache_filter}')->fetchObject();
$this->assertFalse($result, t('Cache cleared.'));
// Reorder filters.
......@@ -51,9 +51,9 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$this->drupalPost('admin/settings/filter/' . $filtered . '/order', $edit, t('Save configuration'));
$this->assertText(t('The filter ordering has been saved.'), t('Order saved successfully.'));
$result = db_query('SELECT * FROM {filter} WHERE format = %d ORDER BY weight ASC', $filtered);
$result = db_query('SELECT * FROM {filter} WHERE format = :format ORDER BY weight ASC', array(':format' => $filtered));
$filters = array();
while ($filter = db_fetch_object($result)) {
foreach ($result as $filter) {
if ($filter->delta == $second_filter || $filter->delta == $first_filter) {
$filters[] = $filter;
}
......@@ -155,7 +155,7 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$filtered = -1;
$full = -1;
while ($format = db_fetch_object($result)) {
foreach ($result as $format) {
if ($format->name == 'Filtered HTML') {
$filtered = $format->format;
}
......@@ -174,7 +174,7 @@ class FilterAdminTestCase extends DrupalWebTestCase {
* @return object Filter object.
*/
function getFilter($name) {
return db_fetch_object(db_query("SELECT * FROM {filter_format} WHERE name = '%s'", $name));
return db_query("SELECT * FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchObject();
}
}
......@@ -224,7 +224,7 @@ class FilterTestCase extends DrupalWebTestCase {
'filters[filter/' . $filter . ']' => TRUE,
);
$this->drupalPost('admin/settings/filter/add', $edit, t('Save configuration'));
return db_fetch_object(db_query("SELECT * FROM {filter_format} WHERE name = '%s'", $edit['name']));
return db_query("SELECT * FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchObject();
}
function deleteFormat($format) {
......
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