Browse Source

Tweaks

microsub
J. King 8 years ago
parent
commit
8f77cbba1e
  1. 6
      vendor/JKingWeb/NewsSync/Database.php
  2. 4
      vendor/JKingWeb/NewsSync/Db/DriverSQLite3.php
  3. 1
      vendor/JKingWeb/NewsSync/Db/Result.php
  4. 8
      vendor/JKingWeb/NewsSync/Db/ResultSQLite3.php
  5. 1
      vendor/JKingWeb/NewsSync/Db/Statement.php
  6. 6
      vendor/JKingWeb/NewsSync/Db/StatementSQLite3.php
  7. 10
      vendor/JKingWeb/NewsSync/User.php

6
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();
}
}

4
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);
}
}

1
vendor/JKingWeb/NewsSync/Db/Result.php

@ -11,4 +11,5 @@ interface Result extends \Iterator {
function get();
function getSingle();
function changes();
}

8
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;
}
}

1
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;

6
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);
}
}

10
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);
}

Loading…
Cancel
Save