routeSQL : Add the Chain support to REST support
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2041 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
108
routeSQL.php
108
routeSQL.php
@@ -292,6 +292,24 @@ class routeSQL
|
|||||||
"(\?({p1}=({v1})?)(&{p2}=({v2})?(&{p3}=({v3})?)?)?)?",
|
"(\?({p1}=({v1})?)(&{p2}=({v2})?(&{p3}=({v3})?)?)?)?",
|
||||||
function ($extension, $p1, $v1, $p2, $v2, $p3, $v3, $chain)
|
function ($extension, $p1, $v1, $p2, $v2, $p3, $v3, $chain)
|
||||||
{
|
{
|
||||||
|
if ($this->chained !== null)
|
||||||
|
{
|
||||||
|
if ($this->chained->accessright ($this->authREST["email"], $chain) !==
|
||||||
|
TRUE)
|
||||||
|
{
|
||||||
|
if ($this->authREST["email"] === "anonymous")
|
||||||
|
throw new Exception (dgettext("domframework",
|
||||||
|
"Anonymous not allowed"), 401);
|
||||||
|
throw new Exception (dgettext("domframework",
|
||||||
|
"Access forbidden"), 403);
|
||||||
|
}
|
||||||
|
$this->chained->connect();
|
||||||
|
// $chainedValues are the informations associated to the $chain
|
||||||
|
$chainedValues = $this->chained->keyexists ($chain);
|
||||||
|
if ($chainedValues === false)
|
||||||
|
throw new Exception (dgettext("domframework",
|
||||||
|
"Object not found"), 404);
|
||||||
|
}
|
||||||
if ($this->accessright ($this->authREST["email"]) !== TRUE)
|
if ($this->accessright ($this->authREST["email"]) !== TRUE)
|
||||||
{
|
{
|
||||||
if ($this->authREST["email"] === "anonymous")
|
if ($this->authREST["email"] === "anonymous")
|
||||||
@@ -344,8 +362,26 @@ class routeSQL
|
|||||||
});
|
});
|
||||||
|
|
||||||
$route->post ("rest/".$this->url_prefix."(\.{extension})?",
|
$route->post ("rest/".$this->url_prefix."(\.{extension})?",
|
||||||
function ($extension)
|
function ($extension, $chain)
|
||||||
{
|
{
|
||||||
|
if ($this->chained !== null)
|
||||||
|
{
|
||||||
|
if ($this->chained->editright ($this->authREST["email"], $chain) !==
|
||||||
|
TRUE)
|
||||||
|
{
|
||||||
|
if ($this->authREST["email"] === "anonymous")
|
||||||
|
throw new Exception (dgettext("domframework",
|
||||||
|
"Anonymous not allowed"), 401);
|
||||||
|
throw new Exception (dgettext("domframework","Access forbidden"),
|
||||||
|
403);
|
||||||
|
}
|
||||||
|
$this->chained->connect();
|
||||||
|
// $chainedvalues are the informations associated to the $chain
|
||||||
|
$chainedvalues = $this->chained->keyexists ($chain);
|
||||||
|
if ($chainedvalues === false)
|
||||||
|
throw new exception (dgettext("domframework",
|
||||||
|
"Object not found"), 404);
|
||||||
|
}
|
||||||
if ($this->accessright ($this->authREST["email"]) !== TRUE)
|
if ($this->accessright ($this->authREST["email"]) !== TRUE)
|
||||||
{
|
{
|
||||||
if ($this->authREST["email"] === "anonymous")
|
if ($this->authREST["email"] === "anonymous")
|
||||||
@@ -369,9 +405,19 @@ class routeSQL
|
|||||||
403);
|
403);
|
||||||
$this->connect();
|
$this->connect();
|
||||||
$values = $_POST;
|
$values = $_POST;
|
||||||
|
$errorsChain = array ();
|
||||||
|
if ($this->chainedForeign !== null &&
|
||||||
|
isset ($values[$this->chainedForeign]) &&
|
||||||
|
$values[$this->chainedForeign] !== $chain)
|
||||||
|
$errorsChain[$this->chainedForeign] =
|
||||||
|
array ("error", dgettext("domframework",
|
||||||
|
"Can not change the external key"));
|
||||||
|
if ($this->chainedForeign !== null)
|
||||||
|
$values[$this->chainedForeign] = $chain;
|
||||||
$errors = $this->objectDB->verify ($values);
|
$errors = $this->objectDB->verify ($values);
|
||||||
if (count ($errors) > 0)
|
if (count ($errors) > 0 || count ($errorsChain) > 0)
|
||||||
$this->renderrest ($extension, $errors, 400);
|
$this->renderrest ($extension, array_merge ($errors, $errorsChain),
|
||||||
|
400);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->objectDB->insert ($values);
|
$this->objectDB->insert ($values);
|
||||||
@@ -384,8 +430,26 @@ class routeSQL
|
|||||||
});
|
});
|
||||||
|
|
||||||
$route->put ("rest/".$this->url_prefix."(\.{extension})?/{id}",
|
$route->put ("rest/".$this->url_prefix."(\.{extension})?/{id}",
|
||||||
function ($extension, $id)
|
function ($extension, $id, $chain)
|
||||||
{
|
{
|
||||||
|
if ($this->chained !== null)
|
||||||
|
{
|
||||||
|
if ($this->chained->editright ($this->authREST["email"], $chain) !==
|
||||||
|
TRUE)
|
||||||
|
{
|
||||||
|
if ($this->authREST["email"] === "anonymous")
|
||||||
|
throw new Exception (dgettext("domframework",
|
||||||
|
"Anonymous not allowed"), 401);
|
||||||
|
throw new Exception (dgettext("domframework","Access forbidden"),
|
||||||
|
403);
|
||||||
|
}
|
||||||
|
$this->chained->connect();
|
||||||
|
// $chainedvalues are the informations associated to the $chain
|
||||||
|
$chainedvalues = $this->chained->keyexists ($chain);
|
||||||
|
if ($chainedvalues === false)
|
||||||
|
throw new exception (dgettext("domframework",
|
||||||
|
"Object not found"), 404);
|
||||||
|
}
|
||||||
if ($this->accessright ($this->authREST["email"]) !== TRUE)
|
if ($this->accessright ($this->authREST["email"]) !== TRUE)
|
||||||
{
|
{
|
||||||
if ($this->authREST["email"] === "anonymous")
|
if ($this->authREST["email"] === "anonymous")
|
||||||
@@ -409,9 +473,17 @@ class routeSQL
|
|||||||
403);
|
403);
|
||||||
$this->connect();
|
$this->connect();
|
||||||
parse_str (file_get_contents ("php://input"), $values);
|
parse_str (file_get_contents ("php://input"), $values);
|
||||||
|
$errorsChain = array ();
|
||||||
|
if ($this->chainedForeign !== null &&
|
||||||
|
isset ($values[$this->chainedForeign]) &&
|
||||||
|
$values[$this->chainedForeign] !== $chain)
|
||||||
|
$errorsChain[$this->chainedForeign] =
|
||||||
|
array ("error", dgettext("domframework",
|
||||||
|
"Can not change the external key"));
|
||||||
$errors = $this->objectDB->verify ($values, $id);
|
$errors = $this->objectDB->verify ($values, $id);
|
||||||
if (count ($errors) > 0)
|
if (count ($errors) > 0 || count ($errorsChain) > 0)
|
||||||
$this->renderrest ($extension, $errors, 400);
|
$this->renderrest ($extension, array_merge ($errors, $errorsChain),
|
||||||
|
400);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->objectDB->update ($id, $values);
|
$this->objectDB->update ($id, $values);
|
||||||
@@ -424,8 +496,26 @@ class routeSQL
|
|||||||
});
|
});
|
||||||
|
|
||||||
$route->delete ("rest/".$this->url_prefix."(\.{extension})?/{id}",
|
$route->delete ("rest/".$this->url_prefix."(\.{extension})?/{id}",
|
||||||
function ($extension, $id)
|
function ($extension, $id, $chain)
|
||||||
{
|
{
|
||||||
|
if ($this->chained !== null)
|
||||||
|
{
|
||||||
|
if ($this->chained->editright ($this->authREST["email"], $chain) !==
|
||||||
|
TRUE)
|
||||||
|
{
|
||||||
|
if ($this->authHTML["email"] === "anonymous")
|
||||||
|
throw new Exception (dgettext("domframework",
|
||||||
|
"Anonymous not allowed"), 401);
|
||||||
|
throw new Exception (dgettext("domframework","Access forbidden"),
|
||||||
|
403);
|
||||||
|
}
|
||||||
|
$this->chained->connect();
|
||||||
|
// $chainedValues are the informations associated to the $chain
|
||||||
|
$chainedValues = $this->chained->keyexists ($chain);
|
||||||
|
if ($chainedValues === false)
|
||||||
|
throw new Exception (dgettext("domframework",
|
||||||
|
"Object not found"), 404);
|
||||||
|
}
|
||||||
if ($this->accessright ($this->authREST["email"]) !== TRUE)
|
if ($this->accessright ($this->authREST["email"]) !== TRUE)
|
||||||
{
|
{
|
||||||
if ($this->authREST["email"] === "anonymous")
|
if ($this->authREST["email"] === "anonymous")
|
||||||
@@ -1168,11 +1258,13 @@ class routeSQL
|
|||||||
"Can not change the primary key"), 403);
|
"Can not change the primary key"), 403);
|
||||||
$errorsChain = array ();
|
$errorsChain = array ();
|
||||||
if ($this->chainedForeign !== null &&
|
if ($this->chainedForeign !== null &&
|
||||||
|
isset ($values[$this->chainedForeign]) &&
|
||||||
$values[$this->chainedForeign] !== $chain)
|
$values[$this->chainedForeign] !== $chain)
|
||||||
$errorsChain[$this->chainedForeign] =
|
$errorsChain[$this->chainedForeign] =
|
||||||
array ("error", dgettext("domframework",
|
array ("error", dgettext("domframework",
|
||||||
"Can not change the external key"));
|
"Can not change the external key"));
|
||||||
|
if ($this->chainedForeign !== null)
|
||||||
|
$values[$this->chainedForeign] = $chain;
|
||||||
$errors = $this->objectDB->verify ($values, $id);
|
$errors = $this->objectDB->verify ($values, $id);
|
||||||
if (count ($errors) == 0 && count ($errorsChain) == 0)
|
if (count ($errors) == 0 && count ($errorsChain) == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user