ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilSessionIStorage Class Reference

Session based immediate storage. More...

+ Collaboration diagram for ilSessionIStorage:

Public Member Functions

 __construct (string $a_component_id, string $a_sess_id="")
 Constructor. More...
 
 set (string $a_key, string $a_val)
 Set a value. More...
 
 get (string $a_key)
 

Static Public Member Functions

static destroySession ($a_session_id)
 Destroy session(s). More...
 

Private Member Functions

 initComponentCacheIfNotExists ()
 

Private Attributes

string $session_id = ""
 
string $component_id
 

Static Private Attributes

static array $values = []
 

Detailed Description

Session based immediate storage.

This class stores session based user data in the database. The difference to ilSession is that data is written immediately when the set() function is called and that this data is written "per key".

Please note that the values are limited to TEXT(1000)!

This class is needed for cases, where ajax calls should write session based data.

Since more concurrent ajax calls can be initiated by a page request, these calls may run into race conditions, if ilSession is used, since it always reads all key/value pairs at the beginning of a request and writes all of them at the end. Similar issues can appear if a page initiates additional requests by (i)frames.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e

Definition at line 41 of file class.ilSessionIStorage.php.

Constructor & Destructor Documentation

◆ __construct()

ilSessionIStorage::__construct ( string  $a_component_id,
string  $a_sess_id = "" 
)

Constructor.

Parameters
string$a_component_idcomponent id (e.g. "crs", "lm", ...)
string$a_sess_idsession id

Definition at line 53 of file class.ilSessionIStorage.php.

54  {
55  $this->component_id = $a_component_id;
56  if ($a_sess_id !== "") {
57  $this->session_id = $a_sess_id;
58  } else {
59  $this->session_id = session_id();
60  }
61  }

Member Function Documentation

◆ destroySession()

static ilSessionIStorage::destroySession (   $a_session_id)
static

Destroy session(s).

This is called by ilSession->destroy

Parameters
$a_session_idstring|array ids of sessions to be deleted

Definition at line 129 of file class.ilSessionIStorage.php.

References $DIC, and $q.

Referenced by ilSession\_destroy().

129  : void
130  {
131  global $DIC;
132 
133  if (!is_array($a_session_id)) {
134  $q = "DELETE FROM usr_sess_istorage WHERE session_id = " .
135  $DIC->database()->quote($a_session_id, "text");
136  } else {
137  $q = "DELETE FROM usr_sess_istorage WHERE " .
138  $DIC->database()->in("session_id", $a_session_id, false, "text");
139  }
140 
141  $DIC->database()->manipulate($q);
142  }
global $DIC
Definition: shib_login.php:22
$q
Definition: shib_logout.php:21
+ Here is the caller graph for this function:

◆ get()

ilSessionIStorage::get ( string  $a_key)
Parameters
string$a_key
Returns
string

Definition at line 99 of file class.ilSessionIStorage.php.

References $component_id, $DIC, $ilDB, and initComponentCacheIfNotExists().

99  : string
100  {
101  global $DIC;
102 
103  $ilDB = $DIC['ilDB'];
104 
105  if (isset(self::$values[$this->component_id][$a_key]) && is_array(self::$values[$this->component_id])) {
106  return self::$values[$this->component_id][$a_key];
107  }
108 
109  $set = $ilDB->query(
110  "SELECT value FROM usr_sess_istorage " .
111  " WHERE session_id = " . $ilDB->quote($this->session_id, "text") .
112  " AND component_id = " . $ilDB->quote($this->component_id, "text") .
113  " AND vkey = " . $ilDB->quote($a_key, "text")
114  );
115  $rec = $ilDB->fetchAssoc($set);
116  $value = (string) ($rec['value'] ?? '');
117 
119 
120  self::$values[$this->component_id][$a_key] = $value;
121 
122  return $value;
123  }
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

◆ initComponentCacheIfNotExists()

ilSessionIStorage::initComponentCacheIfNotExists ( )
private

Definition at line 63 of file class.ilSessionIStorage.php.

References $component_id.

Referenced by get(), and set().

63  : void
64  {
65  if (!isset(self::$values[$this->component_id]) || !is_array(self::$values[$this->component_id])) {
66  self::$values[$this->component_id] = [];
67  }
68  }
+ Here is the caller graph for this function:

◆ set()

ilSessionIStorage::set ( string  $a_key,
string  $a_val 
)

Set a value.

Parameters
string$a_valvalue

Definition at line 75 of file class.ilSessionIStorage.php.

References $component_id, $DIC, $ilDB, and initComponentCacheIfNotExists().

75  : void
76  {
77  global $DIC;
78 
79  $ilDB = $DIC['ilDB'];
80 
82 
83  self::$values[$this->component_id][$a_key] = $a_val;
84  $ilDB->replace(
85  "usr_sess_istorage",
86  array(
87  "session_id" => array("text", $this->session_id),
88  "component_id" => array("text", $this->component_id),
89  "vkey" => array("text", $a_key)
90  ),
91  array("value" => array("text", $a_val))
92  );
93  }
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Field Documentation

◆ $component_id

string ilSessionIStorage::$component_id
private

Definition at line 44 of file class.ilSessionIStorage.php.

Referenced by get(), initComponentCacheIfNotExists(), and set().

◆ $session_id

string ilSessionIStorage::$session_id = ""
private

Definition at line 43 of file class.ilSessionIStorage.php.

◆ $values

array ilSessionIStorage::$values = []
staticprivate

Definition at line 45 of file class.ilSessionIStorage.php.


The documentation for this class was generated from the following file: