Token authentication 6.x-1.0-rc1
Drupal 6.3, installed with SimpleScripts
MySQL 5.0.45
PHP 5.2.6

Extracted 'tokenauth' directory into /modules/
Checked enable checkbox for 'Token authentication' on Modules in admin interface.
Error message:
(Missed original error message)

Registered a new user.
Error message:

user warning: Table 'lingnikc_ssdrp01.tokenauth_tokens' doesn't exist query: INSERT INTO tokenauth_tokens (uid, token) VALUES (3, 'yHYsu33NWP') in /home/lingnikc/public_html/test/drupal/modules/tokenauth/tokenauth.module on line 247.

Disabled 'Token authentication' module.
Enabled 'Token authentication' module.
Error message:

user warning: Table 'lingnikc_ssdrp01.tokenauth_tokens' doesn't exist query: INSERT INTO tokenauth_tokens (uid, token) SELECT u.uid, 'qZCqMz9JWj' FROM users u LEFT JOIN tokenauth_tokens tt ON u.uid=tt.uid WHERE u.uid > 0 AND tt.token IS NULL in /home/lingnikc/public_html/test/drupal/modules/tokenauth/tokenauth.install on line 37.
CommentFileSizeAuthor
#5 tokenauth.schema-fix.patch1.71 KBMark Rose

Comments

Lingnik’s picture

Reinstalled fresh drupal.
Put module in /sites/all/modules/tokenauth

    * warning: Invalid argument supplied for foreach() in /home/lingnikc/public_html/test/drupal/includes/common.inc on line 3169.
    * warning: Invalid argument supplied for foreach() in /home/lingnikc/public_html/test/drupal/includes/common.inc on line 3090.
    * user warning: Table 'lingnikc_ssdrp01.tokenauth_tokens' doesn't exist query: INSERT INTO tokenauth_tokens (uid, token) SELECT u.uid, 'kqX5WHSRNp' FROM users u LEFT JOIN tokenauth_tokens tt ON u.uid=tt.uid WHERE u.uid > 0 AND tt.token IS NULL in /home/lingnikc/public_html/test/drupal/sites/all/modules/tokenauth/tokenauth.install on line 37.
Lingnik’s picture

Tested drupal-6.2 (April 9; prior to release date of tokenauth-6*), with same error messages.
Tested drupal-6.0 (February 13), with same error messages.
Tested drupal-5.7 and tokenauth-5.x-1.2, with apparent success (no error messages).

It appears that tokenauth is not having its tokenauth_install() function called, or there is some other issue with drupal_install_schema or the tokenauth schema preventing it from installing the tokenauth_tokens table. (Silently.)

Lingnik’s picture

Debugging in 6.3...

Changing tokenauth.install>tokenauth_schema, line 27 to
return null;
Gives the same errors.

Changing contents of schema to the example schema listed at http://drupal.org/node/146862 gives the same errors as well.

$schema['tokenauth_tokens'] = array(
    'description' => t('The base table for nodes.'),
    'fields' => array(
      'nid' => array(
        'description' => t('The primary identifier for a node.'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE),
      'vid' => array(
        'description' => t('The current {node_revisions}.vid version identifier.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0),
      'type' => array(
        'description' => t('The {node_type} of this node.'),
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => ''),
      'title' => array(
        'description' => t('The title of this node, always treated a non-markup plain text.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => ''),
      ),
    'indexes' => array(
      'node_changed'        => array('changed'),
      'node_created'        => array('created'),
      ),
    'unique keys' => array(
      'nid_vid' => array('nid', 'vid'),
      'vid'     => array('vid')
      ),
    'primary key' => array('nid'),
);

Removing the contents of the schema, but leaving it defined as an empty array, gives the same errors.

$schema['tokenauth_tokens'] = array(

);
Lingnik’s picture

Manually created table tokenauth_tokens to get this working until it can be fixed.

 CREATE TABLE `lingnikc_ssdrp01`.`tokenauth_tokens` (
`uid` INT NOT NULL COMMENT 'The user''s {users}.uid',
`token` VARCHAR( 50 ) NULL COMMENT 'The user specific token',
PRIMARY KEY ( `uid` ) ,
UNIQUE (
`token`
)
) ENGINE = MYISAM COMMENT = 'Stores information about each user''s token' 
Mark Rose’s picture

StatusFileSize
new1.71 KB

There are several problems. 1) The calls to drupal_install_schema() and drupal_uninstall_schema() are wrong: they are passed the table name, but should be passed the module name. 2) The schema specifies 'unique keys' incorrectly. 3) The "token" column is specified as nullable, but is also specified as a primary key; that's not allowed, according to the Schema API. 4) The module hook_enable() code tries to insert the same token for every user, even though the schema specifies that the "token" column is a unique key.

I've fixed all of these in a patch to 6.x-1.x-dev, attached.

The fix to #3 is a little brute-force for my taste, but I didn't want to introduce any database compatibility issues, and I don't have handy anything other than MySQL 5.x to test against.

(There's another bug, too, which I'll report separately, with a patch: if you reset a user's token using the GUI, it uses the default token length instead of the configured length.)

moshe weitzman’s picture

Status: Active » Fixed

committed. thx. maybe someone can come up with a less brute force way. mine clearly didn't work.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.