composer update + SQL Compare refactored

This commit is contained in:
Roman Hergenreder
2022-11-26 23:57:28 +01:00
parent b1c4c9e976
commit 3b2b5984d6
23 changed files with 317 additions and 540 deletions

View File

@@ -15,10 +15,10 @@ namespace Core\API {
$sql = $this->context->getSQL();
$res = $sql->select($sql->count())
->from("ApiKey")
->where(new Compare("id", $id))
->where(new Compare("user_id", $this->context->getUser()->getId()))
->where(new Compare("valid_until", $sql->currentTimestamp(), ">"))
->where(new Compare("active", 1))
->whereEq("id", $id)
->whereEq("user_id", $this->context->getUser()->getId())
->whereGt("valid_until", $sql->currentTimestamp())
->whereEq("active", 1)
->execute();
$this->success = ($res !== FALSE);
@@ -120,12 +120,12 @@ namespace Core\API\ApiKey {
return false;
}
$validUntil = (new \DateTime)->modify("+30 DAY");
$validUntil = (new \DateTime())->modify("+30 DAY");
$sql = $this->context->getSQL();
$this->success = $sql->update("ApiKey")
->set("valid_until", $validUntil)
->where(new Compare("id", $id))
->where(new Compare("user_id", $this->context->getUser()->getId()))
->whereEq("id", $id)
->whereEq("user_id", $this->context->getUser()->getId())
->execute();
$this->lastError = $sql->getLastError();
@@ -155,8 +155,8 @@ namespace Core\API\ApiKey {
$sql = $this->context->getSQL();
$this->success = $sql->update("ApiKey")
->set("active", false)
->where(new Compare("id", $id))
->where(new Compare("user_id", $this->context->getUser()->getId()))
->whereEq("id", $id)
->whereEq("user_id", $this->context->getUser()->getId())
->execute();
$this->lastError = $sql->getLastError();

View File

@@ -15,7 +15,7 @@ namespace Core\API {
$sql = $this->context->getSQL();
$res = $sql->select($sql->count())
->from("Group")
->where(new Compare("name", $name))
->whereEq("name", $name)
->execute();
$this->success = ($res !== FALSE);

View File

@@ -94,7 +94,7 @@ namespace Core\API\Language {
$this->success = $sql->update("User")
->set("language_id", $languageId)
->where(new Compare("id", $userId))
->whereEq("id", $userId)
->execute();
$this->lastError = $sql->getLastError();

View File

@@ -223,8 +223,8 @@ namespace Core\API\Mail {
$sql = $this->context->getSQL();
$mailQueueItems = MailQueueItem::findBy(MailQueueItem::createBuilder($sql, false)
->where(new Compare("retryCount", 0, ">"))
->where(new Compare("status", "waiting"))
->whereGt("retryCount", 0)
->whereEq("status", "waiting")
->where(new Compare("nextTry", $sql->now(), "<=")));
$this->success = ($mailQueueItems !== false);

View File

@@ -183,7 +183,7 @@ namespace Core\API\Permission {
if ($this->success) {
$res = $sql->delete("ApiPermission")
->where(new Compare("description", "")) // only delete non default permissions
->whereEq("description", "") // only delete non default permissions
->where(new CondNot(new CondIn(new Column("method"), $insertedMethods)))
->execute();

View File

@@ -22,7 +22,7 @@ namespace Core\API {
$sql = $this->context->getSQL();
$res = $sql->select($sql->count())
->from("Route")
->where(new Compare("id", $uid))
->whereEq("id", $uid)
->execute();
$this->success = ($res !== false);
@@ -44,7 +44,7 @@ namespace Core\API {
$sql = $this->context->getSQL();
$this->success = $sql->update("Route")
->set("active", $active)
->where(new Compare("id", $uid))
->whereEq("id", $uid)
->execute();
$this->lastError = $sql->getLastError();
@@ -275,7 +275,7 @@ namespace Core\API\Routes {
->set("action", $action)
->set("target", $target)
->set("extra", $extra)
->where(new Compare("id", $id))
->whereEq("id", $id)
->execute();
$this->lastError = $sql->getLastError();
@@ -294,14 +294,14 @@ namespace Core\API\Routes {
public function _execute(): bool {
$uid = $this->getParam("id");
if (!$this->routeExists($uid)) {
$id = $this->getParam("id");
if (!$this->routeExists($id)) {
return false;
}
$sql = $this->context->getSQL();
$this->success = $sql->delete("Route")
->where(new Compare("id", $uid))
->where("id", $id)
->execute();
$this->lastError = $sql->getLastError();

View File

@@ -86,7 +86,7 @@ namespace Core\API\TFA {
if ($password) {
$res = $sql->select("password")
->from("User")
->where(new Compare("id", $currentUser->getId()))
->whereEq("id", $currentUser->getId())
->execute();
$this->success = !empty($res);
$this->lastError = $sql->getLastError();
@@ -101,7 +101,7 @@ namespace Core\API\TFA {
}
$res = $sql->delete("2FA")
->where(new Compare("id", $token->getId()))
->whereEq("id", $token->getId())
->execute();
$this->success = $res !== false;
@@ -164,7 +164,8 @@ namespace Core\API\TFA {
$this->lastError = $sql->getLastError();
if ($this->success) {
$this->success = $sql->update("User")
->set("2fa_id", $sql->getLastInsertId())->where(new Compare("id", $currentUser->getId()))
->set("2fa_id", $sql->getLastInsertId())
->whereEq("id", $currentUser->getId())
->execute() !== false;
$this->lastError = $sql->getLastError();
}
@@ -196,7 +197,7 @@ namespace Core\API\TFA {
$sql = $this->context->getSQL();
$this->success = $sql->update("2FA")
->set("confirmed", true)
->where(new Compare("id", $twoFactorToken->getId()))
->whereEq("id", $twoFactorToken->getId())
->execute() !== false;
$this->lastError = $sql->getLastError();
return $this->success;
@@ -282,7 +283,7 @@ namespace Core\API\TFA {
$this->success = $sql->update("User")
->set("2fa_id", $sql->getLastInsertId())
->where(new Compare("id", $currentUser->getId()))
->whereEq("id", $currentUser->getId())
->execute() !== false;
$this->lastError = $sql->getLastError();
if (!$this->success) {
@@ -328,7 +329,7 @@ namespace Core\API\TFA {
$this->success = $sql->update("2FA")
->set("data", json_encode($data))
->set("confirmed", true)
->where(new Compare("id", $twoFactorToken->getId()))
->whereEq("id", $twoFactorToken->getId())
->execute() !== false;
$this->lastError = $sql->getLastError();
}

View File

@@ -109,9 +109,9 @@ namespace Core\API {
protected function checkToken(string $token) : UserToken|bool {
$sql = $this->context->getSQL();
$userToken = UserToken::findBy(UserToken::createBuilder($sql, true)
->where(new Compare("UserToken.token", $token))
->where(new Compare("UserToken.valid_until", $sql->now(), ">"))
->where(new Compare("UserToken.used", 0))
->whereEq("UserToken.token", $token)
->whereGt("UserToken.valid_until", $sql->now())
->whereFalse("UserToken.used")
->fetchEntities());
if ($userToken === false) {
@@ -841,7 +841,7 @@ namespace Core\API\User {
if ($user->save($sql)) {
$deleteQuery = $sql->delete("UserGroup")->where(new Compare("user_id", $id));
$deleteQuery = $sql->delete("UserGroup")->whereEq("user_id", $id);
$insertQuery = $sql->insert("UserGroup", array("user_id", "group_id"));
foreach ($groupIds as $groupId) {
@@ -928,7 +928,7 @@ namespace Core\API\User {
$sql = $this->context->getSQL();
$email = $this->getParam("email");
$user = User::findBy(User::createBuilder($sql, true)
->where(new Compare("email", $email))
->whereEq("email", $email)
->fetchEntities());
if ($user === false) {
return $this->createError("Could not fetch user details: " . $sql->getLastError());
@@ -1009,8 +1009,8 @@ namespace Core\API\User {
$email = $this->getParam("email");
$sql = $this->context->getSQL();
$user = User::findBy(User::createBuilder($sql, true)
->where(new Compare("User.email", $email))
->where(new Compare("User.confirmed", false)));
->whereEq("User.email", $email)
->whereFalse("User.confirmed"));
if ($user === false) {
return $this->createError("Error retrieving user details: " . $sql->getLastError());
@@ -1020,9 +1020,9 @@ namespace Core\API\User {
}
$userToken = UserToken::findBy(UserToken::createBuilder($sql, true)
->where(new Compare("used", false))
->where(new Compare("tokenType", UserToken::TYPE_EMAIL_CONFIRM))
->where(new Compare("user_id", $user->getId())));
->whereFalse("used")
->whereEq("tokenType", UserToken::TYPE_EMAIL_CONFIRM)
->whereEq("user_id", $user->getId()));
$validHours = 48;
if ($userToken === false) {
@@ -1333,10 +1333,10 @@ namespace Core\API\User {
$sql = $this->context->getSQL();
$userToken = UserToken::findBy(UserToken::createBuilder($sql, true)
->where(new Compare("token", $token))
->whereEq("token", $token)
->where(new Compare("valid_until", $sql->now(), ">="))
->where(new Compare("user_id", $currentUser->getId()))
->where(new Compare("token_type", UserToken::TYPE_GPG_CONFIRM)));
->whereEq("user_id", $currentUser->getId())
->whereEq("token_type", UserToken::TYPE_GPG_CONFIRM));
if ($userToken !== false) {
if ($userToken === null) {

View File

@@ -84,7 +84,7 @@ namespace Core\API\Visitors {
$sql = $this->context->getSQL();
$query = $sql->select($sql->count(), "day")
->from("Visitor")
->where(new Compare("count", 1, ">"))
->whereGt("count", 1)
->groupBy("day")
->orderBy("day")
->ascending();