Index: knurl.install =================================================================== --- knurl.install (revision 32642) +++ knurl.install (working copy) @@ -8,15 +8,10 @@ $schema['knurl'] = array( 'description' => t('Full to shortened URL mappings'), 'fields' => array( - 'tid' => array( - 'type' => 'int', - 'not null' => TRUE, - 'description' => t('The knurl ID'), - ), 'uid' => array( 'type' => 'int', 'not null' => TRUE, - 'description' => t('Knurl user ID'), + 'description' => t('User ID'), ), 'short_url' => array( 'type' => 'varchar', @@ -30,12 +25,9 @@ 'description' => t('The original URL'), ), ), - 'primary key' => array('tid'), - 'indexes' => array( - 'short_url' => array('short_url'), - ), + 'primary key' => array('short_url'), ); - + return $schema; } @@ -51,4 +43,13 @@ */ function knurl_uninstall() { drupal_uninstall_schema('knurl'); -} \ No newline at end of file +} + +/** + * Implementation of hook_update_N(). + */ +function knurl_update_6100() { + $ret = array(); + db_drop_field($ret, 'knurl', 'tid'); + return $ret; +} Index: knurl.module =================================================================== --- knurl.module (revision 32642) +++ knurl.module (working copy) @@ -66,25 +66,25 @@ 'access callback' => 'user_access', 'access arguments' => array('access knurl'), 'type' => MENU_CALLBACK - ); + ); return $items; } /** * Responds to /knurl/show to list all URL's * and /knurl/show/${url} for one - */ + */ function knurl_show() { $output = '
'; $url_limit = 75; $args = func_get_args(); if (sizeof($args) == 1 ) { - $output .= l('show all', 'knurl/show'); + $output .= l('show all', 'knurl/show'); $res = db_query("SELECT * FROM {knurl} WHERE short_url='%s'", end($args)); - } + } else { $output .= ' '; - $res = pager_query("SELECT * FROM {knurl} ORDER BY tid DESC", 50); + $res = pager_query("SELECT * FROM {knurl} ORDER BY short_url DESC", 50); } $output .= '
| Target URL | '; @@ -162,22 +162,32 @@ global $user; $url_limit = 75; $target_url = $form_state['values']['url']; + // generate a unique URL do { $short_url = _knurl_random_url(); } while (!_knurl_is_unique_url( $short_url ) ); - db_query("INSERT INTO {knurl} (uid, short_url, link) values (%d, '%s', '%s')", $user->uid, $short_url, $target_url); - if (strlen($target_url) > $url_limit) { - $target_url = "
|---|