ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
InternalCAS_PGTStorageDb

Functions

 CAS_PGTStorage_Db::_getPdo ()
 This method returns the PDO object to use for database interactions. More...
 
 CAS_PGTStorage_Db::_getTable ()
 This method returns the table to use when storing/retrieving PGT's. More...
 
 CAS_PGTStorage_Db::getStorageType ()
 This method returns an informational string giving the type of storage used by the object (used for debugging purposes). More...
 
 CAS_PGTStorage_Db::getStorageInfo ()
 This method returns an informational string giving informations on the parameters of the storage. More...
 
 CAS_PGTStorage_Db::__construct ( $cas_parent, $dsn_or_pdo, $username='', $password='', $table='', $driver_options=null)
 The class constructor. More...
 
 CAS_PGTStorage_Db::init ()
 This method is used to initialize the storage. More...
 
 CAS_PGTStorage_Db::_setErrorMode ()
 This method will enable the Exception error mode on the PDO object. More...
 
 CAS_PGTStorage_Db::_resetErrorMode ()
 this method will reset the error mode on the PDO object More...
 
 CAS_PGTStorage_Db::createTableSql ()
 This method returns the query used to create a pgt storage table. More...
 
 CAS_PGTStorage_Db::storePgtSql ()
 This method returns the query used to store a pgt. More...
 
 CAS_PGTStorage_Db::retrievePgtSql ()
 This method returns the query used to retrieve a pgt. More...
 
 CAS_PGTStorage_Db::deletePgtSql ()
 This method returns the query used to delete a pgt. More...
 
 CAS_PGTStorage_Db::createTable ()
 This method creates the database table used to store pgt's and pgtiou's. More...
 
 CAS_PGTStorage_Db::write ($pgt, $pgt_iou)
 This method stores a PGT and its corresponding PGT Iou in the database. More...
 
 CAS_PGTStorage_Db::read ($pgt_iou)
 This method reads a PGT corresponding to a PGT Iou and deletes the corresponding db entry. More...
 

Variables

 CAS_PGTStorage_Db::$_pdo
 the PDO object to use for database interactions More...
 
 CAS_PGTStorage_Db::$_dsn
 database connection options to use when creating a new PDO object More...
 
 CAS_PGTStorage_Db::$_username
 
 CAS_PGTStorage_Db::$_password
 
 CAS_PGTStorage_Db::$_table_options
 
 CAS_PGTStorage_Db::$_table
 the table to use for storing/retrieving pgt's More...
 
 CAS_PGTStorage_Db::$_errMode
 attribute that stores the previous error mode for the PDO handle while processing a transaction More...
 

Detailed Description

Function Documentation

◆ __construct()

CAS_PGTStorage_Db::__construct (   $cas_parent,
  $dsn_or_pdo,
  $username = '',
  $password = '',
  $table = '',
  $driver_options = null 
)

The class constructor.

Parameters
CAS_Client$cas_parentthe CAS_Client instance that creates the object.
string$dsn_or_pdoa dsn string to use for creating a PDO object or a PDO object
string$usernamethe username to use when connecting to the database
string$passwordthe password to use when connecting to the database
string$tablethe table to use for storing and retrieving PGT's
string$driver_optionsany driver options to use when connecting to the database

Definition at line 138 of file Db.php.

References $password, $table, CAS_PGT_STORAGE_DB_DEFAULT_TABLE, phpCAS\traceBegin(), and phpCAS\traceEnd().

145  {
147  // call the ancestor's constructor
148  parent::__construct($cas_parent);
149 
150  // set default values
151  if (empty($table)) {
153  }
154  if (!is_array($driver_options)) {
155  $driver_options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
156  }
157 
158  // store the specified parameters
159  if ($dsn_or_pdo instanceof PDO) {
160  $this->_pdo = $dsn_or_pdo;
161  } else {
162  $this->_dsn = $dsn_or_pdo;
163  $this->_username = $username;
164  $this->_password = $password;
165  $this->_driver_options = $driver_options;
166  }
167 
168  // store the table name
169  $this->_table = $table;
170 
172  }
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:658
$password
Definition: cron.php:14
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
Definition: CAS.php:611
if(empty($password)) $table
Definition: pwgen.php:24
const CAS_PGT_STORAGE_DB_DEFAULT_TABLE
Definition: Db.php:30
+ Here is the call graph for this function:

◆ _getPdo()

CAS_PGTStorage_Db::_getPdo ( )
private

This method returns the PDO object to use for database interactions.

Returns
the PDO object

Definition at line 63 of file Db.php.

References CAS_PGTStorage_Db\$_pdo.

Referenced by CAS_PGTStorage_Db\_resetErrorMode(), CAS_PGTStorage_Db\_setErrorMode(), CAS_PGTStorage_Db\createTable(), CAS_PGTStorage_Db\read(), and CAS_PGTStorage_Db\write().

64  {
65  return $this->_pdo;
66  }
$_pdo
the PDO object to use for database interactions
Definition: Db.php:56
+ Here is the caller graph for this function:

◆ _getTable()

CAS_PGTStorage_Db::_getTable ( )
private

This method returns the table to use when storing/retrieving PGT's.

Returns
the name of the pgt storage table.

Definition at line 86 of file Db.php.

References CAS_PGTStorage_Db\$_table.

Referenced by CAS_PGTStorage_Db\createTableSql(), CAS_PGTStorage_Db\deletePgtSql(), CAS_PGTStorage_Db\getStorageInfo(), CAS_PGTStorage_Db\retrievePgtSql(), and CAS_PGTStorage_Db\storePgtSql().

87  {
88  return $this->_table;
89  }
$_table
the table to use for storing/retrieving pgt's
Definition: Db.php:79
+ Here is the caller graph for this function:

◆ _resetErrorMode()

CAS_PGTStorage_Db::_resetErrorMode ( )
private

this method will reset the error mode on the PDO object

Returns
void

Definition at line 239 of file Db.php.

References $pdo, and CAS_PGTStorage_Db\_getPdo().

Referenced by CAS_PGTStorage_Db\createTable(), CAS_PGTStorage_Db\read(), and CAS_PGTStorage_Db\write().

240  {
241  // get PDO object and reset the error mode to what it was originally
242  $pdo = $this->_getPdo();
243  $pdo->setAttribute(PDO::ATTR_ERRMODE, $this->_errMode);
244  }
_getPdo()
This method returns the PDO object to use for database interactions.
Definition: Db.php:63
$pdo
Definition: migrateto20.php:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _setErrorMode()

CAS_PGTStorage_Db::_setErrorMode ( )
private

This method will enable the Exception error mode on the PDO object.

Returns
void

Definition at line 226 of file Db.php.

References $pdo, and CAS_PGTStorage_Db\_getPdo().

Referenced by CAS_PGTStorage_Db\createTable(), CAS_PGTStorage_Db\read(), and CAS_PGTStorage_Db\write().

227  {
228  // get PDO object and enable exception error mode
229  $pdo = $this->_getPdo();
230  $this->_errMode = $pdo->getAttribute(PDO::ATTR_ERRMODE);
231  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
232  }
_getPdo()
This method returns the PDO object to use for database interactions.
Definition: Db.php:63
$pdo
Definition: migrateto20.php:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createTable()

CAS_PGTStorage_Db::createTable ( )

This method creates the database table used to store pgt's and pgtiou's.

Returns
void

Definition at line 308 of file Db.php.

References $pdo, $query, CAS_PGTStorage_Db\_getPdo(), CAS_PGTStorage_Db\_resetErrorMode(), CAS_PGTStorage_Db\_setErrorMode(), phpCAS\error(), CAS_PGTStorage_Db\init(), CAS_PGTStorage_AbstractStorage\isInitialized(), phpCAS\traceBegin(), and phpCAS\traceEnd().

309  {
311 
312  // initialize this PGTStorage object if it hasn't been initialized yet
313  if (!$this->isInitialized()) {
314  $this->init();
315  }
316 
317  // initialize the PDO object for this method
318  $pdo = $this->_getPdo();
319  $this->_setErrorMode();
320 
321  try {
322  $pdo->beginTransaction();
323 
324  $query = $pdo->query($this->createTableSQL());
325  $query->closeCursor();
326 
327  $pdo->commit();
328  } catch (PDOException $e) {
329  // attempt rolling back the transaction before throwing a phpCAS error
330  try {
331  $pdo->rollBack();
332  } catch (PDOException $e) {
333  }
334  phpCAS::error('error creating PGT storage table: ' . $e->getMessage());
335  }
336 
337  // reset the PDO object
338  $this->_resetErrorMode();
339 
341  }
_setErrorMode()
This method will enable the Exception error mode on the PDO object.
Definition: Db.php:226
_resetErrorMode()
this method will reset the error mode on the PDO object
Definition: Db.php:239
static error($msg)
This method is used by interface methods to print an error and where the function was originally call...
Definition: CAS.php:563
init()
This method is used to initialize the storage.
Definition: Db.php:183
isInitialized()
This method tells if the storage has already been intialized.
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:658
$query
_getPdo()
This method returns the PDO object to use for database interactions.
Definition: Db.php:63
$pdo
Definition: migrateto20.php:62
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
Definition: CAS.php:611
+ Here is the call graph for this function:

◆ createTableSql()

CAS_PGTStorage_Db::createTableSql ( )
protected

This method returns the query used to create a pgt storage table.

Returns
the create table SQL, no bind params in query

Definition at line 258 of file Db.php.

References CAS_PGTStorage_Db\_getTable().

259  {
260  return 'CREATE TABLE ' . $this->_getTable()
261  . ' (pgt_iou VARCHAR(255) NOT NULL PRIMARY KEY, pgt VARCHAR(255) NOT NULL)';
262  }
_getTable()
This method returns the table to use when storing/retrieving PGT's.
Definition: Db.php:86
+ Here is the call graph for this function:

◆ deletePgtSql()

CAS_PGTStorage_Db::deletePgtSql ( )
protected

This method returns the query used to delete a pgt.

Returns
the delete PGT SQL, :pgt_iou is the only bind param contained in the query

Definition at line 294 of file Db.php.

References CAS_PGTStorage_Db\_getTable().

Referenced by CAS_PGTStorage_Db\read().

295  {
296  return 'DELETE FROM ' . $this->_getTable() . ' WHERE pgt_iou = :pgt_iou';
297  }
_getTable()
This method returns the table to use when storing/retrieving PGT's.
Definition: Db.php:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStorageInfo()

CAS_PGTStorage_Db::getStorageInfo ( )

This method returns an informational string giving informations on the parameters of the storage.

(used for debugging purposes).

Returns
an informational string.

Definition at line 113 of file Db.php.

References CAS_PGTStorage_Db\_getTable().

114  {
115  return 'table=`' . $this->_getTable() . '\'';
116  }
_getTable()
This method returns the table to use when storing/retrieving PGT's.
Definition: Db.php:86
+ Here is the call graph for this function:

◆ getStorageType()

CAS_PGTStorage_Db::getStorageType ( )

This method returns an informational string giving the type of storage used by the object (used for debugging purposes).

Returns
an informational string.

Definition at line 101 of file Db.php.

102  {
103  return "db";
104  }

◆ init()

CAS_PGTStorage_Db::init ( )

This method is used to initialize the storage.

Halts on error.

Returns
void

Definition at line 183 of file Db.php.

References phpCAS\error(), init(), CAS_PGTStorage_AbstractStorage\isInitialized(), phpCAS\traceBegin(), and phpCAS\traceEnd().

Referenced by CAS_PGTStorage_Db\createTable().

184  {
186  // if the storage has already been initialized, return immediatly
187  if ($this->isInitialized()) {
188  return;
189  }
190 
191  // initialize the base object
192  parent::init();
193 
194  // create the PDO object if it doesn't exist already
195  if (!($this->_pdo instanceof PDO)) {
196  try {
197  $this->_pdo = new PDO(
198  $this->_dsn,
199  $this->_username,
200  $this->_password,
201  $this->_driver_options
202  );
203  } catch (PDOException $e) {
204  phpCAS::error('Database connection error: ' . $e->getMessage());
205  }
206  }
207 
209  }
static error($msg)
This method is used by interface methods to print an error and where the function was originally call...
Definition: CAS.php:563
isInitialized()
This method tells if the storage has already been intialized.
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:658
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
Definition: CAS.php:611
while(count($oldTaskList) > 0) foreach(array_keys($newTaskList) as $task) init()
Definition: build.php:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

CAS_PGTStorage_Db::read (   $pgt_iou)

This method reads a PGT corresponding to a PGT Iou and deletes the corresponding db entry.

Parameters
string$pgt_iouthe PGT iou
Returns
the corresponding PGT, or FALSE on error

Definition at line 393 of file Db.php.

References $pdo, $query, CAS_PGTStorage_Db\_getPdo(), CAS_PGTStorage_Db\_resetErrorMode(), CAS_PGTStorage_Db\_setErrorMode(), CAS_PGTStorage_Db\deletePgtSql(), CAS_PGTStorage_Db\retrievePgtSql(), phpCAS\trace(), phpCAS\traceBegin(), and phpCAS\traceEnd().

394  {
396  $pgt = false;
397 
398  // initialize the PDO object for this method
399  $pdo = $this->_getPdo();
400  $this->_setErrorMode();
401 
402  try {
403  $pdo->beginTransaction();
404 
405  // fetch the pgt for the specified pgt_iou
406  $query = $pdo->prepare($this->retrievePgtSql());
407  $query->bindValue(':pgt_iou', $pgt_iou, PDO::PARAM_STR);
408  $query->execute();
409  $pgt = $query->fetchColumn(0);
410  $query->closeCursor();
411 
412  // delete the specified pgt_iou from the database
413  $query = $pdo->prepare($this->deletePgtSql());
414  $query->bindValue(':pgt_iou', $pgt_iou, PDO::PARAM_STR);
415  $query->execute();
416  $query->closeCursor();
417 
418  $pdo->commit();
419  } catch (PDOException $e) {
420  // attempt rolling back the transaction before throwing a phpCAS error
421  try {
422  $pdo->rollBack();
423  } catch (PDOException $e) {
424  }
425  phpCAS::trace('error reading PGT from database: ' . $e->getMessage());
426  }
427 
428  // reset the PDO object
429  $this->_resetErrorMode();
430 
432  return $pgt;
433  }
_setErrorMode()
This method will enable the Exception error mode on the PDO object.
Definition: Db.php:226
_resetErrorMode()
this method will reset the error mode on the PDO object
Definition: Db.php:239
retrievePgtSql()
This method returns the query used to retrieve a pgt.
Definition: Db.php:283
deletePgtSql()
This method returns the query used to delete a pgt.
Definition: Db.php:294
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:658
static trace($str)
This method is used to log something in debug mode.
Definition: CAS.php:599
$query
_getPdo()
This method returns the PDO object to use for database interactions.
Definition: Db.php:63
$pdo
Definition: migrateto20.php:62
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
Definition: CAS.php:611
+ Here is the call graph for this function:

◆ retrievePgtSql()

CAS_PGTStorage_Db::retrievePgtSql ( )
protected

This method returns the query used to retrieve a pgt.

the first column of the first row should contain the pgt

Returns
the retrieve PGT SQL, :pgt_iou is the only bind param contained in the query

Definition at line 283 of file Db.php.

References CAS_PGTStorage_Db\_getTable().

Referenced by CAS_PGTStorage_Db\read().

284  {
285  return 'SELECT pgt FROM ' . $this->_getTable() . ' WHERE pgt_iou = :pgt_iou';
286  }
_getTable()
This method returns the table to use when storing/retrieving PGT's.
Definition: Db.php:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ storePgtSql()

CAS_PGTStorage_Db::storePgtSql ( )
protected

This method returns the query used to store a pgt.

Returns
the store PGT SQL, :pgt and :pgt_iou are the bind params contained in the query

Definition at line 270 of file Db.php.

References CAS_PGTStorage_Db\_getTable().

Referenced by CAS_PGTStorage_Db\write().

271  {
272  return 'INSERT INTO ' . $this->_getTable()
273  . ' (pgt_iou, pgt) VALUES (:pgt_iou, :pgt)';
274  }
_getTable()
This method returns the table to use when storing/retrieving PGT's.
Definition: Db.php:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write()

CAS_PGTStorage_Db::write (   $pgt,
  $pgt_iou 
)

This method stores a PGT and its corresponding PGT Iou in the database.

Echoes a warning on error.

Parameters
string$pgtthe PGT
string$pgt_iouthe PGT iou
Returns
void

Definition at line 352 of file Db.php.

References $pdo, $query, CAS_PGTStorage_Db\_getPdo(), CAS_PGTStorage_Db\_resetErrorMode(), CAS_PGTStorage_Db\_setErrorMode(), phpCAS\error(), CAS_PGTStorage_Db\storePgtSql(), phpCAS\traceBegin(), and phpCAS\traceEnd().

353  {
355 
356  // initialize the PDO object for this method
357  $pdo = $this->_getPdo();
358  $this->_setErrorMode();
359 
360  try {
361  $pdo->beginTransaction();
362 
363  $query = $pdo->prepare($this->storePgtSql());
364  $query->bindValue(':pgt', $pgt, PDO::PARAM_STR);
365  $query->bindValue(':pgt_iou', $pgt_iou, PDO::PARAM_STR);
366  $query->execute();
367  $query->closeCursor();
368 
369  $pdo->commit();
370  } catch (PDOException $e) {
371  // attempt rolling back the transaction before throwing a phpCAS error
372  try {
373  $pdo->rollBack();
374  } catch (PDOException $e) {
375  }
376  phpCAS::error('error writing PGT to database: ' . $e->getMessage());
377  }
378 
379  // reset the PDO object
380  $this->_resetErrorMode();
381 
383  }
_setErrorMode()
This method will enable the Exception error mode on the PDO object.
Definition: Db.php:226
_resetErrorMode()
this method will reset the error mode on the PDO object
Definition: Db.php:239
static error($msg)
This method is used by interface methods to print an error and where the function was originally call...
Definition: CAS.php:563
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:658
storePgtSql()
This method returns the query used to store a pgt.
Definition: Db.php:270
$query
_getPdo()
This method returns the PDO object to use for database interactions.
Definition: Db.php:63
$pdo
Definition: migrateto20.php:62
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
Definition: CAS.php:611
+ Here is the call graph for this function:

Variable Documentation

◆ $_dsn

CAS_PGTStorage_Db::$_dsn
private

database connection options to use when creating a new PDO object

Definition at line 71 of file Db.php.

◆ $_errMode

CAS_PGTStorage_Db::$_errMode
private

attribute that stores the previous error mode for the PDO handle while processing a transaction

Definition at line 219 of file Db.php.

◆ $_password

CAS_PGTStorage_Db::$_password
private

Definition at line 73 of file Db.php.

◆ $_pdo

CAS_PGTStorage_Db::$_pdo
private

the PDO object to use for database interactions

Definition at line 56 of file Db.php.

Referenced by CAS_PGTStorage_Db\_getPdo().

◆ $_table

CAS_PGTStorage_Db::$_table
private

the table to use for storing/retrieving pgt's

Definition at line 79 of file Db.php.

Referenced by CAS_PGTStorage_Db\_getTable().

◆ $_table_options

CAS_PGTStorage_Db::$_table_options
private

Definition at line 74 of file Db.php.

◆ $_username

CAS_PGTStorage_Db::$_username
private

Definition at line 72 of file Db.php.