| 1 |
<?php
|
| 2 |
// $Id: imagepicker.install,v 1.5 2008/07/11 12:11:06 hutch Exp $
|
| 3 |
// $Name: HEAD $
|
| 4 |
|
| 5 |
/**
|
| 6 |
* @file
|
| 7 |
* imagepicker instal, update and uninstall functions
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_install().
|
| 12 |
*/
|
| 13 |
function imagepicker_install() {
|
| 14 |
// Create a directory structure so that usernames would be divided by letters.
|
| 15 |
$drupaldir = str_replace('/', DIRECTORY_SEPARATOR, getcwd()) . DIRECTORY_SEPARATOR;
|
| 16 |
$dir = $drupaldir . file_directory_path() . DIRECTORY_SEPARATOR .'imagepicker';
|
| 17 |
|
| 18 |
if (file_check_directory($dir, TRUE)) {
|
| 19 |
$dirlist = range('a', 'z');
|
| 20 |
array_push($dirlist, 'others');
|
| 21 |
|
| 22 |
foreach ($dirlist AS $v) {
|
| 23 |
$newdir = $dir . DIRECTORY_SEPARATOR . $v;
|
| 24 |
if (! file_check_directory($newdir, TRUE)) {
|
| 25 |
drupal_set_message(t('Directory creation for the Imagepicker module was unsuccessful.'), 'error');
|
| 26 |
}
|
| 27 |
}
|
| 28 |
$errors = drupal_get_messages('error');
|
| 29 |
if (! count($errors)) {
|
| 30 |
// clear
|
| 31 |
drupal_get_messages();
|
| 32 |
drupal_set_message(t('Directory creation for the Imagepicker module was successful.'), '');
|
| 33 |
}
|
| 34 |
else {
|
| 35 |
foreach ($errors['error'] AS $error) {
|
| 36 |
drupal_set_message($error, 'error');
|
| 37 |
}
|
| 38 |
}
|
| 39 |
}
|
| 40 |
|
| 41 |
// Create tables.
|
| 42 |
drupal_install_schema('imagepicker');
|
| 43 |
}
|
| 44 |
|
| 45 |
/**
|
| 46 |
* Implementation of hook_schema().
|
| 47 |
*/
|
| 48 |
function imagepicker_schema() {
|
| 49 |
$schema['imagepicker'] = array(
|
| 50 |
'fields' => array(
|
| 51 |
'img_id' => array(
|
| 52 |
'description' => t('The primary image identifier.'),
|
| 53 |
'type' => 'serial',
|
| 54 |
'unsigned' => TRUE,
|
| 55 |
'not null' => TRUE),
|
| 56 |
'uid' => array(
|
| 57 |
'description' => t('The user identifier.'),
|
| 58 |
'type' => 'int',
|
| 59 |
'unsigned' => TRUE,
|
| 60 |
'not null' => TRUE,
|
| 61 |
'default' => 0),
|
| 62 |
'img_name' => array(
|
| 63 |
'type' => 'varchar',
|
| 64 |
'length' => 255,
|
| 65 |
'not null' => TRUE,
|
| 66 |
'default' => ''),
|
| 67 |
'img_title' => array(
|
| 68 |
'type' => 'varchar',
|
| 69 |
'length' => 255,
|
| 70 |
'not null' => TRUE,
|
| 71 |
'default' => ''),
|
| 72 |
'img_description' => array(
|
| 73 |
'type' => 'varchar',
|
| 74 |
'length' => 255,
|
| 75 |
'not null' => TRUE,
|
| 76 |
'default' => ''),
|
| 77 |
'img_date' => array(
|
| 78 |
'type' => 'datetime',
|
| 79 |
'not null' => TRUE),
|
| 80 |
),
|
| 81 |
'indexes' => array(
|
| 82 |
'uid' => array('uid'),
|
| 83 |
),
|
| 84 |
'primary key' => array('img_id'),
|
| 85 |
);
|
| 86 |
|
| 87 |
$schema['imagepicker_user_groups'] = array(
|
| 88 |
'fields' => array(
|
| 89 |
'gid' => array(
|
| 90 |
'description' => t('The primary group identifier.'),
|
| 91 |
'type' => 'serial',
|
| 92 |
'unsigned' => TRUE,
|
| 93 |
'not null' => TRUE),
|
| 94 |
'uid' => array(
|
| 95 |
'description' => t('The user identifier.'),
|
| 96 |
'type' => 'int',
|
| 97 |
'unsigned' => TRUE,
|
| 98 |
'not null' => TRUE,
|
| 99 |
'default' => 0),
|
| 100 |
'group_name' => array(
|
| 101 |
'type' => 'varchar',
|
| 102 |
'length' => 255,
|
| 103 |
'not null' => TRUE,
|
| 104 |
'default' => ''),
|
| 105 |
'group_description' => array(
|
| 106 |
'type' => 'varchar',
|
| 107 |
'length' => 255,
|
| 108 |
'not null' => TRUE,
|
| 109 |
'default' => ''),
|
| 110 |
'state' => array(
|
| 111 |
'type' => 'int',
|
| 112 |
'size' => 'tiny',
|
| 113 |
'unsigned' => TRUE,
|
| 114 |
'not null' => TRUE,
|
| 115 |
'default' => 0),
|
| 116 |
),
|
| 117 |
'indexes' => array(
|
| 118 |
'uid' => array('uid'),
|
| 119 |
),
|
| 120 |
'primary key' => array('gid'),
|
| 121 |
);
|
| 122 |
|
| 123 |
$schema['imagepicker_group_images'] = array(
|
| 124 |
'fields' => array(
|
| 125 |
'gid' => array(
|
| 126 |
'description' => t('The group identifier.'),
|
| 127 |
'type' => 'int',
|
| 128 |
'unsigned' => TRUE,
|
| 129 |
'not null' => TRUE),
|
| 130 |
'img_id' => array(
|
| 131 |
'description' => t('The image identifier.'),
|
| 132 |
'type' => 'int',
|
| 133 |
'unsigned' => TRUE,
|
| 134 |
'not null' => TRUE,
|
| 135 |
'default' => 0),
|
| 136 |
)
|
| 137 |
);
|
| 138 |
|
| 139 |
return $schema;
|
| 140 |
|
| 141 |
}
|
| 142 |
|
| 143 |
/**
|
| 144 |
* Implementation of hook_uninstall().
|
| 145 |
*/
|
| 146 |
function imagepicker_uninstall() {
|
| 147 |
// Remove tables.
|
| 148 |
drupal_uninstall_schema('imagepicker');
|
| 149 |
|
| 150 |
db_query("DELETE FROM {variable} WHERE name LIKE 'imagepicker_%';");
|
| 151 |
}
|
| 152 |
|
| 153 |
function imagepicker_update_1() {
|
| 154 |
|
| 155 |
$schema['imagepicker_user_groups'] = array(
|
| 156 |
'fields' => array(
|
| 157 |
'gid' => array(
|
| 158 |
'description' => t('The primary identifier for a group.'),
|
| 159 |
'type' => 'serial',
|
| 160 |
'unsigned' => TRUE,
|
| 161 |
'not null' => TRUE),
|
| 162 |
'uid' => array(
|
| 163 |
'description' => t('The user identifier for a group.'),
|
| 164 |
'type' => 'int',
|
| 165 |
'unsigned' => TRUE,
|
| 166 |
'not null' => TRUE,
|
| 167 |
'default' => 0),
|
| 168 |
'group_name' => array(
|
| 169 |
'type' => 'varchar',
|
| 170 |
'length' => 255,
|
| 171 |
'not null' => TRUE,
|
| 172 |
'default' => ''),
|
| 173 |
'group_description' => array(
|
| 174 |
'type' => 'varchar',
|
| 175 |
'length' => 255,
|
| 176 |
'not null' => TRUE,
|
| 177 |
'default' => ''),
|
| 178 |
'state' => array(
|
| 179 |
'type' => 'int',
|
| 180 |
'size' => 'tiny',
|
| 181 |
'unsigned' => TRUE,
|
| 182 |
'not null' => TRUE,
|
| 183 |
'default' => 0),
|
| 184 |
),
|
| 185 |
'indexes' => array(
|
| 186 |
'uid' => array('uid'),
|
| 187 |
),
|
| 188 |
'primary key' => array('gid'),
|
| 189 |
);
|
| 190 |
|
| 191 |
$schema['imagepicker_group_images'] = array(
|
| 192 |
'fields' => array(
|
| 193 |
'gid' => array(
|
| 194 |
'description' => t('The group identifier.'),
|
| 195 |
'type' => 'int',
|
| 196 |
'unsigned' => TRUE,
|
| 197 |
'not null' => TRUE),
|
| 198 |
'img_id' => array(
|
| 199 |
'description' => t('The image identifier.'),
|
| 200 |
'type' => 'int',
|
| 201 |
'unsigned' => TRUE,
|
| 202 |
'not null' => TRUE,
|
| 203 |
'default' => 0),
|
| 204 |
)
|
| 205 |
);
|
| 206 |
|
| 207 |
$ret = array();
|
| 208 |
foreach ($schema AS $tablename => $tableschema) {
|
| 209 |
db_create_table($ret, $tablename, $tableschema);
|
| 210 |
}
|
| 211 |
return $ret;
|
| 212 |
}
|