Corrections des modules+repos et TESTS 'user' 'cluster' 'machine' 'userDefault/create' 'machineDefault/create'

This commit is contained in:
xdrm-brackets 2016-07-09 15:06:59 +02:00
parent 352ff86efb
commit e8bc1a72bf
7 changed files with 42 additions and 46 deletions

View File

@ -33,6 +33,7 @@
return ['ModuleError' => ManagerError::ModuleError];
/* [2] Creation du groupe de meme nom que la machine
=========================================================*/
$create_group = new Repo('cluster/create', [
@ -46,7 +47,6 @@
if( $id_group === false )
return ['ModuleError' => ManagerError::ModuleError];
/* [3] Association au groupe
=========================================================*/
$assoc_goup = new Repo('cluster/link', [

View File

@ -44,8 +44,6 @@
]);
$id_user = $create_user->answer();
var_dump($create_user);
// Si une erreur est retournee, on retourne une erreur
if( $id_user === false )
return ['ModuleError' => ManagerError::ModuleError];
@ -54,15 +52,15 @@
/* [3] Creation du groupe de meme nom que l'username
=========================================================*/
$create_group = new Repo('cluster/create', [
$create_cluster = new Repo('cluster/create', [
$_SESSION['WAREHOUSE']['id'],
$username,
clusterRepo::USER_CLASS
]);
$id_group = $create_group->answer();
$id_cluster = $create_cluster->answer();
// Si une erreur est retournee, on retourne une erreur
if( $id_group === false )
if( $id_cluster === false )
return ['ModuleError' => ManagerError::ModuleError];
@ -72,15 +70,15 @@
=========================================================*/
$assoc_goup = new Repo('cluster/link', [
$_SESSION['WAREHOUSE']['id'],
$id_group,
$id_cluster,
$id_user,
clusterRepo::USER_CLASS
]);
$id_assoc = $assoc_goup->answer();
$assoc_err = $assoc_goup->answer();
// Si une erreur est retournee, on retourne une erreur
if( $id_assoc === false )
return ['ModuleError' => ManagerError::ModuleError];
if( $assoc_err != ManagerError::Success )
return ['ModuleError' => $assoc_err];
@ -88,7 +86,7 @@
=========================================================*/
return [
'id_user' => $id_user,
'id_cluster' => $id_group
'id_cluster' => $id_cluster
];
}

View File

@ -68,8 +68,7 @@
* @id_entity<int> UID de la machine ou de l'utilisateur
* @class<int> Spefication du type d'entite (0=user;1=machine)
*
* @return association<int> Renvoie l'UID de l'association cree
* Renvoie FALSE si une erreur occure
* @return error<int> Renvoie le code 'ManagerError'
*
*/
public static function link($id_warehouse, $id_cluster, $id_entity, $class){
@ -130,7 +129,7 @@
// Si n'existe pas on retourne FALSE
if( !is_array($check_cluster_merge) )
return ManagerError::ModuleError;
return ManagerError::RepoError;
// Sinon, on retourne son id
return ManagerError::Success;
@ -150,7 +149,7 @@
* @id_entity<int> UID de la machine ou de l'utilisateur
* @class<int> Spefication du type d'entite (0=user;1=machine)
*
* @return status<Boolean> Retourne si oui ou non l'association a bien ete supprimee
* @return error<int> Renvoie le code 'ManagerError'
*
*/
public static function unlink($id_warehouse, $id_cluster, $id_entity, $class){
@ -245,11 +244,9 @@
*/
public static function getAll($id_warehouse){
// On ecrit la requete
$request = Database::getPDO()->prepare("SELECT c.*, count(cm.id_cluster_merge) as count
FROM cluster as c, cluster_merge as cm
WHERE cm.id_cluster = c.id_cluster
AND c.id_warehouse = :id_warehouse
GROUP BY c.id_cluster
$request = Database::getPDO()->prepare("SELECT *
FROM cluster as c
WHERE c.id_warehouse = :id_warehouse
ORDER BY c.name ASC");
// On execute la requete
@ -279,11 +276,9 @@
public static function getById($id_warehouse, $id){
// On ecrit la requete
$request = Database::getPDO()->prepare("SELECT c.*
FROM cluster as c, cluster_merge as cm
WHERE cm.id_cluster = c.id_cluster
AND c.id_warehouse = :id_warehouse
AND c.id_cluster = :id
ORDER BY c.id ASC");
FROM cluster as c
WHERE c.id_warehouse = :id_warehouse
AND c.id_cluster = :id");
// On execute la requete
$request->execute([
@ -319,11 +314,9 @@
public static function getByName($id_warehouse, $name){
// On ecrit la requete
$request = Database::getPDO()->prepare("SELECT c.*
FROM cluster as c, cluster_merge as cm
WHERE cm.id_cluster = c.id_cluster
AND c.id_warehouse = :id_warehouse
AND c.name = :name
ORDER BY c.name ASC");
FROM cluster as c
WHERE c.id_warehouse = :id_warehouse
AND c.name = :name");
// On execute la requete
$request->execute([

View File

@ -24,8 +24,9 @@
$check_unique = self::getByName($id_warehouse, $name) === false;
// Si une machine a deja ce nom, on renvoie une erreur
if( !$check_unique )
if( !$check_unique ){
return false;
}
/* [2] Creation de la machine

View File

@ -50,7 +50,7 @@
/* [3] On retourne l'id_user ou FALSE si erreur
=========================================================*/
$check_user = self::getByCode($code);
$check_user = self::getByCode($id_warehouse, $code);
// Si n'existe pas on retourne FALSE
if( $check_user === false )
@ -238,7 +238,7 @@
/* [2] On verifie que l'utilisateur n'existe plus
=========================================================*/
return ( self::getById($id_user) === false );
return ( self::getById($id_warehouse, $id_user) === false );
}

View File

@ -21,7 +21,7 @@
*
*/
function insertUsersFromJSON(){
$json = ResourceDispatcher::getResource('f/json/generated_users/conf');
$json = file_get_contents(__ROOT__.'/config/generated_users.json');
$json = json_decode( $json, true );
// Pour chaque entree
@ -29,17 +29,19 @@
// Creation de la requete
$request = new ModuleRequest('userDefault/create', [
$user['code'],
$user['username'],
$user['firstname'],
$user['lastname'],
$user['email'],
$user['password'],
$user['status']
'code' => $user['code'],
'username' => $user['username'],
'firstname' => $user['firstname'],
'lastname' => $user['lastname'],
'mail' => $user['email'],
'password' => $user['password'],
'status' => $user['status']
]);
$answer = $request->dispatch();
// Debug error
var_dump( $answer->error == ManagerError::Success );
if( $answer->error != ManagerError::Success )
var_dump( $answer->error );
}
return true;
@ -56,7 +58,7 @@
*
*/
function insertMachinesFromJSON(){
$json = ResourceDispatcher::getResource('f/json/generated_machines/conf');
$json = file_get_contents(__ROOT__.'/config/generated_machines.json');
$json = json_decode( $json, true );
// Pour chaque entree
@ -64,12 +66,13 @@
// Creation de la requete
$request = new ModuleRequest('machineDefault/create', [
$machine['code'],
$machine['name']
'name' => $machine['name']
]);
$answer = $request->dispatch();
// Debug error
var_dump( $answer->error == ManagerError::Success );
if( $answer->error != ManagerError::Success )
var_dump( $answer->error );
}
return true;

View File

@ -127,6 +127,7 @@
foreach($clusters as $cluster)
if( $cluster['name'] != $user['username'] ) // Si c'est le groupe personnel, on ne l'affiche pas
echo "<span>".$cluster['name']."<span class='rem-group' data-group='".$cluster['id_cluster']."' data-user='".$user['id_user']."'></span></span>";
echo "<span class='add-group' data-user='".$user['id_user']."'>+</span>";
echo"</span>";