2"); db_query("TRUNCATE TABLE {vocabulary}"); db_query("TRUNCATE TABLE {vocabulary_node_types}"); db_query("TRUNCATE TABLE {term_node}"); db_query("TRUNCATE TABLE {term_data}"); db_query("TRUNCATE TABLE {term_hierarchy}"); db_query("TRUNCATE TABLE {term_access}"); db_query("TRUNCATE TABLE {term_access_defaults}"); // For now, V/U/D are all the same. // The three are completely independent and the logic is identical. $node_grants = array('grant_view', 'grant_update', 'grant_delete'); $grant_types = array( 'A' => array(), 'I' => array(), 'D' => array(), 'NC' => array(), ); foreach ($node_grants as $grant) { $grant_types['A'][$grant] = 1; $grant_types['I'][$grant] = 0; $grant_types['D'][$grant] = 2; } // These are here for later. $term_grants = array('grant_create', 'grant_list'); // There are three roles: // 3 - Receives "Allow" in the global default. // 4 - Receives "Ignore" in the global default. // 5 - Receives "Deny" in the global default. // All three receive the same permissions for terms and vocab defaults. db_query( "INSERT INTO {role} (rid, name) VALUES (3, 'Global Allow'), (4, 'Global Ignore'), (5, 'Global Deny')" ); $roles = array(3, 4, 5); _insert_grant_record(0, 3, $grant_types['A'], TRUE); _insert_grant_record(0, 4, $grant_types['I'], TRUE); _insert_grant_record(0, 5, $grant_types['D'], TRUE); // Create 4 vocabularies: A, I, D, and NC // These names indicate what grant the vocab. default will have for view. // (NC means the vocab default is not configured.) // View alone can be used to test V/U/D because the logic is identical. // Each vocabulary has four parent terms in the same fashion: // A-parent, I-parent, D-parent, and NC-parent. // Each of these-parent terms has children in each class, as well: // A-child, I-child, D-child, and NC-child. // So, each vocab looks something like: // - A-parent // - - A-child // - - I-child // - - D-child // - - NC-child // - I-parent // - - A-child // - - I-child // - - D-child // - - NC-child // - D-parent // - - A-child // - - I-child // - - D-child // - - NC-child // - NC-parent // - - A-child // - - I-child // - - D-child // - - NC-child $vocab_id = 0; $term_id = 0; foreach ($grant_types as $vocab_name => $default_grants) { // Add vocabularies. $vocab_id++; $q = "INSERT INTO {vocabulary} (vid, name, multiple) VALUES (%d, '%s', 1)"; db_query($q, $vocab_id, $vocab_name . "-vocab"); $q = "INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, 'page')"; db_query($q, $vocab_id); // Insert the appropriate vocab default grants for each role. if (!empty($default_grants)) { foreach ($roles as $rid) { _insert_grant_record($vocab_id, $rid, $default_grants, TRUE); } } // Add parent terms. foreach ($grant_types as $parent_name => $parent_grants) { $term_id++; // Insert the term and its hierarchy. $parent_name = "[" . $vocab_name . "] " . $parent_name . "-parent"; _insert_term_record($term_id, $vocab_id, $parent_name, 0); // Insert the appropriate term grants for each role. if (!empty($parent_grants)) { foreach ($roles as $rid) { _insert_grant_record($term_id, $rid, $parent_grants); } } // Add child terms. $parent_id = $term_id; foreach ($grant_types as $child_name => $child_grants) { $term_id++; // Insert the term and its hierarchy. $name = $parent_name . " - " . $child_name . "-child"; _insert_term_record($term_id, $vocab_id, $name, $parent_id); // Insert the appropriate term grants for each role. if (!empty($child_grants)) { foreach ($roles as $rid) { _insert_grant_record($term_id, $rid, $child_grants); } } } } } } function _insert_term_record($tid, $vid, $name, $parent = 0) { $q = "INSERT INTO {term_data} (tid, vid, name) VALUES (%d, %d, '%s')"; db_query($q, $tid, $vid, $name); $q = "INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)"; db_query($q, $tid, $parent); } function _insert_grant_record($id, $rid, $grants, $vocab = FALSE) { $table = $vocab ? "{term_access_defaults}" : "{term_access}"; $key = $vocab ? "vid" : "tid"; $q = "INSERT INTO " . db_escape_table($table) . " " . "(" . db_escape_table($key) . ", rid, " . implode(",", array_map('db_escape_table', array_keys($grants))) . ", grant_create, grant_list)" . "VALUES (%d, %d, " . db_placeholders($grants) . ", 0, 1)" ; $args = array(); $args[] = $id; $args[] = $rid; $args = array_merge($args, $grants); db_query($q, $args); }