Removed timezone + API improvements
This commit is contained in:
parent
73d20b4b5c
commit
9904be687f
@ -177,8 +177,11 @@ namespace Api\Groups {
|
||||
}
|
||||
|
||||
$id = $this->getParam("uid");
|
||||
$sql = $this->user->getSQL();
|
||||
if (in_array($id, DEFAULT_GROUPS)) {
|
||||
return $this->createError("You cannot delete a default group.");
|
||||
}
|
||||
|
||||
$sql = $this->user->getSQL();
|
||||
$res = $sql->select($sql->count())
|
||||
->from("Group")
|
||||
->where(new Compare("uid", $id))
|
||||
|
@ -26,7 +26,7 @@ namespace Api\Routes {
|
||||
use Api\RoutesAPI;
|
||||
use Driver\SQL\Column\Column;
|
||||
use Driver\SQL\Condition\CondBool;
|
||||
use Driver\SQL\Condition\Regex;
|
||||
use Driver\SQL\Condition\CondRegex;
|
||||
|
||||
class Fetch extends RoutesAPI {
|
||||
|
||||
@ -99,7 +99,7 @@ namespace Api\Routes {
|
||||
->select("uid", "request", "action", "target", "extra")
|
||||
->from("Route")
|
||||
->where(new CondBool("active"))
|
||||
->where(new Regex($request, new Column("request")))
|
||||
->where(new CondRegex($request, new Column("request")))
|
||||
->limit(1)
|
||||
->execute();
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace Driver\SQL\Condition;
|
||||
|
||||
use Driver\SQL\Column\Column;
|
||||
|
||||
class CondIn extends Condition {
|
||||
|
||||
private string $column;
|
||||
|
@ -2,16 +2,19 @@
|
||||
|
||||
namespace Driver\SQL\Condition;
|
||||
|
||||
class Regex extends Condition {
|
||||
abstract class CondKeyword extends Condition {
|
||||
|
||||
private $leftExpression;
|
||||
private $rightExpression;
|
||||
private string $keyword;
|
||||
|
||||
public function __construct($leftExpression, $rightExpression) {
|
||||
public function __construct($keyword, $leftExpression, $rightExpression) {
|
||||
$this->leftExpression = $leftExpression;
|
||||
$this->rightExpression = $rightExpression;
|
||||
$this->keyword = $keyword;
|
||||
}
|
||||
|
||||
public function getLeftExp() { return $this->leftExpression; }
|
||||
public function getRightExp() { return $this->rightExpression; }
|
||||
public function getKeyword() { return $this->keyword; }
|
||||
}
|
10
core/Driver/SQL/Condition/CondLike.class.php
Normal file
10
core/Driver/SQL/Condition/CondLike.class.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Driver\SQL\Condition;
|
||||
|
||||
class CondLike extends CondKeyword {
|
||||
|
||||
public function __construct($leftExpression, $rightExpression) {
|
||||
parent::__construct("LIKE", $leftExpression, $rightExpression);
|
||||
}
|
||||
}
|
11
core/Driver/SQL/Condition/CondRegex.class.php
Normal file
11
core/Driver/SQL/Condition/CondRegex.class.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Driver\SQL\Condition;
|
||||
|
||||
class CondRegex extends CondKeyword {
|
||||
|
||||
public function __construct($leftExpression, $rightExpression) {
|
||||
parent::__construct("REGEXP", $leftExpression, $rightExpression);
|
||||
}
|
||||
|
||||
}
|
@ -13,7 +13,7 @@ use \Driver\SQL\Column\DateTimeColumn;
|
||||
use Driver\SQL\Column\BoolColumn;
|
||||
use Driver\SQL\Column\JsonColumn;
|
||||
|
||||
use Driver\SQL\Condition\Regex;
|
||||
use Driver\SQL\Condition\CondRegex;
|
||||
use Driver\SQL\Expression\Add;
|
||||
use Driver\SQL\Strategy\Strategy;
|
||||
use \Driver\SQL\Strategy\UpdateStrategy;
|
||||
@ -304,16 +304,4 @@ class MySQL extends SQL {
|
||||
public function getStatus() {
|
||||
return mysqli_stat($this->connection);
|
||||
}
|
||||
|
||||
protected function buildCondition($condition, &$params) {
|
||||
if($condition instanceof Regex) {
|
||||
$left = $condition->getLeftExp();
|
||||
$right = $condition->getRightExp();
|
||||
$left = ($left instanceof Column) ? $this->columnName($left->getName()) : $this->addValue($left, $params);
|
||||
$right = ($right instanceof Column) ? $this->columnName($right->getName()) : $this->addValue($right, $params);
|
||||
return $left . " REGEXP " . $right;
|
||||
} else {
|
||||
return parent::buildCondition($condition, $params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ use \Driver\SQL\Column\DateTimeColumn;
|
||||
use Driver\SQL\Column\BoolColumn;
|
||||
use Driver\SQL\Column\JsonColumn;
|
||||
|
||||
use Driver\SQL\Condition\Regex;
|
||||
use Driver\SQL\Condition\CondRegex;
|
||||
use Driver\SQL\Expression\Add;
|
||||
use Driver\SQL\Strategy\Strategy;
|
||||
use Driver\SQL\Strategy\UpdateStrategy;
|
||||
@ -304,7 +304,7 @@ class PostgreSQL extends SQL {
|
||||
}
|
||||
|
||||
protected function buildCondition($condition, &$params) {
|
||||
if($condition instanceof Regex) {
|
||||
if($condition instanceof CondRegex) {
|
||||
$left = $condition->getLeftExp();
|
||||
$right = $condition->getRightExp();
|
||||
$left = ($left instanceof Column) ? $this->columnName($left->getName()) : $this->addValue($left, $params);
|
||||
|
@ -6,8 +6,9 @@ use Driver\SQL\Column\Column;
|
||||
use Driver\SQL\Condition\Compare;
|
||||
use Driver\SQL\Condition\CondBool;
|
||||
use Driver\SQL\Condition\CondIn;
|
||||
use Driver\SQL\Condition\CondKeyword;
|
||||
use Driver\SQL\Condition\CondOr;
|
||||
use Driver\SQL\Condition\Regex;
|
||||
use Driver\SQL\Condition\CondRegex;
|
||||
use Driver\SQL\Constraint\Constraint;
|
||||
use \Driver\SQL\Constraint\Unique;
|
||||
use \Driver\SQL\Constraint\PrimaryKey;
|
||||
@ -343,6 +344,13 @@ abstract class SQL {
|
||||
|
||||
$values = implode(",", $values);
|
||||
return $this->columnName($condition->getColumn()) . " IN ($values)";
|
||||
} else if($condition instanceof CondKeyword) {
|
||||
$left = $condition->getLeftExp();
|
||||
$right = $condition->getRightExp();
|
||||
$keyword = $condition->getKeyword();
|
||||
$left = ($left instanceof Column) ? $this->columnName($left->getName()) : $this->addValue($left, $params);
|
||||
$right = ($right instanceof Column) ? $this->columnName($right->getName()) : $this->addValue($right, $params);
|
||||
return "$left $keyword $right ";
|
||||
} else {
|
||||
$this->lastError = "Unsupported condition type: " . get_class($condition);
|
||||
return false;
|
||||
|
@ -7,6 +7,10 @@ const USER_GROUP_SUPPORT_NAME = "Support";
|
||||
const USER_GROUP_ADMIN = 3;
|
||||
const USER_GROUP_ADMIN_NAME = "Administrator";
|
||||
|
||||
const DEFAULT_GROUPS = array(
|
||||
USER_GROUP_MODERATOR, USER_GROUP_SUPPORT, USER_GROUP_ADMIN
|
||||
);
|
||||
|
||||
function GroupName($index) {
|
||||
$groupNames = array(
|
||||
USER_GROUP_MODERATOR => USER_GROUP_MODERATOR_NAME,
|
||||
|
@ -1,26 +1,5 @@
|
||||
<?php
|
||||
|
||||
function setTimezone($default) {
|
||||
$timezone = "";
|
||||
if (is_link("/etc/localtime")) {
|
||||
$filename = readlink("/etc/localtime");
|
||||
$pos = strpos($filename, "zoneinfo");
|
||||
if ($pos) {
|
||||
$timezone = substr($filename, $pos + strlen("zoneinfo/"));
|
||||
} else {
|
||||
$timezone = $default;
|
||||
}
|
||||
} else {
|
||||
$timezone = file_get_contents("/etc/timezone");
|
||||
if (!strlen($timezone)) {
|
||||
$timezone = $default;
|
||||
}
|
||||
}
|
||||
date_default_timezone_set($timezone);
|
||||
}
|
||||
|
||||
setTimezone("UTC");
|
||||
|
||||
function getFirstWeekDayOfMonth($d = NULL) {
|
||||
if(is_null($d)) $d = date('Y-m-d H:i:s');
|
||||
$dt = new DateTime($d);
|
||||
|
Loading…
Reference in New Issue
Block a user