file.install

Same filename and directory in other branches
  1. 10 core/modules/file/file.install
  2. 11.x core/modules/file/file.install
  3. 9 core/modules/file/file.install
  4. 8.9.x core/modules/file/file.install
  5. 7.x modules/file/file.install

Install, update and uninstall functions for File module.

File

core/modules/file/file.install

View source
<?php


/**
 * @file
 * Install, update and uninstall functions for File module.
 */

use Drupal\Core\Database\SchemaDefinition\Column;
use Drupal\Core\Database\SchemaDefinition\Index;
use Drupal\Core\Database\SchemaDefinition\IntValue;
use Drupal\Core\Database\SchemaDefinition\PrimaryKey;
use Drupal\Core\Database\SchemaDefinition\Schema;
use Drupal\Core\Database\SchemaDefinition\SchemaDefinitionType;
use Drupal\Core\Database\SchemaDefinition\StringValue;
use Drupal\Core\Database\SchemaDefinition\Table;

/**
 * Implements hook_schema().
 */
function file_schema() : Schema {
  $tables[] = new Table(name: 'file_usage', description: 'Track where a file is used.', columns: [
    Column::int(name: 'fid', description: 'File ID.', unsigned: TRUE, notNull: TRUE),
    Column::varcharAscii(name: 'module', description: 'The name of the module that is using the file.', length: DRUPAL_EXTENSION_NAME_MAX_LENGTH, notNull: TRUE, default: new StringValue('')),
    Column::varcharAscii(name: 'type', description: 'The name of the object type in which the file is used.', length: 64, notNull: TRUE, default: new StringValue('')),
    Column::varcharAscii(name: 'id', description: 'The primary key of the object using the file.', length: 64, notNull: TRUE, default: new StringValue('0')),
    Column::int(name: 'count', description: 'The number of times this file is used by this object.', unsigned: TRUE, notNull: TRUE, default: new IntValue(0)),
  ], primaryKey: new PrimaryKey([
    'fid',
    'type',
    'id',
    'module',
  ]), indexes: [
    new Index(name: 'type_id', columns: [
      'type',
      'id',
    ]),
    new Index(name: 'fid_count', columns: [
      'fid',
      'count',
    ]),
    new Index(name: 'fid_module', columns: [
      'fid',
      'module',
    ]),
  ]);
  return new Schema(type: SchemaDefinitionType::Module, name: 'file', tables: $tables);
}

/**
 * Implements hook_update_last_removed().
 */
function file_update_last_removed() : int {
  return 8700;
}

Functions

Title Deprecated Summary
file_schema Implements hook_schema().
file_update_last_removed Implements hook_update_last_removed().

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.