dblayer/authorizationdb : tableprefix is updated
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1595 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -15,6 +15,8 @@ class authorizationdb extends authorization
|
|||||||
private $separator = "/";
|
private $separator = "/";
|
||||||
/** Database PDO connector */
|
/** Database PDO connector */
|
||||||
private $db = null;
|
private $db = null;
|
||||||
|
/** The prefix for the table */
|
||||||
|
public $tableprefix = "";
|
||||||
|
|
||||||
/** Establish a connexion to the authorization database
|
/** Establish a connexion to the authorization database
|
||||||
@param string $dsn The DSN needed to connect to database
|
@param string $dsn The DSN needed to connect to database
|
||||||
@@ -28,6 +30,7 @@ class authorizationdb extends authorization
|
|||||||
// Define the structure of the table in the database
|
// Define the structure of the table in the database
|
||||||
$this->db = new dblayer ($dsn, $username, $password, $driver_options);
|
$this->db = new dblayer ($dsn, $username, $password, $driver_options);
|
||||||
$this->db->table = "domframework_authorization";
|
$this->db->table = "domframework_authorization";
|
||||||
|
$this->db->tableprefix = $this->tableprefix;
|
||||||
$this->db->fields = array (
|
$this->db->fields = array (
|
||||||
"object"=>array ("varchar", "255", "not null"),
|
"object"=>array ("varchar", "255", "not null"),
|
||||||
"ownerid"=>array ("integer", "not null"),
|
"ownerid"=>array ("integer", "not null"),
|
||||||
@@ -43,7 +46,7 @@ class authorizationdb extends authorization
|
|||||||
if ($this->db === null)
|
if ($this->db === null)
|
||||||
throw new Exception (_("Database to authorize is not connected"), 500);
|
throw new Exception (_("Database to authorize is not connected"), 500);
|
||||||
$tables = $this->db->listTables ();
|
$tables = $this->db->listTables ();
|
||||||
if (!in_array ($this->db->table, $tables))
|
if (!in_array ($this->db->tableprefix.$this->db->table, $tables))
|
||||||
{
|
{
|
||||||
$this->db->createTable ();
|
$this->db->createTable ();
|
||||||
$first = array ("object"=>"/", "ownerid"=>0, "groupid"=>0,
|
$first = array ("object"=>"/", "ownerid"=>0, "groupid"=>0,
|
||||||
|
|||||||
27
dblayer.php
27
dblayer.php
@@ -35,9 +35,9 @@ class dblayer extends PDO
|
|||||||
{
|
{
|
||||||
/** The table name to use */
|
/** The table name to use */
|
||||||
public $table = null;
|
public $table = null;
|
||||||
/** The prefix text to prepend to table name (Should finish by _)
|
/** The tableprefix text to prepend to table name (Should finish by _)
|
||||||
Just allow chars ! */
|
Just allow chars ! */
|
||||||
public $prefix = "";
|
public $tableprefix = "";
|
||||||
/** The fields with the definition of type, and special parameters */
|
/** The fields with the definition of type, and special parameters */
|
||||||
public $fields = array ();
|
public $fields = array ();
|
||||||
/** The primary field */
|
/** The primary field */
|
||||||
@@ -166,7 +166,8 @@ class dblayer extends PDO
|
|||||||
if (file_exists ($file) && ! is_writeable ($file))
|
if (file_exists ($file) && ! is_writeable ($file))
|
||||||
throw new Exception (_("The SQLite database file is write protected"),
|
throw new Exception (_("The SQLite database file is write protected"),
|
||||||
500);
|
500);
|
||||||
if (function_exists ("posix_getuid") && fileowner ($file) === posix_getuid ())
|
if (function_exists ("posix_getuid") &&
|
||||||
|
fileowner ($file) === posix_getuid ())
|
||||||
chmod ($file, 0666);
|
chmod ($file, 0666);
|
||||||
// Force ForeignKeys support (disabled by default)
|
// Force ForeignKeys support (disabled by default)
|
||||||
$this->db->exec("PRAGMA foreign_keys = ON");
|
$this->db->exec("PRAGMA foreign_keys = ON");
|
||||||
@@ -255,7 +256,8 @@ class dblayer extends PDO
|
|||||||
{
|
{
|
||||||
$table = $data[0];
|
$table = $data[0];
|
||||||
$column = $data[1];
|
$column = $data[1];
|
||||||
$req = "SELECT $column FROM `$this->prefix$table` WHERE $column=:$column";
|
$req = "SELECT $column FROM `$this->tableprefix$table` ".
|
||||||
|
"WHERE $column=:$column";
|
||||||
if ($this->debug) echo "DEBUG : $req\n";
|
if ($this->debug) echo "DEBUG : $req\n";
|
||||||
$st = $this->db->prepare ($req);
|
$st = $this->db->prepare ($req);
|
||||||
$val = $datasOK[$foreign];
|
$val = $datasOK[$foreign];
|
||||||
@@ -281,7 +283,7 @@ class dblayer extends PDO
|
|||||||
$column), 405);
|
$column), 405);
|
||||||
}
|
}
|
||||||
|
|
||||||
$req = "INSERT INTO `$this->prefix$this->table` ";
|
$req = "INSERT INTO `$this->tableprefix$this->table` ";
|
||||||
$req .= "(".implode (",", array_keys ($datasOK)).")";
|
$req .= "(".implode (",", array_keys ($datasOK)).")";
|
||||||
$req .= " VALUES ";
|
$req .= " VALUES ";
|
||||||
$req .= "(:".implode (",:", array_keys ($datasOK)).")";
|
$req .= "(:".implode (",:", array_keys ($datasOK)).")";
|
||||||
@@ -344,7 +346,7 @@ class dblayer extends PDO
|
|||||||
|
|
||||||
$req = "SELECT ";
|
$req = "SELECT ";
|
||||||
$req .= implode (",", $display);
|
$req .= implode (",", $display);
|
||||||
$req .= " FROM `$this->prefix$this->table`";
|
$req .= " FROM `$this->tableprefix$this->table`";
|
||||||
if ($select !== null)
|
if ($select !== null)
|
||||||
{
|
{
|
||||||
$req .= " WHERE ";
|
$req .= " WHERE ";
|
||||||
@@ -477,7 +479,8 @@ class dblayer extends PDO
|
|||||||
{
|
{
|
||||||
$table = $data[0];
|
$table = $data[0];
|
||||||
$column = $data[1];
|
$column = $data[1];
|
||||||
$req = "SELECT $column FROM `$this->prefix$table` WHERE $column=:$column";
|
$req = "SELECT $column FROM `$this->tableprefix$table` ".
|
||||||
|
"WHERE $column=:$column";
|
||||||
if ($this->debug) echo "DEBUG : $req\n";
|
if ($this->debug) echo "DEBUG : $req\n";
|
||||||
$st = $this->db->prepare ($req);
|
$st = $this->db->prepare ($req);
|
||||||
$val = $datasOK[$foreign];
|
$val = $datasOK[$foreign];
|
||||||
@@ -504,7 +507,7 @@ class dblayer extends PDO
|
|||||||
}
|
}
|
||||||
|
|
||||||
$datasOK[$this->primary] = $updatekey;
|
$datasOK[$this->primary] = $updatekey;
|
||||||
$req = "UPDATE `".$this->prefix."$this->table` SET ";
|
$req = "UPDATE `".$this->tableprefix."$this->table` SET ";
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($datasOK as $key=>$val)
|
foreach ($datasOK as $key=>$val)
|
||||||
{
|
{
|
||||||
@@ -557,7 +560,7 @@ class dblayer extends PDO
|
|||||||
{
|
{
|
||||||
if ($this->db === null)
|
if ($this->db === null)
|
||||||
throw new Exception ("Database not connected");
|
throw new Exception ("Database not connected");
|
||||||
$req = "DELETE FROM `$this->prefix$this->table` ";
|
$req = "DELETE FROM `$this->tableprefix$this->table` ";
|
||||||
$req .= "WHERE $this->primary = :primary";
|
$req .= "WHERE $this->primary = :primary";
|
||||||
$st = $this->db->prepare ($req);
|
$st = $this->db->prepare ($req);
|
||||||
if ($this->debug) echo "DEBUG : $req\n";
|
if ($this->debug) echo "DEBUG : $req\n";
|
||||||
@@ -600,7 +603,7 @@ class dblayer extends PDO
|
|||||||
switch ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME))
|
switch ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME))
|
||||||
{
|
{
|
||||||
case "sqlite":
|
case "sqlite":
|
||||||
$sql = "CREATE TABLE `$this->prefix$this->table` (\n";
|
$sql = "CREATE TABLE `$this->tableprefix$this->table` (\n";
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($this->fields as $field=>$params)
|
foreach ($this->fields as $field=>$params)
|
||||||
{
|
{
|
||||||
@@ -681,7 +684,7 @@ class dblayer extends PDO
|
|||||||
$sql .=")";
|
$sql .=")";
|
||||||
break;
|
break;
|
||||||
case "mysql":
|
case "mysql":
|
||||||
$sql = "CREATE TABLE `$this->prefix$this->table` (\n";
|
$sql = "CREATE TABLE `$this->tableprefix$this->table` (\n";
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($this->fields as $field=>$params)
|
foreach ($this->fields as $field=>$params)
|
||||||
{
|
{
|
||||||
@@ -760,7 +763,7 @@ class dblayer extends PDO
|
|||||||
$sql .=") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
$sql .=") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||||
break;
|
break;
|
||||||
case "pgsql":
|
case "pgsql":
|
||||||
$sql = "CREATE TABLE \"$this->prefix$this->table\" (\n";
|
$sql = "CREATE TABLE \"$this->tableprefix$this->table\" (\n";
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($this->fields as $field=>$params)
|
foreach ($this->fields as $field=>$params)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user