| 1 |
<?php
|
| 2 |
// $Id: twitter.install,v 1.3.2.1 2009/05/28 06:45:22 walkah Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_schema).
|
| 6 |
*/
|
| 7 |
function twitter_schema() {
|
| 8 |
$schema['twitter'] = array(
|
| 9 |
'description' => t("Stores individual Twitter posts."),
|
| 10 |
'fields' => array(
|
| 11 |
'twitter_id' => array(
|
| 12 |
'description' => t("Unique identifier for each {twitter} post."),
|
| 13 |
'type' => 'int',
|
| 14 |
'unsigned' => TRUE,
|
| 15 |
'size' => 'big',
|
| 16 |
'not null' => TRUE
|
| 17 |
),
|
| 18 |
'screen_name' => array(
|
| 19 |
'description' => t("Screen Name of the {twitter_account} user."),
|
| 20 |
'type' => 'varchar',
|
| 21 |
'length' => 255,
|
| 22 |
'not null' => TRUE,
|
| 23 |
'default' => ''
|
| 24 |
),
|
| 25 |
'created_at' => array(
|
| 26 |
'description' => t("Date and time the {twitter} post was created."),
|
| 27 |
'type' => 'varchar',
|
| 28 |
'length' => 64,
|
| 29 |
'not null' => TRUE,
|
| 30 |
'default' => ''
|
| 31 |
),
|
| 32 |
'created_time' => array(
|
| 33 |
'description' => t("A duplicate of {twitter}.created_at in UNIX timestamp format."),
|
| 34 |
'type' => 'int',
|
| 35 |
'not null' => TRUE
|
| 36 |
),
|
| 37 |
'text' => array(
|
| 38 |
'description' => t("The text of the {twitter} post."),
|
| 39 |
'type' => 'varchar',
|
| 40 |
'length' => 255,
|
| 41 |
'not null' => FALSE
|
| 42 |
),
|
| 43 |
'source' => array(
|
| 44 |
'description' => t("The application that created the {twitter} post."),
|
| 45 |
'type' => 'varchar',
|
| 46 |
'length' => 255,
|
| 47 |
'not null' => FALSE
|
| 48 |
),
|
| 49 |
),
|
| 50 |
'indexes' => array('screen_name' => array('screen_name')),
|
| 51 |
'primary key' => array('twitter_id'),
|
| 52 |
);
|
| 53 |
|
| 54 |
$schema['twitter_account'] = array(
|
| 55 |
'description' => t("Stores information on specific Twitter user accounts."),
|
| 56 |
'fields' => array(
|
| 57 |
'twitter_uid' => array(
|
| 58 |
'description' => t("The unique identifier of the {twitter_account}."),
|
| 59 |
'type' => 'int',
|
| 60 |
'not null' => TRUE
|
| 61 |
),
|
| 62 |
'uid' => array(
|
| 63 |
'description' => t("The {users}.uid of the owner of this account"),
|
| 64 |
'type' => 'int',
|
| 65 |
'unsigned' => TRUE,
|
| 66 |
'size' => 'big',
|
| 67 |
'not null' => TRUE,
|
| 68 |
),
|
| 69 |
'host' => array(
|
| 70 |
'description' => t('The host for this account can be a laconi.ca instance'),
|
| 71 |
'type' => 'varchar',
|
| 72 |
'length' => 255,
|
| 73 |
),
|
| 74 |
'screen_name' => array(
|
| 75 |
'description' => t("The unique login name of the {twitter_account} user."),
|
| 76 |
'type' => 'varchar',
|
| 77 |
'length' => 255
|
| 78 |
),
|
| 79 |
'password' => array(
|
| 80 |
'description' => t("The password for the Twitter account."),
|
| 81 |
'type' => 'varchar',
|
| 82 |
'length' => 64
|
| 83 |
),
|
| 84 |
'oauth_token' => array(
|
| 85 |
'description' => t('The token_key for oauth-based access.'),
|
| 86 |
'type' => 'varchar',
|
| 87 |
'length' => 64,
|
| 88 |
),
|
| 89 |
'oauth_token_secret' => array(
|
| 90 |
'description' => t('The token_secret for oauth-based access.'),
|
| 91 |
'type' => 'varchar',
|
| 92 |
'length' => 64,
|
| 93 |
),
|
| 94 |
'name' => array(
|
| 95 |
'description' => t("The full name of the {twitter_account} user."),
|
| 96 |
'type' => 'varchar',
|
| 97 |
'length' => 64,
|
| 98 |
'not null' => TRUE,
|
| 99 |
'default' => ''
|
| 100 |
),
|
| 101 |
'description' => array(
|
| 102 |
'description' => t("The description/biography associated with the {twitter_account}."),
|
| 103 |
'type' => 'varchar',
|
| 104 |
'length' => 255
|
| 105 |
),
|
| 106 |
'location' => array(
|
| 107 |
'description' => t("The location of the {twitter_account}'s owner."),
|
| 108 |
'type' => 'varchar',
|
| 109 |
'length' => 255
|
| 110 |
),
|
| 111 |
'followers_count' => array(
|
| 112 |
'description' => t("The number of users following this {twitter_account}."),
|
| 113 |
'type' => 'int',
|
| 114 |
'not null' => TRUE,
|
| 115 |
'default' => 0
|
| 116 |
),
|
| 117 |
'profile_image_url' => array(
|
| 118 |
'description' => t("The url of the {twitter_account}'s profile image."),
|
| 119 |
'type' => 'varchar',
|
| 120 |
'length' => 255
|
| 121 |
),
|
| 122 |
'url' => array(
|
| 123 |
'description' => t("The url of the {twitter_account}'s home page."),
|
| 124 |
'type' => 'varchar',
|
| 125 |
'length' => 255
|
| 126 |
),
|
| 127 |
'protected' => array(
|
| 128 |
'description' => t("Boolean flag indicating whether the {twitter_account}'s posts are publicly accessible."),
|
| 129 |
'type' => 'int',
|
| 130 |
'unsigned' => TRUE,
|
| 131 |
'not null' => TRUE,
|
| 132 |
'default' => 0
|
| 133 |
),
|
| 134 |
'import' => array(
|
| 135 |
'description' => t("Boolean flag indicating whether the {twitter_user}'s posts should be pulled in by the site."),
|
| 136 |
'type' => 'int',
|
| 137 |
'unsigned' => TRUE,
|
| 138 |
'not null' => TRUE,
|
| 139 |
'default' => 1
|
| 140 |
),
|
| 141 |
'last_refresh' => array(
|
| 142 |
'description' => t("A UNIX timestamp marking the date Twitter statuses were last fetched on."),
|
| 143 |
'type' => 'int',
|
| 144 |
'not null' => TRUE
|
| 145 |
),
|
| 146 |
),
|
| 147 |
'indexes' => array('screen_name' => array('screen_name')),
|
| 148 |
'primary key' => array('twitter_uid'),
|
| 149 |
);
|
| 150 |
|
| 151 |
return $schema;
|
| 152 |
}
|
| 153 |
|
| 154 |
/**
|
| 155 |
* Implementation of hook_install().
|
| 156 |
*/
|
| 157 |
function twitter_install() {
|
| 158 |
// Create tables.
|
| 159 |
drupal_install_schema('twitter');
|
| 160 |
|
| 161 |
// Set the weight to 3, making it heaving than Pathauto.
|
| 162 |
db_query("UPDATE {system} SET weight = 3 WHERE name = 'twitter'");
|
| 163 |
}
|
| 164 |
|
| 165 |
/**
|
| 166 |
* Previous versions of the Twitter module had no database schema.
|
| 167 |
* We're safe just running the basic install for update_1.
|
| 168 |
*/
|
| 169 |
function twitter_update_6000() {
|
| 170 |
twitter_install();
|
| 171 |
}
|
| 172 |
|
| 173 |
/**
|
| 174 |
* Adding a handful of additional flags on accounts, and saving more metadata
|
| 175 |
* when Twitter sends it to us.
|
| 176 |
*/
|
| 177 |
function twitter_update_6001() {
|
| 178 |
$ret = array();
|
| 179 |
$attributes = array(
|
| 180 |
'description' => t("Boolean flag indicating whether the {twitter_user}'s posts should be pulled in by the site."),
|
| 181 |
'unsigned' => TRUE,
|
| 182 |
'default' => 1,
|
| 183 |
'not null' => TRUE,
|
| 184 |
);
|
| 185 |
db_add_column($ret, 'twitter_user', 'import', 'int', $attributes);
|
| 186 |
|
| 187 |
$attributes = array(
|
| 188 |
'description' => t("The location of the {twitter_account}'s owner."),
|
| 189 |
'length' => 255
|
| 190 |
);
|
| 191 |
db_add_column($ret, 'twitter_account', 'location', 'varchar(255)', $attributes);
|
| 192 |
|
| 193 |
$attributes = array(
|
| 194 |
'description' => t("The number of users following this {twitter_account}."),
|
| 195 |
'unsigned' => TRUE,
|
| 196 |
'not null' => TRUE,
|
| 197 |
'default' => 0
|
| 198 |
);
|
| 199 |
db_add_column($ret, 'twitter_account', 'followers_count', 'int', $attributes);
|
| 200 |
|
| 201 |
return $ret;
|
| 202 |
}
|
| 203 |
|
| 204 |
/**
|
| 205 |
* Set the weight a little heavier to allow Pathauto and other modules to do
|
| 206 |
* their work on the title, path alias, etc. before the twitter post is sent.
|
| 207 |
*/
|
| 208 |
function twitter_update_6002() {
|
| 209 |
$ret = array();
|
| 210 |
$ret[] = update_sql("UPDATE {system} SET weight = 3 WHERE name = 'twitter'");
|
| 211 |
return $ret;
|
| 212 |
}
|
| 213 |
|
| 214 |
/**
|
| 215 |
* Twitter status IDs are hitting the rollover point for signed ints. Let's
|
| 216 |
* be sure we're ready. See http://bit.ly/kokvi for details.
|
| 217 |
*/
|
| 218 |
function twitter_update_6003() {
|
| 219 |
$ret = array();
|
| 220 |
db_drop_primary_key($ret, 'twitter');
|
| 221 |
|
| 222 |
db_change_field($ret, 'twitter', 'twitter_id', 'twitter_id',
|
| 223 |
array('description' => t("Unique identifier for each {twitter} post."),
|
| 224 |
'type' => 'int', 'size' => 'big', 'unsigned' => 'true', 'not null' => TRUE),
|
| 225 |
array('primary key' => array('twitter_id')));
|
| 226 |
|
| 227 |
return $ret;
|
| 228 |
}
|
| 229 |
|
| 230 |
/**
|
| 231 |
* Add NOT NULL constraint and DEFAULT value to the screen_name field of the
|
| 232 |
* twitter and twitter_user tables per updated schema definition.
|
| 233 |
*
|
| 234 |
* See http://drupal.org/node/336048 and http://drupal.org/node/430442
|
| 235 |
*/
|
| 236 |
function twitter_update_6004() {
|
| 237 |
$ret = array();
|
| 238 |
// Have to drop PRIMARY KEY and indexes that use the field being changed.
|
| 239 |
// twitter
|
| 240 |
db_drop_index($ret, 'twitter', 'screen_name');
|
| 241 |
db_change_field($ret, 'twitter', 'screen_name', 'screen_name', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), array('indexes' => array('screen_name' => array('screen_name'))));
|
| 242 |
|
| 243 |
// twitter_user
|
| 244 |
db_drop_index($ret, 'twitter_user', 'screen_name');
|
| 245 |
db_drop_primary_key($ret, 'twitter_user');
|
| 246 |
db_change_field($ret, 'twitter_user', 'screen_name', 'screen_name', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), array('primary key' => array('uid', 'screen_name'), 'indexes' => array('screen_name' => array('screen_name'))));
|
| 247 |
return $ret;
|
| 248 |
}
|
| 249 |
|
| 250 |
function twitter_uninstall() {
|
| 251 |
// Remove tables.
|
| 252 |
drupal_uninstall_schema('twitter');
|
| 253 |
}
|