mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Tweaks
This commit is contained in:
parent
9ed4bb6f5b
commit
8f77cbba1e
7 changed files with 23 additions and 13 deletions
6
vendor/JKingWeb/NewsSync/Database.php
vendored
6
vendor/JKingWeb/NewsSync/Database.php
vendored
|
@ -268,8 +268,10 @@ class Database {
|
||||||
|
|
||||||
public function subscriptionRemove(int $id): bool {
|
public function subscriptionRemove(int $id): bool {
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
$feed = $this->db->prepare("SELECT feed from newssync_subscriptions where id is ?", "int")->run($id)->getSingle();
|
$user = $this->db->prepare("SELECT owner from newssync_subscriptions where id is ?", "int")->run($id)->getSingle();
|
||||||
$this->db->prepare("DELETE from newssync_subscriptions where id is ?", "int")->run($id);
|
if($user===null) return false;
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -50,10 +50,10 @@ class DriverSQLite3 implements Driver {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function query(string $query): Result {
|
public function query(string $query): Result {
|
||||||
return new ResultSQLite3($this->db->query($query));
|
return new ResultSQLite3($this->db->query($query), $this->db->changes());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prepareArray(string $query, array $paramTypes): Statement {
|
public function prepareArray(string $query, array $paramTypes): Statement {
|
||||||
return new StatementSQLite3($this->db->prepare($query), $paramTypes);
|
return new StatementSQLite3($this->db, $this->db->prepare($query), $paramTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
1
vendor/JKingWeb/NewsSync/Db/Result.php
vendored
1
vendor/JKingWeb/NewsSync/Db/Result.php
vendored
|
@ -11,4 +11,5 @@ interface Result extends \Iterator {
|
||||||
|
|
||||||
function get();
|
function get();
|
||||||
function getSingle();
|
function getSingle();
|
||||||
|
function changes();
|
||||||
}
|
}
|
|
@ -7,10 +7,12 @@ class ResultSQLite3 implements Result {
|
||||||
protected $set;
|
protected $set;
|
||||||
protected $pos = 0;
|
protected $pos = 0;
|
||||||
protected $cur = null;
|
protected $cur = null;
|
||||||
|
protected $rows = 0;
|
||||||
|
|
||||||
public function __construct($result, $statement = null) {
|
public function __construct($result, $changes, $statement = null) {
|
||||||
$this->st = $statement; //keeps the statement from being destroyed, invalidating the result set
|
$this->st = $statement; //keeps the statement from being destroyed, invalidating the result set
|
||||||
$this->set = $result;
|
$this->set = $result;
|
||||||
|
$this->rows = $changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct() {
|
public function __destruct() {
|
||||||
|
@ -55,4 +57,8 @@ class ResultSQLite3 implements Result {
|
||||||
$this->next();
|
$this->next();
|
||||||
return ($this->valid() ? $this->cur : null);
|
return ($this->valid() ? $this->cur : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function changes() {
|
||||||
|
return $this->rows;
|
||||||
|
}
|
||||||
}
|
}
|
1
vendor/JKingWeb/NewsSync/Db/Statement.php
vendored
1
vendor/JKingWeb/NewsSync/Db/Statement.php
vendored
|
@ -3,7 +3,6 @@ declare(strict_types=1);
|
||||||
namespace JKingWeb\NewsSync\Db;
|
namespace JKingWeb\NewsSync\Db;
|
||||||
|
|
||||||
interface Statement {
|
interface Statement {
|
||||||
function __construct($st, array $bindings = null);
|
|
||||||
function __invoke(&...$values); // alias of run()
|
function __invoke(&...$values); // alias of run()
|
||||||
function run(&...$values): Result;
|
function run(&...$values): Result;
|
||||||
function runArray(array &$values): Result;
|
function runArray(array &$values): Result;
|
||||||
|
|
|
@ -3,10 +3,12 @@ declare(strict_types=1);
|
||||||
namespace JKingWeb\NewsSync\Db;
|
namespace JKingWeb\NewsSync\Db;
|
||||||
|
|
||||||
class StatementSQLite3 implements Statement {
|
class StatementSQLite3 implements Statement {
|
||||||
|
protected $db;
|
||||||
protected $st;
|
protected $st;
|
||||||
protected $types;
|
protected $types;
|
||||||
|
|
||||||
public function __construct($st, array $bindings = null) {
|
public function __construct($db, $st, array $bindings = null) {
|
||||||
|
$this->db = $db;
|
||||||
$this->st = $st;
|
$this->st = $st;
|
||||||
$this->types = [];
|
$this->types = [];
|
||||||
foreach($bindings as $binding) {
|
foreach($bindings as $binding) {
|
||||||
|
@ -66,6 +68,6 @@ class StatementSQLite3 implements Statement {
|
||||||
}
|
}
|
||||||
$this->st->bindParam($a+1, $values[$a], $type);
|
$this->st->bindParam($a+1, $values[$a], $type);
|
||||||
}
|
}
|
||||||
return new ResultSQLite3($this->st->execute(), $this);
|
return new ResultSQLite3($this->st->execute(), $this->db->changes(), $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
10
vendor/JKingWeb/NewsSync/User.php
vendored
10
vendor/JKingWeb/NewsSync/User.php
vendored
|
@ -144,7 +144,7 @@ class User {
|
||||||
if($this->u->driverFunctions("userAdd") != User\Driver::FUNC_INTERNAL) {
|
if($this->u->driverFunctions("userAdd") != User\Driver::FUNC_INTERNAL) {
|
||||||
if(!$this->data->user->authorize($user, "userAdd")) throw new User\ExceptionAuthz("notAuthorized", ["action" => "userAdd", "user" => $user]);
|
if(!$this->data->user->authorize($user, "userAdd")) throw new User\ExceptionAuthz("notAuthorized", ["action" => "userAdd", "user" => $user]);
|
||||||
}
|
}
|
||||||
if($this->exists($user)) throw new User\Exception("alreadyExists", ["user" => $user, "action" => "userAdd"]);
|
if($this->exists($user)) return false;
|
||||||
$out = $this->u->userAdd($user, $password);
|
$out = $this->u->userAdd($user, $password);
|
||||||
if($out && $this->u->driverFunctions("userAdd") != User\Driver::FUNC_INTERNAL) {
|
if($out && $this->u->driverFunctions("userAdd") != User\Driver::FUNC_INTERNAL) {
|
||||||
try {
|
try {
|
||||||
|
@ -158,7 +158,7 @@ class User {
|
||||||
if($this->u->driverFunctions("userRemove") != User\Driver::FUNC_INTERNAL) {
|
if($this->u->driverFunctions("userRemove") != User\Driver::FUNC_INTERNAL) {
|
||||||
if(!$this->data->user->authorize($user, "userRemove")) throw new User\ExceptionAuthz("notAuthorized", ["action" => "userRemove", "user" => $user]);
|
if(!$this->data->user->authorize($user, "userRemove")) throw new User\ExceptionAuthz("notAuthorized", ["action" => "userRemove", "user" => $user]);
|
||||||
}
|
}
|
||||||
if(!$this->exists($user)) throw new User\Exception("doesNotExist", ["user" => $user, "action" => "userRemove"]);
|
if(!$this->exists($user)) return false;
|
||||||
$out = $this->u->userRemove($user);
|
$out = $this->u->userRemove($user);
|
||||||
if($out && $this->u->driverFunctions("userRemove") != User\Driver::FUNC_INTERNAL) {
|
if($out && $this->u->driverFunctions("userRemove") != User\Driver::FUNC_INTERNAL) {
|
||||||
try {
|
try {
|
||||||
|
@ -172,7 +172,7 @@ class User {
|
||||||
if($this->u->driverFunctions("userPasswordSet") != User\Driver::FUNC_INTERNAL) {
|
if($this->u->driverFunctions("userPasswordSet") != User\Driver::FUNC_INTERNAL) {
|
||||||
if(!$this->data->user->authorize($user, "userPasswordSet")) throw new User\ExceptionAuthz("notAuthorized", ["action" => "userPasswordSet", "user" => $user]);
|
if(!$this->data->user->authorize($user, "userPasswordSet")) throw new User\ExceptionAuthz("notAuthorized", ["action" => "userPasswordSet", "user" => $user]);
|
||||||
}
|
}
|
||||||
if(!$this->exists($user)) throw new User\Exception("doesNotExist", ["user" => $user, "action" => "userPasswordSet"]);
|
if(!$this->exists($user)) return false;
|
||||||
return $this->u->userPasswordSet($user, $password);
|
return $this->u->userPasswordSet($user, $password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ class User {
|
||||||
if($this->u->driverFunctions("userPropertiesGet") != User\Driver::FUNC_INTERNAL) {
|
if($this->u->driverFunctions("userPropertiesGet") != User\Driver::FUNC_INTERNAL) {
|
||||||
if(!$this->data->user->authorize($user, "userPropertiesGet")) throw new User\ExceptionAuthz("notAuthorized", ["action" => "userPropertiesGet", "user" => $user]);
|
if(!$this->data->user->authorize($user, "userPropertiesGet")) throw new User\ExceptionAuthz("notAuthorized", ["action" => "userPropertiesGet", "user" => $user]);
|
||||||
}
|
}
|
||||||
if(!$this->exists($user)) throw new User\Exception("doesNotExist", ["user" => $user, "action" => "userPropertiesGet"]);
|
if(!$this->exists($user)) return false;
|
||||||
$domain = null;
|
$domain = null;
|
||||||
if($this->data->conf->userComposeNames) $domain = substr($user,strrpos($user,"@")+1);
|
if($this->data->conf->userComposeNames) $domain = substr($user,strrpos($user,"@")+1);
|
||||||
$init = [
|
$init = [
|
||||||
|
@ -216,7 +216,7 @@ class User {
|
||||||
if($this->u->driverFunctions("userRightsSet") != User\Driver::FUNC_INTERNAL) {
|
if($this->u->driverFunctions("userRightsSet") != User\Driver::FUNC_INTERNAL) {
|
||||||
if(!$this->data->user->authorize($user, "userRightsSet")) throw new User\ExceptionAuthz("notAuthorized", ["action" => "userRightsSet", "user" => $user]);
|
if(!$this->data->user->authorize($user, "userRightsSet")) throw new User\ExceptionAuthz("notAuthorized", ["action" => "userRightsSet", "user" => $user]);
|
||||||
}
|
}
|
||||||
if(!$this->exists($user)) throw new User\Exception("doesNotExist", ["user" => $user, "action" => "userPromote"]);
|
if(!$this->exists($user)) return false;
|
||||||
return $this->u->userRightsSet($user, $level);
|
return $this->u->userRightsSet($user, $level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue