benedmunds / CodeIgniter-Ion-Auth

Simple and Lightweight Auth System for CodeIgniter
http://benedmunds.com/ion_auth/
MIT License
2.34k stars 1.14k forks source link

[Postgres] Wrong users_groups insert when registering user #1091

Closed phiwui closed 7 years ago

phiwui commented 7 years ago

Context : I migrate and old application (pure uggly PHP and mysql DB) into CI with Ion_Auth on Postgre DB.

In order to migrate the users of the old app, i use a migration script which get the user info from the old database and call the register method.

Bug description : The problem comes from the use of the method insert_id (line 935 of Ion_auth_model.php) that returns a wrong id and use it to insert into the users_groups table.

According to CI documentation (https://www.codeigniter.com/user_guide/database/helpers.html): If using the PDO driver with PostgreSQL, or using the Interbase driver, this function requires a $name parameter, which specifies the appropriate sequence to check for the insert id.

Proposed solution : By modifying this line with : $id = $this->db->insert_id($this->tables['users'] . '_id_seq');

the insert into users_groups table works as expected.

There is other lines using insert_id method in this file, there might also need to be modified.

Sorry for my poor english but it's not my native language.

benedmunds commented 7 years ago

Would it be possible to just check for this case in the code and make this conditional? To support both Postgres+PDO and others?

phiwui commented 7 years ago

Acording to the code of this method in others drivers, i think that passing this argument is not a problem. Other db drivers simply ignore it.

benedmunds commented 7 years ago

Ah nice! Send a PR then and I'll be happy to merge.

phiwui commented 7 years ago

The default branch seems to be named '2'.

From which branch may I must base my PR 'master' or '2' ?

Edit: I assum that is the brach '2'. Tell me if it's wrong.

benedmunds commented 7 years ago

Closing since this was merged in. Thanks!