t('Table used to store data for module "developer_pages".'), 'fields' => array( 'nid' => array( 'description' => t('The node\'s ID.'), 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), 'vid' => array( 'description' => t('The primary identifier for a node\'s revision.'), 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), 'private' => array( 'description' => t('"private" field for module "developer_pages".'), 'type' => 'int', 'size' => 'normal' ) ), 'primary key' => array('vid'), 'unique keys' => array('vid_nid' => array('vid', 'nid')), ); return $schema; } /** * Creates required database tables */ function developer_pages_install() { drupal_install_schema('developer_pages'); } /** * Remove tables, sequence on uninstall. */ function developer_pages_uninstall() { drupal_uninstall_schema('developer_pages'); } /** * Control access on node-revision level. */ function developer_pages_update_6100() { // retrieve the nids of the nodes that are currently private $result = db_query("SELECT * FROM {developer_pages} WHERE private = 1"); $private_nodes = array(); while ($node = db_fetch_object($result)) { $private_nodes[] = $node; } // Alter the table // As we have to delete all data & indeces anyways, we just drop the table and reinstall it // using the new schema. $ret = array(); db_drop_table($ret, 'developer_pages'); $install_ret = drupal_install_schema('developer_pages'); $ret[] = array('success' => $install_ret[0]['success'], 'query' => $install_ret[0]['query']); // Insert nodes again. // Restrict access to all revisions of currently private nodes $result = array(); foreach ($private_nodes as $node) { $revs = node_revision_list($node); if (count($revs) > 0) { $sql = "INSERT INTO {developer_pages} (`vid`, `nid`, `private`) VALUES "; foreach ($revs as $r) { $sql .= "($r->vid, {$node->nid}, 1), "; } // ommit the last two chars $sql = substr($sql, 0, -2); // Insert it, with all revisions of the node db_query($sql); } } return $ret; }