4 Commits
Author SHA1 Message Date
bence 585d469b69 Merge pull request 'use the correct table alias in joins 'on clause'' (#17) from bugfix/fix-multiple-level-join-table-alias into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #17
2023-05-02 18:06:33 +02:00
bence a17db2c79c use the correct table alias in joins 'on clause'
soko-web/pipeline/pr-master This commit looks good
2023-05-02 18:04:35 +02:00
bence fd286c9cff Merge pull request 'check session validity by DatabaseSessionHandler' (#16) from feature/sessions-should-expire into master
soko-web/pipeline/head This commit looks good
Reviewed-on: #16
2023-05-02 12:55:47 +02:00
bence 72fc78220f check session validity by DatabaseSessionHandler
soko-web/pipeline/pr-master This commit looks good
2023-05-02 12:37:31 +02:00
2 changed files with 13 additions and 7 deletions

No files matched your search

+4 -4
View File
@@ -150,7 +150,7 @@ class PersistentDataManager implements IPersistentDataManager
$columns = array_merge($columns, $this->getRelationColumns($table, $relations, $withRelations)); $columns = array_merge($columns, $this->getRelationColumns($table, $relations, $withRelations));
$this->leftJoinRelations($select, $table, $relations, $withRelations); $this->leftJoinRelations($select, $table, $table, $relations, $withRelations);
$select->columns($columns); $select->columns($columns);
} else { } else {
$select->columns($columns); $select->columns($columns);
@@ -180,19 +180,19 @@ class PersistentDataManager implements IPersistentDataManager
return $columns; return $columns;
} }
private function leftJoinRelations(Select $select, string $table, array $relations, array $withRelations): void private function leftJoinRelations(Select $select, string $table, string $tableAlias, array $relations, array $withRelations): void
{ {
foreach ($relations as $relation => $relationType) { foreach ($relations as $relation => $relationType) {
$relationTableAlias = $table . '__' . $relation; $relationTableAlias = $table . '__' . $relation;
$relationTable = call_user_func([$relationType, 'getTable']); $relationTable = call_user_func([$relationType, 'getTable']);
$select->setTableAliases([$relationTableAlias => $relationTable]); $select->setTableAliases([$relationTableAlias => $relationTable]);
$select->leftJoin($relationTableAlias, [$relationTableAlias, 'id'], '=', [$table, $relation . '_id']); $select->leftJoin($relationTableAlias, [$relationTableAlias, 'id'], '=', [$tableAlias, $relation . '_id']);
$relationsOfRelation = call_user_func([$relationType, 'getRelations']); $relationsOfRelation = call_user_func([$relationType, 'getRelations']);
if (count($withRelations)) { if (count($withRelations)) {
$relationsOfRelation = array_intersect_key($relationsOfRelation, array_flip($withRelations)); $relationsOfRelation = array_intersect_key($relationsOfRelation, array_flip($withRelations));
} }
$this->leftJoinRelations($select, $relationTable, $relationsOfRelation, $withRelations); $this->leftJoinRelations($select, $relationTable, $relationTableAlias, $relationsOfRelation, $withRelations);
} }
} }
+9 -3
View File
@@ -13,14 +13,17 @@ class DatabaseSessionHandler implements ISessionHandler
private string $table; private string $table;
private DateTime $shouldBeNewerThan;
private bool $exists = false; private bool $exists = false;
private bool $written = false; private bool $written = false;
public function __construct(IConnection $dbConnection, string $table) public function __construct(IConnection $dbConnection, string $table, DateTime $shouldBeNewerThan)
{ {
$this->dbConnection = $dbConnection; $this->dbConnection = $dbConnection;
$this->table = $table; $this->table = $table;
$this->shouldBeNewerThan = $shouldBeNewerThan;
} }
public function open($savePath, $sessionName): bool public function open($savePath, $sessionName): bool
@@ -36,17 +39,20 @@ class DatabaseSessionHandler implements ISessionHandler
public function read($id): string public function read($id): string
{ {
$select = new Select($this->dbConnection, $this->table); $select = new Select($this->dbConnection, $this->table);
$select->columns(['data']); $select->columns(['data', 'updated']);
$select->whereId(substr($id, 0, 32)); $select->whereId(substr($id, 0, 32));
$result = $select->execute()->fetch(IResultSet::FETCH_ASSOC); $result = $select->execute()->fetch(IResultSet::FETCH_ASSOC);
if ($result === null) { if ($result === null) {
return ''; return '';
} }
$this->exists = true; $this->exists = true;
if (new DateTime($result['updated']) < $this->shouldBeNewerThan) {
return '';
}
return $result['data']; return $result['data'];
} }