Newer
Older
Angie Byron
committed
/**
* @file
* Install, update and uninstall functions for the node module.
*/
Dries Buytaert
committed
* Implements hook_schema().
*/
function node_schema() {
$schema['node'] = array(
Dries Buytaert
committed
'description' => 'The base table for nodes.',
'fields' => array(
'nid' => array(
Dries Buytaert
committed
'description' => 'The primary identifier for a node.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
Dries Buytaert
committed
'uuid' => array(
'description' => 'Unique Key: Universally unique identifier for this entity.',
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
Angie Byron
committed
// Defaults to NULL in order to avoid a brief period of potential
// deadlocks on the index.
'vid' => array(
Dries Buytaert
committed
'description' => 'The current {node_revision}.vid version identifier.',
'type' => 'int',
'unsigned' => TRUE,
Angie Byron
committed
'not null' => FALSE,
'default' => NULL,
'type' => array(
Dries Buytaert
committed
'description' => 'The {node_type}.type of this node.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'langcode' => array(
'description' => 'The {language}.langcode of this node.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'title' => array(
Dries Buytaert
committed
'description' => 'The title of this node, always treated as non-markup plain text.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'uid' => array(
Angie Byron
committed
'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
'type' => 'int',
Dries Buytaert
committed
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'status' => array(
Dries Buytaert
committed
'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'created' => array(
Dries Buytaert
committed
'description' => 'The Unix timestamp when the node was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
Dries Buytaert
committed
'description' => 'The Unix timestamp when the node was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'comment' => array(
Dries Buytaert
committed
'description' => 'Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write).',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'promote' => array(
Dries Buytaert
committed
'description' => 'Boolean indicating whether the node should be displayed on the front page.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'sticky' => array(
Dries Buytaert
committed
'description' => 'Boolean indicating whether the node should be displayed at the top of lists in which it appears.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'tnid' => array(
Dries Buytaert
committed
'description' => 'The translation set id for this node, which equals the node id of the source post in each set.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'translate' => array(
Dries Buytaert
committed
'description' => 'A boolean indicating whether this translation page needs to be updated.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'indexes' => array(
'node_changed' => array('changed'),
'node_created' => array('created'),
Dries Buytaert
committed
'node_frontpage' => array('promote', 'status', 'sticky', 'created'),
'node_status_type' => array('status', 'type', 'nid'),
'node_title_type' => array('title', array('type', 4)),
'node_type' => array(array('type', 4)),
'uid' => array('uid'),
'tnid' => array('tnid'),
'translate' => array('translate'),
'unique keys' => array(
'vid' => array('vid'),
Dries Buytaert
committed
'uuid' => array('uuid'),
'foreign keys' => array(
Dries Buytaert
committed
'node_revision' => array(
'table' => 'node_revision',
'columns' => array('vid' => 'vid'),
),
'node_author' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'primary key' => array('nid'),
$schema['node_access'] = array(
Dries Buytaert
committed
'description' => 'Identifies which realm/grant pairs a user must possess in order to view, update, or delete specific nodes.',
'fields' => array(
'nid' => array(
Dries Buytaert
committed
'description' => 'The {node}.nid this record affects.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'gid' => array(
Dries Buytaert
committed
'description' => "The grant ID a user must possess in the specified realm to gain this row's privileges on the node.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'realm' => array(
Dries Buytaert
committed
'description' => 'The realm in which the user must possess the grant ID. Each node access node can define one or more realms.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'grant_view' => array(
Dries Buytaert
committed
'description' => 'Boolean indicating whether a user with the realm/grant pair can view this node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
'grant_update' => array(
Dries Buytaert
committed
'description' => 'Boolean indicating whether a user with the realm/grant pair can edit this node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
'grant_delete' => array(
Dries Buytaert
committed
'description' => 'Boolean indicating whether a user with the realm/grant pair can delete this node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'primary key' => array('nid', 'gid', 'realm'),
Dries Buytaert
committed
'foreign keys' => array(
'affected_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
),
Dries Buytaert
committed
$schema['node_revision'] = array(
Dries Buytaert
committed
'description' => 'Stores information about each saved version of a {node}.',
'fields' => array(
'nid' => array(
Dries Buytaert
committed
'description' => 'The {node} this version belongs to.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'vid' => array(
Dries Buytaert
committed
'description' => 'The primary identifier for this version.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
Angie Byron
committed
'description' => 'The {users}.uid that created this version.',
'type' => 'int',
Dries Buytaert
committed
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'title' => array(
Dries Buytaert
committed
'description' => 'The title of this version.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'log' => array(
Dries Buytaert
committed
'description' => 'The log entry explaining the changes in this version.',
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
),
'timestamp' => array(
Dries Buytaert
committed
'description' => 'A Unix timestamp indicating when this version was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
Dries Buytaert
committed
'status' => array(
'description' => 'Boolean indicating whether the node (at the time of this revision) is published (visible to non-administrators).',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'comment' => array(
'description' => 'Whether comments are allowed on this node (at the time of this revision): 0 = no, 1 = closed (read only), 2 = open (read/write).',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'promote' => array(
'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed on the front page.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'sticky' => array(
'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed at the top of lists in which it appears.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'indexes' => array(
'nid' => array('nid'),
'uid' => array('uid'),
),
'primary key' => array('vid'),
'foreign keys' => array(
Dries Buytaert
committed
'versioned_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'version_author' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
$schema['node_type'] = array(
Dries Buytaert
committed
'description' => 'Stores information about all defined {node} types.',
'fields' => array(
'type' => array(
Dries Buytaert
committed
'description' => 'The machine-readable name of this type.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'name' => array(
Dries Buytaert
committed
'description' => 'The human-readable name of this type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
Dries Buytaert
committed
'translatable' => TRUE,
'base' => array(
Dries Buytaert
committed
'description' => 'The base string used to construct callbacks corresponding to this node type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
Angie Byron
committed
'module' => array(
'description' => 'The module defining this node type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'description' => array(
Dries Buytaert
committed
'description' => 'A brief description of this type.',
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
Dries Buytaert
committed
'translatable' => TRUE,
'help' => array(
Dries Buytaert
committed
'description' => 'Help information shown to the user when creating a {node} of this type.',
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
Dries Buytaert
committed
'translatable' => TRUE,
'has_title' => array(
Dries Buytaert
committed
'description' => 'Boolean indicating whether this type uses the {node}.title field.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'size' => 'tiny',
),
'title_label' => array(
Dries Buytaert
committed
'description' => 'The label displayed for the title field on the edit form.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
Dries Buytaert
committed
'translatable' => TRUE,
'custom' => array(
'description' => 'A boolean indicating whether this type is defined by a module (FALSE) or by a user via Add content type (TRUE).',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
'modified' => array(
Dries Buytaert
committed
'description' => 'A boolean indicating whether this type has been modified by an administrator; currently not used in any way.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
'locked' => array(
Dries Buytaert
committed
'description' => 'A boolean indicating whether the administrator can change the machine name of this type.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
Angie Byron
committed
'disabled' => array(
'description' => 'A boolean indicating whether the node type is disabled.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny'
),
'orig_type' => array(
Dries Buytaert
committed
'description' => 'The original machine-readable name of this node type. This may be different from the current type name if the locked field is 0.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'primary key' => array('type'),
Dries Buytaert
committed
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
$schema['block_node_type'] = array(
'description' => 'Sets up display criteria for blocks based on content types',
'fields' => array(
'module' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'description' => "The block's origin module, from {block}.module.",
),
'delta' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'description' => "The block's unique delta within module, from {block}.delta.",
),
'type' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'description' => "The machine-readable name of this type from {node_type}.type.",
),
),
'primary key' => array('module', 'delta', 'type'),
'indexes' => array(
'type' => array('type'),
),
);
$schema['history'] = array(
'description' => 'A record of which {users} have read which {node}s.',
'fields' => array(
'uid' => array(
'description' => 'The {users}.uid that read the {node} nid.',
'type' => 'int',
Dries Buytaert
committed
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'nid' => array(
'description' => 'The {node}.nid that was read.',
'type' => 'int',
Dries Buytaert
committed
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'timestamp' => array(
'description' => 'The Unix timestamp at which the read occurred.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('uid', 'nid'),
'indexes' => array(
'nid' => array('nid'),
),
);
return $schema;
}
Dries Buytaert
committed
/**
* Implements hook_install().
*/
function node_install() {
// Populate the node access table.
db_insert('node_access')
->fields(array(
'nid' => 0,
'gid' => 0,
'realm' => 'all',
'grant_view' => 1,
'grant_update' => 0,
'grant_delete' => 0,
))
->execute();
}
/**
* Implements hook_uninstall().
*
* @see node_ranking()
* @see _node_rankings()
*/
function node_uninstall() {
// Delete node type variables.
$types = db_query('SELECT type FROM {node_type}')->fetchCol();
foreach ($types as $type) {
db_delete('variable')
->condition(db_or()
->condition('name', 'node_preview_' . $type)
->condition('name', 'node_options_' . $type)
->condition('name', 'node_submitted_' . $type)
->condition('name', 'node_permissions_' . $type)
->condition('name', 'node_type_language_default_' . $type)
->condition('name', 'node_type_language_hidden_' . $type)
->condition('name', 'node_type_language_translation_enabled_' . $type)
)
->execute();
}
// Delete node search ranking variables.
variable_del('node_rank_relevance');
variable_del('node_rank_sticky');
variable_del('node_rank_promote');
variable_del('node_rank_recent');
// Delete remaining general module variables.
variable_del('node_access_needs_rebuild');
variable_del('node_admin_theme');
variable_del('node_cron_last');
variable_del('node_recent_block_count');
variable_del('default_nodes_main');
}
Angie Byron
committed
/**
* Fetches node types directly from the database.
Angie Byron
committed
*
Jennifer Hodgdon
committed
* @ingroup update_api
Angie Byron
committed
*/
Dries Buytaert
committed
function _update_7000_node_get_types() {
Dries Buytaert
committed
$node_types = db_query('SELECT * FROM {node_type}')->fetchAllAssoc('type', PDO::FETCH_OBJ);
// Create default settings for orphaned nodes.
$all_types = db_query('SELECT DISTINCT type FROM {node}')->fetchCol();
$extra_types = array_diff($all_types, array_keys($node_types));
foreach ($extra_types as $type) {
$type_object = new stdClass();
Dries Buytaert
committed
$type_object->type = $type;
// In Drupal 6, whether you have a body field or not is a flag in the node
// type table. If it's enabled, nodes may or may not have an empty string
// for the bodies. As we can't detect what this setting should be in
// Drupal 7 without access to the Drupal 6 node type settings, we assume
// the default, which is to enable the body field.
$type_object->has_body = 1;
$type_object->body_label = 'Body';
$node_types[$type_object->type] = $type_object;
}
return $node_types;
Angie Byron
committed
}
/**
* @addtogroup updates-7.x-to-8.x
* @{
*/
Dries Buytaert
committed
/**
* Rename node type language variable names.
*
* @see http://drupal.org/node/540294
Dries Buytaert
committed
*
* @ingroup config_upgrade
Dries Buytaert
committed
*/
function node_update_8001() {
$types = db_query('SELECT type FROM {node_type}')->fetchCol();
foreach ($types as $type) {
$node_type_language = update_variable_get('language_content_type_' . $type);
if (isset($node_type_language)) {
update_variable_set('node_type_language_' . $type, $node_type_language);
Dries Buytaert
committed
}
update_variable_del('language_content_type_' . $type);
Dries Buytaert
committed
}
}
/**
* Rename node.language field to node.langcode.
*/
function node_update_8002() {
$spec = array(
'description' => 'The {language}.langcode of this node.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
);
db_change_field('node', 'language', 'langcode', $spec);
}
* Rename node type language variable names.
*/
function node_update_8003() {
$types = db_query('SELECT type FROM {node_type}')->fetchCol();
foreach ($types as $type) {
update_variable_set('node_type_language_default_' . $type, LANGUAGE_NOT_SPECIFIED);
$node_type_language = update_variable_get('node_type_language_' . $type, 0);
if ($node_type_language == 0) {
update_variable_set('node_type_language_hidden_' . $type, TRUE);
}
if ($node_type_language == 2) {
// Translation was enabled, so enable it again and
// unhide the language selector. Because if language is
// LANGUAGE_NOT_SPECIFIED and the selector hidden, translation
// cannot be enabled.
update_variable_set('node_type_language_hidden_' . $type, FALSE);
update_variable_set('node_type_language_translation_enabled_' . $type, TRUE);
}
update_variable_del('node_type_language_' . $type);
}
}
Dries Buytaert
committed
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
/**
* Create a UUID column for nodes.
*
* @todo UUID upgrade path: http://drupal.org/node/1642526
*/
function node_update_8004() {
$spec = array(
'description' => 'Unique Key: Universally unique identifier for this entity.',
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
);
$keys = array(
'unique keys' => array(
'uuid' => array('uuid'),
),
);
// Account for sites having the contributed UUID module installed.
if (db_field_exists('node', 'uuid')) {
db_change_field('node', 'uuid', 'uuid', $spec, $keys);
}
else {
db_add_field('node', 'uuid', $spec, $keys);
}
}
Dries Buytaert
committed
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
/**
* Make *id fields unsigned.
*/
function node_update_8005() {
db_drop_index('node', 'uid');
db_change_field('node', 'uid', 'uid',
array(
'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
array('indexes' => array(
'uid' => array('uid'),
))
);
db_drop_index('node_revision', 'uid');
db_change_field('node_revision', 'uid', 'uid',
array(
'description' => 'The {users}.uid that created this version.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
array('indexes' => array(
'uid' => array('uid'),
))
);
db_drop_primary_key('history');
db_drop_index('history', 'nid');
db_change_field('history', 'uid', 'uid',
array(
'description' => 'The {users}.uid that read the {node} nid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
)
);
db_change_field('history', 'nid', 'nid',
array(
'description' => 'The {node}.nid that was read.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
array('primary key' => array('uid', 'nid'), 'indexes' => array(
'nid' => array('nid'),
))
);
}
/**
* @} End of "addtogroup updates-7.x-to-8.x"
* The next series of updates should start at 9000.
*/