party_hat.install in Party 7
Same filename and directory in other branches
Contains install hooks for the party hat module..
File
modules/party_hat/party_hat.installView source
<?php
/**
* @file
* Contains install hooks for the party hat module..
*/
/**
* Implements hook_schema().
*/
function party_hat_schema() {
$schema['party_hat'] = array(
'description' => 'Stores hat definitions',
'fields' => array(
'hid' => array(
'description' => 'Primary key for the hat.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'name' => array(
'description' => 'The machine readable name of the hat',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'parent' => array(
'description' => "The machine readable name of the hat's parent.",
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'label' => array(
'description' => 'A human readable name for the hat',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'description' => array(
'description' => 'Some text describing the purpose of the hat',
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
'translatable' => TRUE,
),
'data' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'serialize' => TRUE,
'description' => 'Serialized data containing the field properties that do not warrant a dedicated column.',
),
'required' => array(
'description' => 'This Hat is required',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
) + party_hat_exportable_schema_fields(),
'primary key' => array(
'hid',
),
);
return $schema;
}
/**
* Exportable schema fields.
*/
function party_hat_exportable_schema_fields() {
return array(
'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,
),
);
}
/**
* Implements hook_field_schema()
*/
function party_hat_field_schema() {
$columns = array(
'hat_name' => array(
'description' => 'The machine readable name of the hat',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
);
$indexes = array();
return array(
'columns' => $columns,
'indexes' => $indexes,
);
}
/**
* Implements hook_install().
*/
function party_hat_install() {
field_info_cache_clear();
if (!field_info_field('party_hat')) {
$field = array(
'field_name' => 'party_hat',
'type' => 'hat_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'settings' => array(),
);
field_create_field($field);
$instance = array(
'field_name' => 'party_hat',
'entity_type' => 'party',
'bundle' => 'party',
'label' => st('Hats'),
'required' => FALSE,
'description' => st("This party's hats"),
'default_value_function' => 'party_hat_field_get_default',
'widget' => array(
'type' => 'options_buttons',
'settings' => array(),
),
'display' => array(
'default' => array(
'type' => 'hat_reference_default',
'label' => 'inline',
),
),
);
field_create_instance($instance);
}
}
/**
* Drop Party Bundles - migrate hat fields.
*/
function party_hat_update_7001() {
if (!field_info_instance('party', 'party_hat', 'party')) {
$instance = array(
'field_name' => 'party_hat',
'entity_type' => 'party',
'bundle' => 'party',
'label' => t('Hats'),
'required' => FALSE,
'description' => t("This party's hats"),
'default_value_function' => 'party_hat_field_get_default',
'widget' => array(
'type' => 'options_buttons',
'settings' => array(),
),
'display' => array(
'default' => array(
'type' => 'hat_reference_default',
'label' => 'inline',
),
),
);
field_create_instance($instance);
}
// Update Existing field data
db_update('field_data_party_hat')
->fields(array(
'bundle' => 'party',
))
->execute();
db_update('field_revision_party_hat')
->fields(array(
'bundle' => 'party',
))
->execute();
// Remove old instances
$instance = array(
'field_name' => 'party_hat',
'entity_type' => 'party',
'bundle' => 'organisation',
);
field_delete_instance($instance);
$instance = array(
'field_name' => 'party_hat',
'entity_type' => 'party',
'bundle' => 'individual',
);
field_delete_instance($instance);
}
/**
* Make party_hat data field not 'not null'.
*/
function party_hat_update_7002() {
$spec = array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'serialize' => TRUE,
'description' => 'Serialized data containing the field properties that do not warrant a dedicated column.',
);
db_change_field('party_hat', 'data', 'data', $spec);
}
/**
* Remove party types data from hats.
*/
function party_hat_update_7003() {
// Get all the hats.
$party_hats = db_select('party_hat', 'ph')
->fields('ph', array(
'hid',
'data',
))
->execute()
->fetchAllAssoc('hid');
foreach ($party_hats as $hid => $hat) {
$hat->data = unserialize($hat->data);
unset($hat->data['party_types']);
$hat->data = serialize($hat->data);
// Update the record.
db_update('party_hat')
->fields(array(
'data' => $hat->data,
))
->condition('hid', $hid)
->execute();
}
}
/**
* Migrate data from {party_hat_data_set_rules} table to hat entity data.
*/
function party_hat_update_7004() {
$party_hats = db_select('party_hat', 'ph')
->fields('ph', array(
'hid',
'name',
'data',
))
->execute()
->fetchAllAssoc('hid');
foreach ($party_hats as $hid => $hat) {
// Prepare the hat data to be worked with.
$hat->data = unserialize($hat->data);
$results = db_select('party_hat_data_set_rules', 'c')
->fields('c', array(
'data_set',
'has',
'multiple',
))
->condition('hat', $hat->name, '=')
->execute()
->fetchAllAssoc('data_set', PDO::FETCH_ASSOC);
foreach ($results as $data_set_name => $data) {
// Remove the data set name.
unset($data['data_set']);
$hat->data['data_sets'][$data_set_name] = $data;
}
// Re-serialize the hat data ready to be saved.
$hat->data = serialize($hat->data);
db_update('party_hat', 'ph')
->fields(array(
'data' => $hat->data,
))
->condition('hid', $hid)
->execute();
}
db_delete('party_hat_data_set_rules');
}
/**
* Filter out unused data sets in hat entity data.
*/
function party_hat_update_7005() {
$party_hats = db_select('party_hat', 'ph')
->fields('ph', array(
'hid',
'data',
))
->execute()
->fetchAllAssoc('hid');
foreach ($party_hats as $hid => $hat) {
$hat->data = unserialize($hat->data);
$values = $hat->data['data_sets'];
party_hat_set_data_set_rules($hat, $values);
$hat->data = serialize($hat->data);
db_update('party_hat', 'ph')
->fields(array(
'data' => $hat->data,
))
->condition('hid', $hid)
->execute();
}
}
/**
* Add a description field to party hats.
*/
function party_hat_update_7006() {
$field = array(
'description' => 'Some text describing the purpose of the hat',
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
'translatable' => TRUE,
);
db_add_field('party_hat', 'description', $field);
}
/**
* Add a parent field to the party hat table
*/
function party_hat_update_7007() {
$spec = array(
'description' => "The machine readable name of the hat's parent",
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
);
db_add_field('party_hat', 'parent', $spec);
}
Functions
Name | Description |
---|---|
party_hat_exportable_schema_fields | Exportable schema fields. |
party_hat_field_schema | Implements hook_field_schema() |
party_hat_install | Implements hook_install(). |
party_hat_schema | Implements hook_schema(). |
party_hat_update_7001 | Drop Party Bundles - migrate hat fields. |
party_hat_update_7002 | Make party_hat data field not 'not null'. |
party_hat_update_7003 | Remove party types data from hats. |
party_hat_update_7004 | Migrate data from {party_hat_data_set_rules} table to hat entity data. |
party_hat_update_7005 | Filter out unused data sets in hat entity data. |
party_hat_update_7006 | Add a description field to party hats. |
party_hat_update_7007 | Add a parent field to the party hat table |