diff --git a/vendor/JKingWeb/NewsSync/Database.php b/vendor/JKingWeb/NewsSync/Database.php index 5cad7a27..59ff2a43 100644 --- a/vendor/JKingWeb/NewsSync/Database.php +++ b/vendor/JKingWeb/NewsSync/Database.php @@ -268,8 +268,10 @@ class Database { public function subscriptionRemove(int $id): bool { $this->db->begin(); - $feed = $this->db->prepare("SELECT feed from newssync_subscriptions where id is ?", "int")->run($id)->getSingle(); - $this->db->prepare("DELETE from newssync_subscriptions where id is ?", "int")->run($id); + $user = $this->db->prepare("SELECT owner from newssync_subscriptions where id is ?", "int")->run($id)->getSingle(); + 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(); } } \ No newline at end of file diff --git a/vendor/JKingWeb/NewsSync/Db/DriverSQLite3.php b/vendor/JKingWeb/NewsSync/Db/DriverSQLite3.php index d3c1f313..7cff0263 100644 --- a/vendor/JKingWeb/NewsSync/Db/DriverSQLite3.php +++ b/vendor/JKingWeb/NewsSync/Db/DriverSQLite3.php @@ -50,10 +50,10 @@ class DriverSQLite3 implements Driver { } 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 { - return new StatementSQLite3($this->db->prepare($query), $paramTypes); + return new StatementSQLite3($this->db, $this->db->prepare($query), $paramTypes); } } \ No newline at end of file diff --git a/vendor/JKingWeb/NewsSync/Db/Result.php b/vendor/JKingWeb/NewsSync/Db/Result.php index 0cf902ea..78ad90ab 100644 --- a/vendor/JKingWeb/NewsSync/Db/Result.php +++ b/vendor/JKingWeb/NewsSync/Db/Result.php @@ -11,4 +11,5 @@ interface Result extends \Iterator { function get(); function getSingle(); + function changes(); } \ No newline at end of file diff --git a/vendor/JKingWeb/NewsSync/Db/ResultSQLite3.php b/vendor/JKingWeb/NewsSync/Db/ResultSQLite3.php index ef1371cd..10400497 100644 --- a/vendor/JKingWeb/NewsSync/Db/ResultSQLite3.php +++ b/vendor/JKingWeb/NewsSync/Db/ResultSQLite3.php @@ -7,10 +7,12 @@ class ResultSQLite3 implements Result { protected $set; protected $pos = 0; 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->set = $result; + $this->rows = $changes; } public function __destruct() { @@ -55,4 +57,8 @@ class ResultSQLite3 implements Result { $this->next(); return ($this->valid() ? $this->cur : null); } + + public function changes() { + return $this->rows; + } } \ No newline at end of file diff --git a/vendor/JKingWeb/NewsSync/Db/Statement.php b/vendor/JKingWeb/NewsSync/Db/Statement.php index 492fd4c4..4dee6d9a 100644 --- a/vendor/JKingWeb/NewsSync/Db/Statement.php +++ b/vendor/JKingWeb/NewsSync/Db/Statement.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace JKingWeb\NewsSync\Db; interface Statement { - function __construct($st, array $bindings = null); function __invoke(&...$values); // alias of run() function run(&...$values): Result; function runArray(array &$values): Result; diff --git a/vendor/JKingWeb/NewsSync/Db/StatementSQLite3.php b/vendor/JKingWeb/NewsSync/Db/StatementSQLite3.php index 7b983371..e0b235c3 100644 --- a/vendor/JKingWeb/NewsSync/Db/StatementSQLite3.php +++ b/vendor/JKingWeb/NewsSync/Db/StatementSQLite3.php @@ -3,10 +3,12 @@ declare(strict_types=1); namespace JKingWeb\NewsSync\Db; class StatementSQLite3 implements Statement { + protected $db; protected $st; protected $types; - public function __construct($st, array $bindings = null) { + public function __construct($db, $st, array $bindings = null) { + $this->db = $db; $this->st = $st; $this->types = []; foreach($bindings as $binding) { @@ -66,6 +68,6 @@ class StatementSQLite3 implements Statement { } $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); } } \ No newline at end of file diff --git a/vendor/JKingWeb/NewsSync/User.php b/vendor/JKingWeb/NewsSync/User.php index b9b46908..ad7cc369 100644 --- a/vendor/JKingWeb/NewsSync/User.php +++ b/vendor/JKingWeb/NewsSync/User.php @@ -144,7 +144,7 @@ class User { 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->exists($user)) throw new User\Exception("alreadyExists", ["user" => $user, "action" => "userAdd"]); + if($this->exists($user)) return false; $out = $this->u->userAdd($user, $password); if($out && $this->u->driverFunctions("userAdd") != User\Driver::FUNC_INTERNAL) { try { @@ -158,7 +158,7 @@ class User { 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->exists($user)) throw new User\Exception("doesNotExist", ["user" => $user, "action" => "userRemove"]); + if(!$this->exists($user)) return false; $out = $this->u->userRemove($user); if($out && $this->u->driverFunctions("userRemove") != User\Driver::FUNC_INTERNAL) { try { @@ -172,7 +172,7 @@ class User { 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->exists($user)) throw new User\Exception("doesNotExist", ["user" => $user, "action" => "userPasswordSet"]); + if(!$this->exists($user)) return false; return $this->u->userPasswordSet($user, $password); } @@ -180,7 +180,7 @@ class User { 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->exists($user)) throw new User\Exception("doesNotExist", ["user" => $user, "action" => "userPropertiesGet"]); + if(!$this->exists($user)) return false; $domain = null; if($this->data->conf->userComposeNames) $domain = substr($user,strrpos($user,"@")+1); $init = [ @@ -216,7 +216,7 @@ class User { 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->exists($user)) throw new User\Exception("doesNotExist", ["user" => $user, "action" => "userPromote"]); + if(!$this->exists($user)) return false; return $this->u->userRightsSet($user, $level); }