218 lines
5.6 KiB
Plaintext
218 lines
5.6 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Farm asset install.
|
|
*/
|
|
|
|
/**
|
|
* Implements hook_enable().
|
|
*/
|
|
function farm_asset_install() {
|
|
|
|
/**
|
|
* Set the weight of this module to 1.
|
|
*
|
|
* We do this so that our hook_views_data_alter() fires after the taxonomy
|
|
* module's hook, because we need to alter it.
|
|
*
|
|
* @see farm_asset_views_data_alter()
|
|
*/
|
|
db_query("UPDATE {system} SET weight = 1 WHERE name = 'farm_asset'");
|
|
}
|
|
|
|
/**
|
|
* Implements hook_schema().
|
|
*/
|
|
function farm_asset_schema() {
|
|
$schema['farm_asset'] = array(
|
|
'description' => 'Farm assets',
|
|
'fields' => array(
|
|
'id' => array(
|
|
'description' => 'Asset ID',
|
|
'type' => 'serial',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'name' => array(
|
|
'description' => 'Asset name',
|
|
'type' => 'varchar',
|
|
'length' => '255',
|
|
'not null' => FALSE,
|
|
),
|
|
'type' => array(
|
|
'description' => 'Asset type',
|
|
'type' => 'varchar',
|
|
'length' => '255',
|
|
'not null' => FALSE,
|
|
),
|
|
'uid' => array(
|
|
'description' => 'Asset author',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
),
|
|
'created' => array(
|
|
'description' => 'Timestamp when the asset was created',
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
),
|
|
'changed' => array(
|
|
'description' => 'Timestamp when the asset was last modified',
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
),
|
|
'archived' => array(
|
|
'description' => 'Timestamp when the asset was archived',
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
),
|
|
),
|
|
'primary key' => array('id'),
|
|
'indexes' => array(
|
|
'name' => array('name'),
|
|
'type_index' => array('type'),
|
|
'uid' => array('uid'),
|
|
'created' => array('created'),
|
|
'modified' => array('changed'),
|
|
'archived' => array('archived'),
|
|
),
|
|
);
|
|
$schema['farm_asset_type'] = array(
|
|
'description' => 'Stores information about all defined asset types.',
|
|
'fields' => array(
|
|
'id' => array(
|
|
'description' => 'Primary Key: Unique asset type ID.',
|
|
'type' => 'serial',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'type' => array(
|
|
'description' => 'The machine-readable name of this asset type.',
|
|
'type' => 'varchar',
|
|
'length' => 32,
|
|
'not null' => TRUE,
|
|
),
|
|
'label' => array(
|
|
'description' => 'The human-readable name of this asset type.',
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
),
|
|
|
|
// The following fields are required to make types exportable via
|
|
// Entity API and Ctools.
|
|
'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' => 0x01,
|
|
'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;
|
|
}
|
|
|
|
/**
|
|
* Add 'active' field to farm assets.
|
|
*/
|
|
function farm_asset_update_7000(&$sandbox) {
|
|
|
|
// Add 'active' field to farm assets.
|
|
$active = array(
|
|
'description' => 'Boolean indicating whether the asset is active.',
|
|
'type' => 'int',
|
|
'size' => 'tiny',
|
|
'not null' => TRUE,
|
|
'default' => 1,
|
|
);
|
|
db_add_field('farm_asset', 'active', $active);
|
|
db_add_index('farm_asset', 'active', array('active'));
|
|
}
|
|
|
|
/**
|
|
* Increase module weight.
|
|
*/
|
|
function farm_asset_update_7001(&$sandbox) {
|
|
|
|
// Set the weight of farm_asset to 1.
|
|
db_query("UPDATE {system} SET weight = 1 WHERE name = 'farm_asset'");
|
|
}
|
|
|
|
/**
|
|
* Change the name of the {farm_asset} index to fix SQLite installs.
|
|
*/
|
|
function farm_asset_update_7002(&$sandbox) {
|
|
db_drop_index('farm_asset', 'type');
|
|
db_add_index('farm_asset', 'type_index', array('type'));
|
|
}
|
|
|
|
/**
|
|
* Change the asset active property to an archived timestamp.
|
|
*/
|
|
function farm_asset_update_7003(&$sandbox) {
|
|
|
|
// Add the new archived field and index.
|
|
$new_field = array(
|
|
'description' => 'Timestamp when the asset was last archived',
|
|
'type' => 'int',
|
|
);
|
|
$new_keys = array(
|
|
'indexes' => array(
|
|
'archived' => array('archived'),
|
|
),
|
|
);
|
|
db_add_field('farm_asset', 'archived', $new_field, $new_keys);
|
|
|
|
// Populate the archived field of inactive assets with the value from the
|
|
// asset's changed field.
|
|
db_query('UPDATE {farm_asset} SET archived = changed WHERE active = 0');
|
|
|
|
// Drop the active field.
|
|
db_drop_field('farm_asset', 'active');
|
|
}
|
|
|
|
/**
|
|
* Change default value of asset archived property to 0 instead of null.
|
|
*/
|
|
function farm_asset_update_7004(&$sandbox) {
|
|
|
|
// Drop the index.
|
|
db_drop_index('farm_asset', 'archived');
|
|
|
|
// Set all NULL values to 0.
|
|
db_query('UPDATE {farm_asset} SET archived = 0 WHERE archived IS NULL');
|
|
|
|
// Change the field.
|
|
$archived = array(
|
|
'description' => 'Timestamp when the asset was archived',
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
);
|
|
$archived_keys = array(
|
|
'indexes' => array(
|
|
'archived' => array('archived'),
|
|
),
|
|
);
|
|
db_change_field('farm_asset', 'archived', 'archived', $archived, $archived_keys);
|
|
}
|