Commit 96ca81fb authored by Dries's avatar Dries

- Patch #394484 by Berdir and Crell: converted node module to the new database...

- Patch #394484 by Berdir and Crell: converted node module to the new database abstraction layer. Yay.
parent 57b558e3
......@@ -391,7 +391,7 @@ function node_type_delete_confirm(&$form_state, $type) {
$message = t('Are you sure you want to delete the content type %type?', array('%type' => $type->name));
$caption = '';
$num_nodes = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = '%s'", $type->type));
$num_nodes = db_query("SELECT COUNT(*) FROM {node} WHERE type = :type", array(':type' => $type->type))->fetchField();
if ($num_nodes) {
$caption .= '<p>' . format_plural($num_nodes, '<strong>Warning:</strong> there is currently 1 %type post on your site. It may not be able to be displayed or edited correctly, once you have removed this content type.', '<strong>Warning:</strong> there are currently @count %type posts on your site. They may not be able to be displayed or edited correctly, once you have removed this content type.', array('%type' => $type->name)) . '</p>';
}
......
......@@ -13,7 +13,7 @@ function node_configure() {
// Only show rebuild button if there are either 0, or 2 or more, rows
// in the {node_access} table, or if there are modules that
// implement hook_node_grants().
if (db_result(db_query('SELECT COUNT(*) FROM {node_access}')) != 1 || count(module_implements('node_grants')) > 0) {
if (db_query('SELECT COUNT(*) FROM {node_access}')->fetchField() != 1 || count(module_implements('node_grants')) > 0) {
$status = '<p>' . t('If the site is experiencing problems with permissions to content, you may have to rebuild the permissions cache. Possible causes for permission problems are disabling modules or configuration changes to permissions. Rebuilding will remove all privileges to posts, and replace them with permissions based on the current modules and settings.') . '</p>';
$status .= '<p>' . t('Rebuilding may take some time if there is a lot of content or complex permission settings. After rebuilding has completed posts will automatically use the new permissions.') . '</p>';
......@@ -457,7 +457,7 @@ function node_admin_content($form_state) {
function node_admin_nodes() {
// Enable language column if translation module is enabled
// or if we have any node with language.
$multilanguage = (module_exists('translation') || db_result(db_query("SELECT COUNT(*) FROM {node} WHERE language != ''")));
$multilanguage = (module_exists('translation') || db_query("SELECT COUNT(*) FROM {node} WHERE language != ''")->fetchField());
// Build the sortable table header.
$header = array();
......@@ -624,7 +624,7 @@ function node_multiple_delete_confirm(&$form_state, $nodes) {
$form['nodes'] = array('#prefix' => '<ul>', '#suffix' => '</ul>', '#tree' => TRUE);
// array_filter returns only elements with TRUE values
foreach ($nodes as $nid => $value) {
$title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
$title = db_query('SELECT title FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
$form['nodes'][$nid] = array(
'#type' => 'hidden',
'#value' => $nid,
......
......@@ -181,7 +181,9 @@ function hook_node_alter($node, $teaser) {
* None.
*/
function hook_node_delete($node) {
db_query('DELETE FROM {mytable} WHERE nid = %d', $node->nid);
db_delete('mytable')
->condition('nid', $node->nid)
->execute();
}
/**
......@@ -215,7 +217,12 @@ function hook_node_delete_revision($node) {
* None.
*/
function hook_node_insert($node) {
db_query("INSERT INTO {mytable} (nid, extra) VALUES (%d, '%s')", $node->nid, $node->extra);
db_insert('mytable')
->fields(array(
'nid' => $node->nid,
'extra' => $node->extra,
))
->execute();
}
/**
......@@ -344,7 +351,10 @@ function hook_node_presave($node) {
* None.
*/
function hook_node_update($node) {
db_query("UPDATE {mytable} SET extra = '%s' WHERE nid = %d", $node->extra, $node->nid);
db_update('mytable')
->fields(array('extra' => $node->extra))
->condition('nid', $node->nid)
->execute();
}
/**
......@@ -565,7 +575,9 @@ function hook_access($op, $node, $account) {
* For a detailed usage example, see node_example.module.
*/
function hook_delete(&$node) {
db_query('DELETE FROM {mytable} WHERE nid = %d', $node->nid);
db_delete('mytable')
->condition('nid', $nid->nid)
->execute();
}
/**
......
This diff is collapsed.
......@@ -602,12 +602,15 @@ function node_revision_delete_confirm($form_state, $node_revision) {
function node_revision_delete_confirm_submit($form, &$form_state) {
$node_revision = $form['#node_revision'];
db_query("DELETE FROM {node_revision} WHERE nid = %d AND vid = %d", $node_revision->nid, $node_revision->vid);
db_delete('node_revision')
->condition('nid', $node_revision->nid)
->condition('vid', $node_revision->vid)
->execute();
node_invoke_node($node_revision, 'delete_revision');
watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title, '%revision' => $node_revision->vid));
drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($node_revision->revision_timestamp), '@type' => node_get_types('name', $node_revision), '%title' => $node_revision->title)));
$form_state['redirect'] = 'node/' . $node_revision->nid;
if (db_result(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = %d', $node_revision->nid)) > 1) {
if (db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid', array(':nid' => $node_revision->nid))->fetchField() > 1) {
$form_state['redirect'] .= '/revisions';
}
}
......@@ -162,7 +162,7 @@ class NodeRevisionsTestCase extends DrupalWebTestCase {
$this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.',
array('%revision-date' => format_date($nodes[1]->revision_timestamp),
'@type' => 'Page', '%title' => $nodes[1]->title)), t('Revision deleted.'));
$this->assertTrue(db_result(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = %d and vid = %d', $node->nid, $nodes[1]->vid)) == 0, t('Revision not found.'));
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', array(':nid' => $node->nid, ':vid' => $nodes[1]->vid))->fetchField() == 0, t('Revision not found.'));
}
}
......
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