[Done] Managed anti-duplication name pour `machineDefault/create` et `machineDefault/edit` (interne à warehouse)

This commit is contained in:
xdrm-brackets 2017-02-20 12:07:44 +01:00
parent 49fad95ad8
commit aa5e2a572e
3 changed files with 36 additions and 11 deletions

View File

@ -24,7 +24,18 @@
public function create($params){ public function create($params){
extract($params); extract($params);
/* [1] Creation de la machine /* [1] Vérification unicité (name)
=========================================================*/
/* (1) Check if unique : name */
$byName_r = new Repo('machine/getByName', [$_SESSION['WAREHOUSE']['id'], $name]);
$byName = $byName_r->answer();
/* (2) If already used -> error */
if( $byName != false )
return ['error' => new Error(Err::AlreadyExists, 'name')];
/* [2] Creation de la machine
=========================================================*/ =========================================================*/
$create_machine = new Repo('machine/create', [ $create_machine = new Repo('machine/create', [
$_SESSION['WAREHOUSE']['id'], $_SESSION['WAREHOUSE']['id'],
@ -38,7 +49,7 @@
/* [2] Gestion du retour /* [3] Gestion du retour
=========================================================*/ =========================================================*/
return [ return [
'id_machine' => $id_machine 'id_machine' => $id_machine
@ -256,8 +267,18 @@
/* [2] Vérification unicité (name)
=========================================================*/
/* (1) Check if unique : name */
$byName_r = new Repo('machine/getByName', [$_SESSION['WAREHOUSE']['id'], $name]);
$byName = $byName_r->answer();
/* [2] Normalisation + verification des donnees /* (2) If already used (not current machine) -> error */
if( $byName != false && $byName['id_machine'] != $id_machine )
return ['error' => new Error(Err::AlreadyExists, 'name')];
/* [3] Normalisation + verification des donnees
=========================================================*/ =========================================================*/
/* (1) Verification des parametres (si correct et different)*/ /* (1) Verification des parametres (si correct et different)*/
@ -271,7 +292,7 @@
]; ];
/* [3] Modification de la machine /* [4] Modification de la machine
=========================================================*/ =========================================================*/
$request = new Repo('machine/edit', [ $request = new Repo('machine/edit', [
$_SESSION['WAREHOUSE']['id'], $_SESSION['WAREHOUSE']['id'],

View File

@ -46,7 +46,7 @@
return ['error' => new Error(Err::AlreadyExists, 'code')]; return ['error' => new Error(Err::AlreadyExists, 'code')];
/* [1] Creation de l'utilisateur /* [2] Creation de l'utilisateur
=========================================================*/ =========================================================*/
$create_user = new Repo('user/create', [ $create_user = new Repo('user/create', [
$_SESSION['WAREHOUSE']['id'], $_SESSION['WAREHOUSE']['id'],
@ -63,7 +63,7 @@
return ['error' => new Error(Err::RepoError)]; return ['error' => new Error(Err::RepoError)];
/* [2] Gestion du retour /* [3] Gestion du retour
=========================================================*/ =========================================================*/
return [ return [
'id_user' => $id_user 'id_user' => $id_user
@ -332,7 +332,7 @@
if( $byCode != false && $byCode['id_user'] != $id_user ) if( $byCode != false && $byCode['id_user'] != $id_user )
return ['error' => new Error(Err::AlreadyExists, 'code')]; return ['error' => new Error(Err::AlreadyExists, 'code')];
/* [2] Normalisation + verification des donnees /* [3] Normalisation + verification des donnees
=========================================================*/ =========================================================*/
/* (1) Verification des parametres (si non nul + differents)*/ /* (1) Verification des parametres (si non nul + differents)*/
$diff_param = [ $diff_param = [
@ -355,7 +355,7 @@
/* [3] Modification de l'utilisateur /* [4] Modification de l'utilisateur
=========================================================*/ =========================================================*/
$request = new Repo('user/edit', [ $request = new Repo('user/edit', [
$_SESSION['WAREHOUSE']['id'], $_SESSION['WAREHOUSE']['id'],

View File

@ -4,6 +4,8 @@
use \database\core\DatabaseDriver; use \database\core\DatabaseDriver;
use \orm\core\Table; use \orm\core\Table;
use \orm\core\Rows; use \orm\core\Rows;
use \error\core\Error;
use \error\core\Err;
use \api\core\Checker; use \api\core\Checker;
use \manager\repo\cluster as clusterRepo; use \manager\repo\cluster as clusterRepo;
@ -232,14 +234,15 @@
->select('token') ->select('token')
->select('unlock_code') ->select('unlock_code')
->orderby('name', Rows::ORDER_ASC) ->orderby('name', Rows::ORDER_ASC)
->unique(); ->unique()
->fetch();
/* (2) Manage error */ /* (2) Manage error */
if( $machine === false ) if( $machine === false )
return false; return false;
/* (3) On remplace les valeurs 'unlock_code' et 'token' */ /* (3) On remplace les valeurs 'unlock_code' et 'token' */
$machine['token'] = strlen($machine['token']) > 0; $machine['token'] = strlen($machine['token']) > 0;
$machine['unlock_code'] = strlen($machine['unlock_code']) > 0; $machine['unlock_code'] = strlen($machine['unlock_code']) > 0;
/* (4) On retourne la réponse */ /* (4) On retourne la réponse */
@ -275,7 +278,8 @@
->select('token') ->select('token')
->select('unlock_code') ->select('unlock_code')
->orderby('name', Rows::ORDER_ASC) ->orderby('name', Rows::ORDER_ASC)
->unique(); ->unique()
->fetch();
/* (2) Manage error */ /* (2) Manage error */
if( $machine === false ) if( $machine === false )