1
1
Fork 0
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:
J. King 2021-05-17 15:46:46 -04:00
parent 805a508ea6
commit 3eab5aad5d
2 changed files with 8 additions and 1 deletions

View file

@ -271,7 +271,7 @@ class Database {
} }
$hash = (strlen($password) > 0) ? password_hash($password, \PASSWORD_DEFAULT) : ""; $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 // 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; return true;
} }

View file

@ -205,4 +205,11 @@ trait SeriesUser {
$this->assertException("alreadyExists", "User", "ExceptionConflict"); $this->assertException("alreadyExists", "User", "ExceptionConflict");
Arsse::$db->userRename("john.doe@example.com", "jane.doe@example.com"); 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", ""));
}
} }