mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Fix adding users to a blank database
This commit is contained in:
parent
805a508ea6
commit
3eab5aad5d
2 changed files with 8 additions and 1 deletions
|
@ -271,7 +271,7 @@ class Database {
|
|||
}
|
||||
$hash = (strlen($password) > 0) ? password_hash($password, \PASSWORD_DEFAULT) : "";
|
||||
// NOTE: This roundabout construction (with 'select' rather than 'values') is required by MySQL, because MySQL is riddled with pitfalls and exceptions
|
||||
$this->db->prepare("INSERT INTO arsse_users(id,password,num) select ?, ?, ((select max(num) from arsse_users) + 1)", "str", "str")->runArray([$user,$hash]);
|
||||
$this->db->prepare("INSERT INTO arsse_users(id,password,num) select ?, ?, (coalesce((select max(num) from arsse_users), 0) + 1)", "str", "str")->runArray([$user,$hash]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -205,4 +205,11 @@ trait SeriesUser {
|
|||
$this->assertException("alreadyExists", "User", "ExceptionConflict");
|
||||
Arsse::$db->userRename("john.doe@example.com", "jane.doe@example.com");
|
||||
}
|
||||
|
||||
public function testAddFirstUser(): void {
|
||||
// first truncate the users table
|
||||
static::$drv->exec("DELETE FROM arsse_users");
|
||||
// add a user; if the max of the num column is not properly coalesced, this will result in a constraint violation
|
||||
$this->assertTrue(Arsse::$db->userAdd("john.doe@example.com", ""));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue