Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
407 lines (389 sloc) 10.4 KB
<?php
/**
* Implementation of hook_install
*/
function bandcamp_install() {
// add fields for releases and tracks - the following was pinched from node_example_install
foreach (_bandcamp_installed_fields() as $field) {
field_create_field($field);
}
// Create all the instances for our fields.
// http://api.drupal.org/api/function/field_create_instance/7
$instances = _bandcamp_installed_instances();
$entity_fields = array(
'release' => array(
'bandcamp_large_art_url',
'bandcamp_small_art_url',
'bandcamp_downloadable',
'bandcamp_release_date',
'bandcamp_release_url',
'bandcamp_about',
'bandcamp_artist',
),
'track' => array(
'bandcamp_large_art_url',
'bandcamp_small_art_url',
'bandcamp_downloadable',
'bandcamp_track_credits',
'bandcamp_track_streaming_url',
'bandcamp_track_duration',
'bandcamp_about',
'bandcamp_track_url',
'bandcamp_track_number',
'bandcamp_track_lyrics',
'bandcamp_artist',
),
);
foreach ($entity_fields as $entity => $fields) {
foreach($fields as $key) {
$instance = $instances[$key];
$instance['entity_type'] = $entity;
$instance['bundle'] = $entity;
field_create_instance($instance);
}
}
}
/**
* Implementation of hook_uninstall
*/
function bandcamp_uninstall() {
foreach (array_keys(_bandcamp_installed_fields()) as $field) {
field_delete_field($field);
}
foreach(array('release', 'track') as $entity) {
$instances = field_info_instances($entity, $entity);
foreach ($instances as $instance_name => $instance) {
field_delete_instance($instance);
}
}
field_purge_batch(1000);
return drupal_uninstall_schema('bandcamp');
}
/**
* Implementation of hook_schema
*/
function bandcamp_schema() {
$schema['bandcamp_band'] = array(
'description' => 'Storage for Bandcamp band entity',
'fields' => array(
'bid' => array(
'description' => 'Primary key for band entity',
'type' => 'serial',
'unsigned' => true,
'not null' => true,
),
'band_id' => array(
'description' => 'Bandcamp band id',
'type' => 'varchar',
'length' => '10',
),
'band_name' => array(
'description' => 'Band name',
'type' => 'varchar',
'length' => '255',
'not null' => true,
),
'band_url_name' => array(
'description' => 'Bandcamp band url name',
'type' => 'varchar',
'length' => '128',
),
'imported' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => true,
'default' => 0,
),
),
'primary key' => array('bid'),
);
$schema['bandcamp_release'] = array(
'description' => 'Storage for Bandcamp release entity',
'fields' => array(
'rid' => array(
'description' => 'Primary key for release entity',
'type' => 'serial',
'unsigned' => true,
'not null' => true,
),
'title' => array(
'description' => t('Release title'),
'type' => 'varchar',
'length' => 255,
'not null' => true,
),
// note album_id is numeric but it's uncertain whether this may change over time
'album_id' => array(
'description' => 'Bandcamp album ID',
'type' => 'varchar',
'length' => 16,
'not null' => true,
),
'title' => array(
'description' => t('Release title'),
'type' => 'varchar',
'length' => 255,
'not null' => true,
),
'bid' => array(
'description' => 'Bandcamp band ID for this album (bandcamp_band bid)',
'type' => 'int',
'unsigned' => true,
'not null' => true,
),
),
'primary key' => array('rid'),
);
$schema['bandcamp_track'] = array(
'description' => 'Storage for Bandcamp release entity',
'fields' => array(
'tid' => array(
'description' => 'Primary key for track entity',
'type' => 'serial',
'unsigned' => true,
'not null' => true,
),
'title' => array(
'description' => t('Track title'),
'type' => 'varchar',
'length' => 255,
'not null' => true,
),
'track_id' => array(
'description' => 'Bandcamp track ID',
'type' => 'varchar',
'length' => 16,
'not null' => true,
),
'rid' => array(
'description' => 'Bandcamp album ID for this track (bandcamp_release rid)',
'type' => 'varchar',
'length' => 16,
'not null' => true,
),
'bid' => array(
'description' => 'bandcamp_band bid',
'type' => 'int',
'unsigned' => true,
'not null' => true,
),
),
'primary key' => array('tid'),
);
return $schema;
}
/**
* Release and track field definitions
*
* Filched from _node_example_installed_fields()
*/
function _bandcamp_installed_fields() {
$t = get_t();
return array(
'bandcamp_large_art_url' => array(
'field_name' => 'bandcamp_large_art_url',
'cardinality' => 1,
'type' => 'link_field',
'module' => 'link',
'active' => 1,
'settings' => array(
'url' => 0,
'title' => 'optional',
'title_value' => '',
'enable_tokens' => 1,
'display' => array(
'url_cutoff' => 80,
),
'attributes' => array(
'target' => 'default',
'rel' => '',
'class' => '',
),
),
),
'bandcamp_small_art_url' => array(
'field_name' => 'bandcamp_small_art_url',
'cardinality' => 1,
'type' => 'link_field',
'module' => 'link',
'active' => 1,
'settings' => array(
'url' => 0,
'title' => 'optional',
'title_value' => '',
'enable_tokens' => 1,
'display' => array(
'url_cutoff' => 80,
),
'attributes' => array(
'target' => 'default',
'rel' => '',
'class' => '',
),
),
),
'bandcamp_downloadable' => array(
'field_name' => 'bandcamp_downloadable',
'cardinality' => 1,
'type' => 'number_integer',
),
'bandcamp_release_date' => array(
'field_name' => 'bandcamp_release_date',
'cardinality' => 1,
'type' => 'datetime',
'module' => 'date',
'active' => 1,
'settings' => array(
'repeat' => 0,
'todate' => '',
'granularity' => array(
'year' => 'year',
'month' => 'month',
'day' => 'day',
'hour' => 'hour',
'minute' => 'minute',
'second' => 'second',
),
'tz_handling' => 'site',
'timezone_db' => 'UTC',
),
),
'bandcamp_release_url' => array(
'field_name' => 'bandcamp_release_url',
'cardinality' => 1,
'type' => 'link_field',
'module' => 'link',
'active' => 1,
'settings' => array(
'url' => 0,
'title' => 'optional',
'title_value' => '',
'enable_tokens' => 1,
'display' => array(
'url_cutoff' => 80,
),
'attributes' => array(
'target' => 'default',
'rel' => '',
'class' => '',
),
),
),
'bandcamp_track_credits' => array(
'field_name' => 'bandcamp_track_credits',
'cardinality' => 1,
'type' => 'text_long',
),
'bandcamp_track_streaming_url' => array(
'field_name' => 'bandcamp_track_streaming_url',
'cardinality' => 1,
'type' => 'link_field',
'module' => 'link',
'active' => 1,
'settings' => array(
'url' => 0,
'title' => 'optional',
'title_value' => '',
'enable_tokens' => 1,
'display' => array(
'url_cutoff' => 80,
),
'attributes' => array(
'target' => 'default',
'rel' => '',
'class' => '',
),
),
),
'bandcamp_track_duration' => array(
'field_name' => 'bandcamp_track_duration',
'cardinality' => 1,
'type' => 'number_float',
),
'bandcamp_about' => array(
'field_name' => 'bandcamp_about',
'cardinality' => 1,
'type' => 'text_long',
),
'bandcamp_track_url' => array(
'field_name' => 'bandcamp_track_url',
'cardinality' => 1,
'type' => 'link_field',
'module' => 'link',
'active' => 1,
'settings' => array(
'url' => 0,
'title' => 'optional',
'title_value' => '',
'enable_tokens' => 1,
'display' => array(
'url_cutoff' => 80,
),
'attributes' => array(
'target' => 'default',
'rel' => '',
'class' => '',
),
),
),
'bandcamp_track_number' => array(
'field_name' => 'bandcamp_track_number',
'cardinality' => 1,
'type' => 'number_integer',
),
'bandcamp_track_lyrics' => array(
'field_name' => 'bandcamp_track_lyrics',
'cardinality' => 1,
'type' => 'text_long',
),
'bandcamp_artist' => array(
'field_name' => 'bandcamp_artist',
'cardinality' => 1,
'type' => 'text',
),
);
}
function _bandcamp_installed_instances() {
$t = get_t();
return array(
'bandcamp_large_art_url' => array(
'field_name' => 'bandcamp_large_art_url',
),
'bandcamp_small_art_url' => array(
'field_name' => 'bandcamp_small_art_url',
),
'bandcamp_downloadable' => array(
'field_name' => 'bandcamp_downloadable',
),
'bandcamp_release_date' => array(
'field_name' => 'bandcamp_release_date',
),
'bandcamp_release_url' => array(
'field_name' => 'bandcamp_release_url',
),
'bandcamp_track_credits' => array(
'field_name' => 'bandcamp_track_credits',
),
'bandcamp_track_streaming_url' => array(
'field_name' => 'bandcamp_track_streaming_url',
),
'bandcamp_track_duration' => array(
'field_name' => 'bandcamp_track_duration',
),
'bandcamp_about' => array(
'field_name' => 'bandcamp_about',
),
'bandcamp_track_url' => array(
'field_name' => 'bandcamp_track_url',
),
'bandcamp_track_number' => array(
'field_name' => 'bandcamp_track_number',
),
'bandcamp_track_lyrics' => array(
'field_name' => 'bandcamp_track_lyrics',
),
'bandcamp_artist' => array(
'field_name' => 'bandcamp_artist',
),
);
}