Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to add new users in Matomo 3.13.3 #15678

Closed
sgoeting opened this issue Mar 6, 2020 · 4 comments
Closed

Not able to add new users in Matomo 3.13.3 #15678

sgoeting opened this issue Mar 6, 2020 · 4 comments
Labels
answered For when a question was asked and we referred to forum or answered it.

Comments

@sgoeting
Copy link

sgoeting commented Mar 6, 2020

Trying to add a new users results in error-message:
Integrity constraint violation: 1062 Duplicate entry '' for key unique_user_id'

This happens after adding a first initial user.

Inspecting the database (users-table) it occurs that the user_id column is not initiated with a value other than an empty string ''.

Inspecting the code in /path/to/matomo/plugins/UsersManager/Model.php function 'addUser' no proper initialization op the user_id property has taken place:

public function addUser($userLogin, $hashedPassword, $email, $alias, $tokenAuth, $dateRegistered)
    {
        $user = array(
            'login'            => $userLogin,
            'password'         => $hashedPassword,
            'alias'            => $alias,
            'email'            => $email,
            'token_auth'       => $tokenAuth,
            'date_registered'  => $dateRegistered,
            'superuser_access' => 0,
            'ts_password_modified' => Date::now()->getDatetime(),
        );

        $db = $this->getDb();
        $db->insert($this->table, $user);
    }

changing this code to:

    // SOURCE :: https://www.php.net/manual/en/function.com-create-guid.php
    private function GUID()
    {
        if (function_exists('com_create_guid') === true)
        {
            return trim(com_create_guid(), '{}');
        }

        return sprintf( '%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
                        mt_rand(0, 65535),
                        mt_rand(0, 65535),
                        mt_rand(0, 65535),
                        mt_rand(16384, 20479),
                        mt_rand(32768, 49151),
                        mt_rand(0, 65535),
                        mt_rand(0, 65535),
                        mt_rand(0, 65535));
    }

    public function addUser($userLogin, $hashedPassword, $email, $alias, $tokenAuth, $dateRegistered)
    {
        $user = array(
            'login'            => $userLogin,
            'password'         => $hashedPassword,
            'alias'            => $alias,
            'email'            => $email,
            'token_auth'       => $tokenAuth,
            'user_id'          => $this->GUID(),
            'date_registered'  => $dateRegistered,
            'superuser_access' => 0,
            'ts_password_modified' => Date::now()->getDatetime(),
        );

        $db = $this->getDb();
        $db->insert($this->table, $user);
    }

results in expected behaviour.

@pebosi
Copy link
Contributor

pebosi commented Mar 6, 2020

My installation has no column called "user_id".
Please add more information, PHP, MySQL, etc.

@sgoeting
Copy link
Author

sgoeting commented Mar 6, 2020

Using a Matomo fresh install from matomo:latest (ie. 3.13.3) but database is migrated from a PiwikPro database and afterwards upgraded. So maybe that is a issue.
I'am new to both products so I am not familiar with what is legacy and what not and maybe that user_id-col is related to old PiwikPro-stuff :-)

For the record: Host is a redhat 7.3 machine with PHP 7.3.11 installed and using MariaDB 10.2.22 as a backend.

@pebosi
Copy link
Contributor

pebosi commented Mar 6, 2020

i'm pretty sure the migration was the problem :) try removing the column user_id in the users table. Backup first :)

@mattab
Copy link
Member

mattab commented Mar 7, 2020

You may find witch plug-in defines this field by grepping from the string user_id in the plugins/ folder in matomo.

@mattab mattab closed this as completed Mar 7, 2020
@tsteur tsteur added the answered For when a question was asked and we referred to forum or answered it. label Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Projects
None yet
Development

No branches or pull requests

4 participants