| 1 |
<?php
|
| 2 |
// $Id: mmedia.install,v 1.1.2.4 2008/11/19 03:10:32 rhys Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* mplementation of hook_schema().
|
| 6 |
*/
|
| 7 |
function mmedia_schema() {
|
| 8 |
// media details including necessary metadata
|
| 9 |
$schema['media'] = array(
|
| 10 |
'fields' => array(
|
| 11 |
'mid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 12 |
'fid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 13 |
'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 14 |
|
| 15 |
// path details
|
| 16 |
'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 17 |
'mime' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''),
|
| 18 |
'type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''),
|
| 19 |
'ext' => array('type' => 'varchar', 'length' => 10, 'not null' => TRUE, 'default' => ''),
|
| 20 |
'hash' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
|
| 21 |
'path' => array('type' => 'text', 'not null' => TRUE),
|
| 22 |
'local' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 1),
|
| 23 |
'public' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 1),
|
| 24 |
|
| 25 |
// some important metadata
|
| 26 |
'title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 27 |
'summary' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 28 |
'expire' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 29 |
'dimensions' => array('type' => 'text', 'not null' => TRUE),
|
| 30 |
'source' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 31 |
'reference' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 32 |
|
| 33 |
// details for creation/modification
|
| 34 |
'created' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 35 |
'changed' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 36 |
|
| 37 |
),
|
| 38 |
'primary key' => array('mid'),
|
| 39 |
'unique key' => array('hash'),
|
| 40 |
'indexes' => array(
|
| 41 |
'fid' => array('fid'),
|
| 42 |
'uid' => array('uid'),
|
| 43 |
'ext' => array('ext'),
|
| 44 |
'created' => array('created'),
|
| 45 |
'changed' => array('changed'),
|
| 46 |
'title' => array('title(32)'),
|
| 47 |
),
|
| 48 |
);
|
| 49 |
|
| 50 |
// listing of folders that exist on the system
|
| 51 |
$schema['media_folders'] = array(
|
| 52 |
'fields' => array(
|
| 53 |
'fid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 54 |
'parent' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 55 |
'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 56 |
|
| 57 |
// path details
|
| 58 |
'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 59 |
'depth' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 60 |
'lineage' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 61 |
'path' => array('type' => 'text', 'not null' => TRUE),
|
| 62 |
),
|
| 63 |
'primary key' => array('fid'),
|
| 64 |
'indexes' => array(
|
| 65 |
'parent' => array('parent'),
|
| 66 |
'depth' => array('depth'),
|
| 67 |
'lineage' => array('lineage'),
|
| 68 |
),
|
| 69 |
);
|
| 70 |
|
| 71 |
// commonly used metadata information
|
| 72 |
$schema['media_extras'] = array(
|
| 73 |
'fields' => array(
|
| 74 |
'eid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 75 |
'mid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 76 |
'licence' => array('type' => 'text'),
|
| 77 |
'description' => array('type' => 'text'),
|
| 78 |
'bitrate' => array('type' => 'varchar', 'length' => 255),
|
| 79 |
'quality' => array('type' => 'varchar', 'length' => 255),
|
| 80 |
'length' => array('type' => 'varchar', 'length' => 255),
|
| 81 |
'info' => array('type' => 'text'),
|
| 82 |
),
|
| 83 |
'primary key' => array('eid'),
|
| 84 |
'indexes' => array(
|
| 85 |
'mid' => array('mid'),
|
| 86 |
),
|
| 87 |
);
|
| 88 |
|
| 89 |
// extra metadata that doesn't fit the generally used
|
| 90 |
$schema['media_metadata'] = array(
|
| 91 |
'fields' => array(
|
| 92 |
'metaid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 93 |
'mid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 94 |
'type' => array('type' => 'varchar', 'length' => 255),
|
| 95 |
'value' => array('type' => 'text', 'not null' => TRUE),
|
| 96 |
),
|
| 97 |
'primary key' => array('metaid'),
|
| 98 |
'indexes' => array(
|
| 99 |
'mid' => array('mid'),
|
| 100 |
'type' => array('type(16)', 'value(16)'),
|
| 101 |
),
|
| 102 |
);
|
| 103 |
|
| 104 |
// for caching the media folders for users
|
| 105 |
$schema['cache_media'] = array(
|
| 106 |
'fields' => array(
|
| 107 |
'cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
|
| 108 |
'data' => array('type' => 'blob', 'size' => 'big'),
|
| 109 |
'expire' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 110 |
'created' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 111 |
'headers' => array('type' => 'text'),
|
| 112 |
'serialized' => array('type' => 'int', 'length' => 1, 'not null' => TRUE, 'default' => 0),
|
| 113 |
),
|
| 114 |
'primary key' => array('cid'),
|
| 115 |
'indexes' => array(
|
| 116 |
'expire' => array('expire'),
|
| 117 |
),
|
| 118 |
);
|
| 119 |
|
| 120 |
return $schema;
|
| 121 |
}
|
| 122 |
|
| 123 |
/**
|
| 124 |
* Implementation of hook_install().
|
| 125 |
*/
|
| 126 |
function mmedia_install() {
|
| 127 |
drupal_install_schema('mmedia');
|
| 128 |
}
|
| 129 |
|
| 130 |
/**
|
| 131 |
* Implementation of hook_uninstall().
|
| 132 |
*/
|
| 133 |
function mmedia_uninstall() {
|
| 134 |
// delete all of the media that exist on the system
|
| 135 |
$results = db_query("SELECT mid FROM {media}");
|
| 136 |
while ($obj = db_fetch_object($results)) {
|
| 137 |
media_delete($obj->mid);
|
| 138 |
}
|
| 139 |
|
| 140 |
// delete all of the folders that exist on the system
|
| 141 |
$results = db_query("SELECT fid FROM {media_folders}");
|
| 142 |
while ($obj = db_fetch_object($results)) {
|
| 143 |
mmedia_folder_delete($obj->fid, TRUE, 'media');
|
| 144 |
}
|
| 145 |
|
| 146 |
drupal_uninstall_schema('mmedia');
|
| 147 |
}
|