@ -173,7 +173,7 @@ class Database {
public function userExists(string $user): bool {
public function userExists(string $user): bool {
if(!$this->data->user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
if(!$this->data->user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
return (bool) $this->db->prepare("SELECT count(*) from newssync_users where id is ?", "str")->run($user)->getSingl e();
return (bool) $this->db->prepare("SELECT count(*) from newssync_users where id is ?", "str")->run($user)->getValu e();
}
}
public function userAdd(string $user, string $password = null): string {
public function userAdd(string $user, string $password = null): string {
@ -212,7 +212,7 @@ class Database {
public function userPasswordGet(string $user): string {
public function userPasswordGet(string $user): string {
if(!$this->data->user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
if(!$this->data->user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
if(!$this->userExists($user)) throw new User\Exception("doesNotExist", ["action" => __FUNCTION__, "user" => $user]);
if(!$this->userExists($user)) throw new User\Exception("doesNotExist", ["action" => __FUNCTION__, "user" => $user]);
return (string) $this->db->prepare("SELECT password from newssync_users where id is ?", "str")->run($user)->getSingl e();
return (string) $this->db->prepare("SELECT password from newssync_users where id is ?", "str")->run($user)->getValu e();
}
}
public function userPasswordSet(string $user, string $password = null): string {
public function userPasswordSet(string $user, string $password = null): string {
@ -249,7 +249,7 @@ class Database {
public function userRightsGet(string $user): int {
public function userRightsGet(string $user): int {
if(!$this->data->user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
if(!$this->data->user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
return (int) $this->db->prepare("SELECT rights from newssync_users where id is ?", "str")->run($user)->getSingl e();
return (int) $this->db->prepare("SELECT rights from newssync_users where id is ?", "str")->run($user)->getValu e();
}
}
public function userRightsSet(string $user, int $rights): bool {
public function userRightsSet(string $user, int $rights): bool {
@ -273,7 +273,7 @@ class Database {
// If the feed doesn't already exist in the database then add it to the database after determining its validity with PicoFeed.
// If the feed doesn't already exist in the database then add it to the database after determining its validity with PicoFeed.
$qFeed = $this->db->prepare("SELECT id from newssync_feeds where url is ? and username is ? and password is ?", "str", "str", "str");
$qFeed = $this->db->prepare("SELECT id from newssync_feeds where url is ? and username is ? and password is ?", "str", "str", "str");
$feed = $qFeed->run($url, $fetchUser, $fetchPassword)->getSingl e();
$feed = $qFeed->run($url, $fetchUser, $fetchPassword)->getValu e();
if ($feed === null) {
if ($feed === null) {
try {
try {
$reader = new Reader;
$reader = new Reader;
@ -310,19 +310,19 @@ class Database {
// TODO: Populate newssync_articles with contents of what was obtained from PicoFeed.
// TODO: Populate newssync_articles with contents of what was obtained from PicoFeed.
// Get the ID for the feed that was just added.
// Get the ID for the feed that was just added.
$feedID = $qFeed->run($url, $fetchUser, $fetchPassword)->getSingl e();
$feedID = $qFeed->run($url, $fetchUser, $fetchPassword)->getValu e();
}
}
// Add the feed to the user's subscriptions.
// Add the feed to the user's subscriptions.
$this->db->prepare("INSERT INTO newssync_subscriptions(owner,feed) values(?,?)", "str", "int")->run($user, $feedID);
$this->db->prepare("INSERT INTO newssync_subscriptions(owner,feed) values(?,?)", "str", "int")->run($user, $feedID);
$sub = $this->db->prepare("SELECT id from newssync_subscriptions where owner is ? and feed is ?", "str", "int")->run($user, $feedID)->getSingl e();
$sub = $this->db->prepare("SELECT id from newssync_subscriptions where owner is ? and feed is ?", "str", "int")->run($user, $feedID)->getValu e();
$this->db->commit();
$this->db->commit();
return $sub;
return $sub;
}
}
public function subscriptionRemove(int $id): bool {
public function subscriptionRemove(int $id): bool {
$this->db->begin();
$this->db->begin();
$user = $this->db->prepare("SELECT owner from newssync_subscriptions where id is ?", "int")->run($id)->getSingl e();
$user = $this->db->prepare("SELECT owner from newssync_subscriptions where id is ?", "int")->run($id)->getValu e();
if($user===null) return false;
if($user===null) return false;
if(!$this->data->user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
if(!$this->data->user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
return (bool) $this->db->prepare("DELETE from newssync_subscriptions where id is ?", "int")->run($id)->changes();
return (bool) $this->db->prepare("DELETE from newssync_subscriptions where id is ?", "int")->run($id)->changes();