HEX
Server: Apache
System: Linux server1.ariadata.co 4.18.0-553.120.1.el8_10.x86_64 #1 SMP Mon Apr 20 18:04:27 EDT 2026 x86_64
User: nepi (1051)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,show_source,popen,proc_open
Upload Files
File: /home/nepi/public_html/src/core/Directus/Database/TableGateway/DirectusUserSessionsTableGateway.php
<?php

namespace Directus\Database\TableGateway;

use Directus\Permissions\Acl;
use Directus\Util\DateTimeUtils;
use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\Sql\Insert;
use Zend\Db\Sql\Update;
use Zend\Db\Sql\Select;

class DirectusUserSessionsTableGateway extends RelationalTableGateway
{
    const TOKEN_COOKIE = 'cookie';
    const TOKEN_JWT = 'jwt';

    public static $_tableName = 'directus_user_sessions';

    public $primaryKeyFieldName = 'id';

    /**
     * DirectusUserSessionTableGateway constructor.
     *
     * @param AdapterInterface $adapter
     * @param Acl $acl
     */
    public function __construct(AdapterInterface $adapter, $acl = null)
    {
        parent::__construct(self::$_tableName, $adapter, $acl);
    }

    public function recordSession($data)
    {
        $sessionData = [
            'user' => $data['user'],
            'token' => $data['token'],
            'token_type' => $data['token_type'],
            'token_expired_at' => $data['token_expired_at'],
            'created_on' => DateTimeUtils::now()->toString(),
            'ip_address' => \Directus\get_request_ip(),
            'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''
        ];
        
        $insert = new Insert($this->getTable());
        $insert
            ->values($sessionData);

        $this->insertWith($insert);
        return $this->getLastInsertValue();
    }

    public function updateSession($id,$data)
    {
        $update = new Update($this->getTable());
        $update->set($data);
        $update->where([
            'id' => $id
        ]);
        $this->updateWith($update);
    }

    public function fetchSession($condition)
    {
        $select = new Select($this->getTable());
        $select->columns(['*']);
        $select->where($condition);
        $select->limit(1);
        return $this->selectWith($select)->current();
    }

}