drupal/core/modules/node/node.install

471 lines
15 KiB
Plaintext

<?php
/**
* @file
* Install, update and uninstall functions for the node module.
*/
use Drupal\Component\Uuid\Uuid;
use Drupal\Core\Language\Language;
/**
* Implements hook_requirements().
*/
function node_requirements($phase) {
$requirements = array();
if ($phase === 'runtime') {
// 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().
$grant_count = \Drupal::entityManager()->getAccessController('node')->countGrants();
if ($grant_count != 1 || count(\Drupal::moduleHandler()->getImplementations('node_grants')) > 0) {
$value = format_plural($grant_count, 'One permission in use', '@count permissions in use', array('@count' => $grant_count));
}
else {
$value = t('Disabled');
}
$description = t('If the site is experiencing problems with permissions to content, you may have to rebuild the permissions cache. Rebuilding will remove all privileges to content and replace them with permissions based on the current modules and settings. Rebuilding may take some time if there is a lot of content or complex permission settings. After rebuilding has completed, content will automatically use the new permissions.');
$requirements['node_access'] = array(
'title' => t('Node Access Permissions'),
'value' => $value,
'description' => $description . ' ' . l(t('Rebuild permissions'), 'admin/reports/status/rebuild'),
);
}
return $requirements;
}
/**
* Implements hook_schema().
*/
function node_schema() {
$schema['node'] = array(
'description' => 'The base table for nodes.',
'fields' => array(
'nid' => array(
'description' => 'The primary identifier for a node.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uuid' => array(
'description' => 'Unique Key: Universally unique identifier for this entity.',
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
// Defaults to NULL in order to avoid a brief period of potential
// deadlocks on the index.
'vid' => array(
'description' => 'The current {node_field_revision}.vid version identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
),
'type' => array(
'description' => 'The type of this node.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
),
'indexes' => array(
'node_type' => array(array('type', 4)),
),
'unique keys' => array(
'vid' => array('vid'),
'uuid' => array('uuid'),
),
'foreign keys' => array(
'node_revision' => array(
'table' => 'node_revision',
'columns' => array('vid' => 'vid'),
),
),
'primary key' => array('nid'),
);
$schema['node_revision'] = array(
'description' => 'Stores information about each saved version of a {node}.',
'fields' => array(
'nid' => array(
'description' => 'The {node} this version belongs to.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'vid' => array(
'description' => 'The primary identifier for this version.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'revision_uid' => array(
'description' => 'The {users}.uid that created this version.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'log' => array(
'description' => 'The log entry explaining the changes in this version.',
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
),
'revision_timestamp' => array(
'description' => 'The Unix timestamp when the version was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'langcode' => array(
'description' => 'The {language}.langcode of this version.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
),
'indexes' => array(
'nid' => array('nid'),
'revision_uid' => array('revision_uid'),
'node_langcode' => array('langcode'),
),
'foreign keys' => array(
'versioned_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'version_author' => array(
'table' => 'users',
'columns' => array('revision_uid' => 'uid'),
),
),
'primary key' => array('vid'),
);
// Node field storage.
$schema['node_field_data'] = array(
'description' => 'Data table for node base fields.',
'fields' => array(
'nid' => array(
'description' => 'The primary identifier for a node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'vid' => array(
'description' => 'The current {node_field_revision}.vid version identifier.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'The {node_type}.type of this node.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'langcode' => array(
'description' => 'The {language}.langcode of these node property values.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'default_langcode' => array(
'description' => 'Boolean indicating whether the property values are in the {language}.langcode of this node.',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'title' => array(
'description' => 'The title of this node, always treated as non-markup plain text.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'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,
),
'status' => array(
'description' => 'Boolean indicating whether the node translation is published (visible to non-administrators).',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'created' => array(
'description' => 'The Unix timestamp when the node translation was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the node translation was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'promote' => array(
'description' => 'Boolean indicating whether the node translation should be displayed on the front page.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'sticky' => array(
'description' => 'Boolean indicating whether the node translation should be displayed at the top of lists in which it appears.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'node_changed' => array('changed'),
'node_created' => array('created'),
'node_default_langcode' => array('default_langcode'),
'node_langcode' => array('langcode'),
'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)),
'vid' => array('vid'),
'uid' => array('uid'),
),
'foreign keys' => array(
'node_base' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'node_author' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
'primary key' => array('nid', 'langcode'),
);
$schema['node_field_revision'] = array(
'description' => 'Revision table for node base fields.',
'fields' => array(
'nid' => array(
'description' => 'The {node} this version belongs to.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'vid' => array(
'description' => 'The primary identifier for this version.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'langcode' => array(
'description' => 'The {language}.langcode of this version.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'default_langcode' => array(
'description' => 'Boolean indicating whether the property values of this version are in the {language}.langcode of this node.',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'title' => array(
'description' => 'The title of this version, always treated as non-markup plain text.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'uid' => array(
'description' => 'The {users}.uid that created this node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'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,
),
'created' => array(
'description' => 'The Unix timestamp when the node was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the version was most recently saved.',
'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(
'uid' => array('uid'),
'node_default_langcode' => array('default_langcode'),
'node_langcode' => array('langcode'),
),
'foreign keys' => array(
'versioned_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'node_author' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
'primary key' => array('vid', 'langcode'),
);
$schema['node_access'] = array(
'description' => 'Identifies which realm/grant pairs a user must possess in order to view, update, or delete specific nodes.',
'fields' => array(
'nid' => array(
'description' => 'The {node}.nid this record affects.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'langcode' => array(
'description' => 'The {language}.langcode of this node.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'fallback' => array(
'description' => 'Boolean indicating whether this record should be used as a fallback if a language condition is not provided.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
),
'gid' => array(
'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(
'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(
'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(
'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(
'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', 'langcode'),
'foreign keys' => array(
'affected_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function node_install() {
// Enable default permissions for system roles.
// IMPORTANT: Modules SHOULD NOT automatically grant any user role access
// permissions in hook_install().
// However, the 'access content' permission is a very special case, since
// there is hardly a point in installing the Node module without granting
// these permissions. Doing so also allows tests to continue to operate as
// expected without first having to manually grant these default permissions.
if (\Drupal::moduleHandler()->moduleExists('user')) {
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content'));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content'));
}
// 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 = config_get_storage_names_with_prefix('node.type.');
foreach ($types as $config_name) {
$type = \Drupal::config($config_name)->get('type');
\Drupal::config('language.settings')->clear('node. ' . $type . '.language.default_configuration')->save();
}
// Delete remaining general module variables.
\Drupal::state()->delete('node.node_access_needs_rebuild');
// Delete any stored state.
\Drupal::state()->delete('node.cron_last');
}