asset.install in Asset 7
Same filename and directory in other branches
Install, update and uninstall functions for the assets module.
File
asset.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the assets module.
*/
/**
* Implements hook_schema().
*/
function asset_schema() {
$schema['asset'] = array(
'description' => 'Stores assets.',
'fields' => array(
'aid' => array(
'description' => 'Primary Key: Unique asset item ID.',
'type' => 'serial',
'not null' => TRUE,
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
'description' => "The {users}.uid of the associated user.",
),
'type' => array(
'description' => 'The {asset_type}.type of the asset.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'title' => array(
'description' => 'The title of the asset.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'created' => array(
'description' => 'The Unix timestamp when the asset was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the asset was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'uuid' => array(
'type' => 'char',
'length' => 36,
'default' => '',
'description' => 'The Universally Unique Identifier.',
),
),
'indexes' => array(
'asset_type' => array(
array(
'type',
4,
),
),
'asset_title_type' => array(
'title',
array(
'type',
4,
),
),
'asset_changed' => array(
'changed',
),
'asset_created' => array(
'created',
),
),
'foreign keys' => array(
'uid' => array(
'users' => 'uid',
),
'type' => array(
'asset_types' => 'type',
),
),
'primary key' => array(
'aid',
),
);
$schema['asset_type'] = array(
'description' => 'Stores information about all defined asset types.',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique asset type ID.',
),
'type' => array(
'description' => 'The machine-readable name of this asset type.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'name' => array(
'description' => 'The human-readable name of this asset type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'translatable' => TRUE,
),
'description' => array(
'description' => 'A brief description of this asset type.',
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
'translatable' => TRUE,
),
'locked' => array(
'description' => 'A boolean indicating whether the administrator may delete this asset type.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
'help' => array(
'description' => 'Help information shown to the user when creating an asset of this type.',
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
'translatable' => TRUE,
),
'icon' => array(
'description' => 'WYSIWYG button image path.',
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
'weight' => array(
'description' => 'The weight of this asset type in relation to others.',
'type' => 'int',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
'uuid' => array(
'type' => 'char',
'length' => 36,
'default' => '',
'description' => 'The Universally Unique Identifier.',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
// Set the default to ENTITY_CUSTOM without using the constant as it is
// not safe to use it at this point.
'default' => 0x1,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'primary key' => array(
'id',
),
'unique keys' => array(
'type' => array(
'type',
),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function asset_install() {
// Increase the module weight.
db_update('system')
->fields(array(
'weight' => 1,
))
->condition('type', 'module')
->condition('name', 'asset')
->execute();
// Try to add support for entitycache by default.
asset_update_7102();
}
/**
* Check if uuid fields exist.
*/
function asset_update_7100() {
foreach (array(
'asset',
'asset_type',
) as $base) {
if (!db_field_exists($base, 'uuid')) {
db_add_field($base, 'uuid', array(
'type' => 'char',
'length' => 36,
'default' => '',
'description' => 'The Universally Unique Identifier.',
));
}
}
return FALSE;
}
/**
* Add indexes for table `asset`.
*/
function asset_update_7101() {
db_add_index('asset', 'asset_changed', array(
'changed',
));
db_add_index('asset', 'asset_created', array(
'created',
));
}
/**
* If entitycache module exists enable asset_entitycache module.
*/
function asset_update_7102() {
if (module_exists('entitycache')) {
module_enable(array(
'asset_entitycache',
));
}
}
Functions
Name | Description |
---|---|
asset_install | Implements hook_install(). |
asset_schema | Implements hook_schema(). |
asset_update_7100 | Check if uuid fields exist. |
asset_update_7101 | Add indexes for table `asset`. |
asset_update_7102 | If entitycache module exists enable asset_entitycache module. |