Move domain items up to lib

- WIP on converting more complex queries
This commit is contained in:
2024-05-31 22:57:24 -04:00
parent f7f5dba795
commit 610ab67475
16 changed files with 189 additions and 167 deletions

View File

@@ -6,8 +6,9 @@ use BitBadger\Documents\SQLite\Count;
use BitBadger\Documents\SQLite\Delete;
use BitBadger\Documents\SQLite\Patch;
use FeedReaderCentral\Data;
use FeedReaderCentral\Domain\Table;
use FeedReaderCentral\Security;
use FeedReaderCentral\Table;
use FeedReaderCentral\User;
require __DIR__ . '/../cli-start.php';
@@ -99,15 +100,17 @@ function add_user(): void
try {
// Ensure there is not already a user with this e-mail address
$user = Security::findUserByEmail($argv[2], $db);
$user = User::findByEmail($argv[2]);
if ($user) {
printfn('A user with e-mail address "%s" already exists', $argv[2]);
return;
}
Security::addUser($argv[2], $argv[3], $db);
User::add($argv[2], $argv[3], $db);
printfn('User "%s" with password "%s" added successfully', $argv[2], $argv[3]);
} catch (DocumentException $ex) {
printfn("$ex");
} finally {
$db->close();
}
@@ -134,7 +137,7 @@ function set_password(string $email, string $password): void
$displayUser = display_user($email);
// Ensure this user exists
$user = Security::findUserByEmail($email, $db);
$user = User::findByEmail($email);
if (!$user) {
printfn('No %s exists', $displayUser);
return;
@@ -145,6 +148,8 @@ function set_password(string $email, string $password): void
$msg = $email == Security::SINGLE_USER_EMAIL && $password == Security::SINGLE_USER_PASSWORD
? 'reset' : sprintf('set to "%s"', $password);
printfn('%s password %s successfully', init_cap($displayUser), $msg);
} catch (DocumentException $ex) {
printfn("$ex");
} finally {
$db->close();
}
@@ -163,7 +168,7 @@ function delete_user(string $email): void
$displayUser = display_user($email);
// Get the user for the provided e-mail address
$user = Security::findUserByEmail($email, $db);
$user = User::findByEmail($email);
if (!$user) {
printfn('No %s exists', $displayUser);
return;
@@ -195,6 +200,8 @@ function delete_user(string $email): void
} catch (DocumentException $ex) {
printfn("$ex");
}
} catch (DocumentException $ex) {
printfn("$ex");
} finally {
$db->close();
}
@@ -210,7 +217,7 @@ function migrate_single_user(): void
$db = Data::getConnection();
try {
if (!$single = Security::findUserByEmail(Security::SINGLE_USER_EMAIL, $db)) {
if (!$single = User::findByEmail(Security::SINGLE_USER_EMAIL)) {
printfn('There is no single-user mode user to be migrated');
return;
}