function protected_node_action_protect_all_nodes in Protected Node 7
Same name and namespace in other branches
- 6 protected_node.settings.inc \protected_node_action_protect_all_nodes()
- 1.0.x protected_node.settings.inc \protected_node_action_protect_all_nodes()
Protect all nodes.
This function adds to the protected nodes list all the existing nodes and marks ALL nodes as protected.
1 string reference to 'protected_node_action_protect_all_nodes'
- protected_node_admin_settings in ./
protected_node.settings.inc - Define the settings form.
File
- ./
protected_node.settings.inc, line 902 - Configuration file for the protected_node module.
Code
function protected_node_action_protect_all_nodes($form, &$form_state) {
// First protect all nodes that already are in our table.
db_update('protected_nodes')
->fields(array(
'protected_node_is_protected' => 1,
))
->condition('protected_node_is_protected', 0)
->execute();
// Add never protected nodes to protected_nodes.
$nodes = db_select('node')
->fields('node', array(
'nid',
))
->execute();
foreach ($nodes as $node) {
$nid = $node->nid;
$nid_in_protected_node = db_select('protected_nodes')
->fields('protected_nodes', array(
'nid',
))
->condition('nid', $nid)
->execute()
->fetchfield();
if (!$nid_in_protected_node) {
// Add the node in protected_nodes.
db_insert('protected_nodes')
->fields(array(
'nid' => $nid,
'protected_node_is_protected' => '1',
'protected_node_show_title' => $form_state['values']['protected_node_show_node_titles'],
))
->execute();
}
}
}