Update *module_merge* to link `id_etree` instead of `id_module` (impacts 5. 6. 8.)
This commit is contained in:
parent
261398d4a8
commit
05d1ef50e0
|
@ -426,7 +426,7 @@
|
|||
|
||||
/* RETOURNE LA LISTE DES MODULE D'UN GROUPE DE MACHINES
|
||||
*
|
||||
* @id_cluster<int> UID du groupe de machine
|
||||
* @id_machine_cluster<int> UID du groupe de machine
|
||||
*
|
||||
* @return modules<Array> Liste des modules autorisés pour le groupe de machines
|
||||
*
|
||||
|
@ -438,9 +438,9 @@
|
|||
/* [1] On récupère les modules
|
||||
=========================================================*/
|
||||
/* (1) Récupération */
|
||||
$mod_req = new Repo('module/getByMachineCluster', [
|
||||
$mod_req = new Repo('module/getForMachineCluster', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_cluster
|
||||
$id_machine_cluster
|
||||
]);
|
||||
|
||||
$answer = $mod_req->answer();
|
||||
|
@ -457,6 +457,44 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* RETOURNE L'E-TREE D'UN GROUPE DE MACHINES
|
||||
*
|
||||
* @id_machine_cluster<int> UID du groupe de machine
|
||||
*
|
||||
* @return e-tree<Array> E-tree du groupe de machines
|
||||
*
|
||||
*/
|
||||
public static function getEtree($params){
|
||||
extract($params);
|
||||
|
||||
|
||||
/* [1] On récupère les modules
|
||||
=========================================================*/
|
||||
/* (1) Récupération */
|
||||
$mod_req = new Repo('etree/getForMachineCluster', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_machine_cluster
|
||||
]);
|
||||
|
||||
$answer = $mod_req->answer();
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
if( $answer === false )
|
||||
return ['error' => new Error(Err::NoMatchFound)]; // no error
|
||||
|
||||
|
||||
/* [3] On retourne la liste
|
||||
=========================================================*/
|
||||
return [ 'etree' => $answer ];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
foreach($clusters as $cluster){
|
||||
|
||||
$get_mods = new Repo('module/getByMachineCluster', [$id_warehouse, $cluster['id_machine_cluster']]);
|
||||
$get_mods = new Repo('module/getForMachineCluster', [$id_warehouse, $cluster['id_machine_cluster']]);
|
||||
|
||||
$mods = $get_mods->answer();
|
||||
|
||||
|
|
|
@ -0,0 +1,202 @@
|
|||
<?php
|
||||
|
||||
namespace database\repo;
|
||||
use \database\core\DatabaseDriver;
|
||||
use \error\core\Err;
|
||||
use \database\core\Repo;
|
||||
use \orm\core\Table;
|
||||
use \orm\core\Rows;
|
||||
|
||||
class etree extends parentRepo{
|
||||
|
||||
protected static function table_name(){ static $table_name = 'etree'; return $table_name; }
|
||||
|
||||
/* [1] Fetch all etrees for the given machine_cluster
|
||||
*
|
||||
* @id_warehouse<int> UID of the given warehouse
|
||||
* @id_machine_cluster<int> UID of the given machine_cluster
|
||||
*
|
||||
* @return etrees<Array> The list of etrees
|
||||
* FALSE on error
|
||||
*
|
||||
=========================================================*/
|
||||
public static function getForMachineCluster($id_warehouse, $id_machine_cluster){
|
||||
|
||||
/* (1) On récupère le ETREE de la machine
|
||||
---------------------------------------------------------*/
|
||||
$module = Table::get('module')
|
||||
->select('id_module')
|
||||
->select('name');
|
||||
|
||||
$etree = Table::get('etree')
|
||||
->select('id_etree')
|
||||
->select('daemon')
|
||||
->join('id_module', $module);
|
||||
|
||||
$merge = Table::get('module_merge')
|
||||
->join('id_etree', $etree)
|
||||
->whereIdWarehouse($id_warehouse)
|
||||
->whereIdMachineCluster($id_machine_cluster);
|
||||
|
||||
return $merge->fetch();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* [4] Adds a module to machine cluster of a warehouse
|
||||
*
|
||||
* @id_warehouse<int> UID of the given warehouse
|
||||
* @id_machine_cluster<int> UID of the given machine_cluster
|
||||
* @id_module UID of the given module
|
||||
*
|
||||
* @return status<bool> TRUE on success
|
||||
*
|
||||
=========================================================*/
|
||||
public static function link($id_warehouse, $id_machine_cluster, $id_module){
|
||||
|
||||
/* (1) Check module
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Check if module exists (by its id) */
|
||||
$module = Table::get('module')
|
||||
->select('*')
|
||||
->unique()
|
||||
->whereId($id_module);
|
||||
|
||||
if( !$module->fetch() )
|
||||
return false;
|
||||
|
||||
/* (2) Check if the module is allowed in the warehouse */
|
||||
$module_m = Table::get('module_availability')
|
||||
->select('*')
|
||||
->unique()
|
||||
->whereIdWarehouse($id_warehouse)
|
||||
->whereIdModule($id_module);
|
||||
|
||||
// if not allowed in the warehouse -> error
|
||||
if( !$module->fetch() )
|
||||
return false;
|
||||
|
||||
|
||||
/* (2) Check machine_cluster
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Check if machine_cluster exists (by its id) */
|
||||
$machine_cluster = Table::get('machine_cluster')
|
||||
->select('*')
|
||||
->unique()
|
||||
->whereIdWarehouse($id_warehouse)
|
||||
->whereId($id_machine_cluster);
|
||||
|
||||
if( !$machine_cluster->fetch() )
|
||||
return false;
|
||||
|
||||
/* (2) Check link does not already exists */
|
||||
$exists = Table::get('module_merge')
|
||||
->select('*')
|
||||
->unique()
|
||||
->whereIdWarehouse($id_warehouse)
|
||||
->whereIdMachineCluster($id_machine_cluster)
|
||||
->whereIdModule($id_module);
|
||||
|
||||
if( !!$exists->fetch() )
|
||||
return true; // returns all right (even if nothing done)
|
||||
|
||||
|
||||
|
||||
/* (3) Create link
|
||||
---------------------------------------------------------*/
|
||||
$inserted = Table::get('module_merge')->insert([
|
||||
'id_warehouse' => $id_warehouse,
|
||||
'id_module' => $id_module,
|
||||
'id_machine_cluster' => $id_machine_cluster
|
||||
]);
|
||||
|
||||
// return TRUE only if PDO insert successful
|
||||
return $inserted;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* [5] Removes a module from machine cluster of a warehouse
|
||||
*
|
||||
* @id_warehouse<int> UID of the given warehouse
|
||||
* @id_machine_cluster<int> UID of the given machine_cluster
|
||||
* @id_module UID of the given module
|
||||
*
|
||||
* @return status<bool> TRUE on success
|
||||
*
|
||||
=========================================================*/
|
||||
public static function unlink($id_warehouse, $id_machine_cluster, $id_module){
|
||||
|
||||
/* (1) Check module
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Check if module exists (by its id) */
|
||||
$module = Table::get('module')
|
||||
->select('*')
|
||||
->unique()
|
||||
->whereId($id_module);
|
||||
|
||||
if( !$module->fetch() )
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
/* (2) Check machine_cluster
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Check if machine_cluster exists (by its id) */
|
||||
$machine_cluster = Table::get('machine_cluster')
|
||||
->select('*')
|
||||
->unique()
|
||||
->whereIdWarehouse($id_warehouse)
|
||||
->whereId($id_machine_cluster);
|
||||
|
||||
if( !$machine_cluster->fetch() )
|
||||
return false;
|
||||
|
||||
/* (2) Check if link already exists */
|
||||
$exists = Table::get('module_merge')
|
||||
->select('*')
|
||||
->unique()
|
||||
->whereIdWarehouse($id_warehouse)
|
||||
->whereIdMachineCluster($id_machine_cluster)
|
||||
->whereIdModule($id_module);
|
||||
|
||||
if( !$exists->fetch() )
|
||||
return false; // returns all right (even if nothing done)
|
||||
|
||||
|
||||
|
||||
/* (3) Remove link
|
||||
---------------------------------------------------------*/
|
||||
$deleted = Table::get('module_merge')
|
||||
->whereIdWarehouse($id_warehouse)
|
||||
->whereIdModule($id_module)
|
||||
->whereIdMachineCluster($id_machine_cluster)
|
||||
->delete();
|
||||
|
||||
// return TRUE only if PDO delete successful
|
||||
return $deleted;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -37,7 +37,7 @@
|
|||
* FALSE on error
|
||||
*
|
||||
=========================================================*/
|
||||
public static function getByWarehouse($id_warehouse){
|
||||
public static function getForWarehouse($id_warehouse){
|
||||
|
||||
/* (1) Build request */
|
||||
$modules = Table::get('module')->select('*');
|
||||
|
@ -63,14 +63,21 @@
|
|||
* FALSE on error
|
||||
*
|
||||
=========================================================*/
|
||||
public static function getByMachineCluster($id_warehouse, $id_machine_cluster){
|
||||
public static function getForMachineCluster($id_warehouse, $id_machine_cluster){
|
||||
|
||||
/* (1) Build request */
|
||||
$modules = Table::get('module')->select('*');
|
||||
$merge = Table::get('module_merge')
|
||||
/* (1) On récupère le ETREE de la machine
|
||||
---------------------------------------------------------*/
|
||||
$module = Table::get('module')
|
||||
->select('id_module')
|
||||
->select('name');
|
||||
|
||||
$etree = Table::get('etree')
|
||||
->join('id_module', $module);
|
||||
|
||||
$merge = Table::get('module_merge')
|
||||
->join('id_etree', $etree)
|
||||
->whereIdWarehouse($id_warehouse)
|
||||
->whereIdMachineCluster($id_machine_cluster);
|
||||
$merge->join('id_module', $modules);
|
||||
|
||||
return $merge->fetch();
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
/* [1] On récupère les modules
|
||||
=========================================================*/
|
||||
/* (1) Récupération */
|
||||
$mod_req = new Repo('module/getByWarehouse', [$id_warehouse]);
|
||||
$mod_req = new Repo('module/getForWarehouse', [$id_warehouse]);
|
||||
|
||||
$answer = $mod_req->answer();
|
||||
|
||||
|
|
|
@ -61,16 +61,17 @@
|
|||
}));
|
||||
|
||||
$twig->addFunction(new \Twig_Function('f_options', function($id_cluster){
|
||||
$modReq = new Request('clusterDefault/getModules', [
|
||||
'id_cluster' => (int) $id_cluster
|
||||
$modReq = new Request('clusterDefault/getEtree', [
|
||||
'id_machine_cluster' => (int) $id_cluster
|
||||
]);
|
||||
|
||||
$modRes = $modReq->dispatch();
|
||||
|
||||
// si erreur, on affiche rien par défaut
|
||||
if( $modRes->error->get() != Err::Success )
|
||||
return [];
|
||||
|
||||
return $modRes->get('modules');
|
||||
return $modRes->get('etree');
|
||||
}));
|
||||
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
{{ p_icon.option | raw }}
|
||||
{% for option in f_options(machine_cluster.id_machine_cluster) %}
|
||||
<span class='ignore'>
|
||||
<span>{{ option.name }}</span>
|
||||
<span>{{ option.name }}:{{ option.daemon }}</span>
|
||||
</span>
|
||||
{% else %}
|
||||
<span class='ignore'>Aucune option</span>
|
||||
|
|
|
@ -62,16 +62,17 @@
|
|||
}));
|
||||
|
||||
$twig->addFunction(new \Twig_Function('f_options', function($id_cluster){
|
||||
$modReq = new Request('clusterDefault/getModules', [
|
||||
'id_cluster' => (int) $id_cluster
|
||||
$modReq = new Request('clusterDefault/getEtree', [
|
||||
'id_machine_cluster' => (int) $id_cluster
|
||||
]);
|
||||
|
||||
$modRes = $modReq->dispatch();
|
||||
|
||||
// si erreur, on affiche rien par défaut
|
||||
if( $modRes->error->get() != Err::Success )
|
||||
return [];
|
||||
|
||||
return $modRes->get('modules');
|
||||
return $modRes->get('etree');
|
||||
}));
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
{{ p_icon.option | raw }}
|
||||
{% for option in f_options(cluster.id_machine_cluster) %}
|
||||
<span class='ignore'>
|
||||
<span>{{ option.name }}</span>
|
||||
<span>{{ option.name }}:{{ option.daemon }}</span>
|
||||
</span>
|
||||
{% else %}
|
||||
<span class='ignore'>Aucune option</span>
|
||||
|
|
|
@ -509,11 +509,22 @@
|
|||
"description": "Retourne les modules d'un groupe de machines",
|
||||
"permissions": [["admin"]],
|
||||
"parameters": {
|
||||
"id_cluster": { "description": "UID du groupe de machines", "type": "id" }
|
||||
"id_machine_cluster": { "description": "UID du groupe de machines", "type": "id" }
|
||||
},
|
||||
"output": {
|
||||
"modules": { "description": "Modules du groupe", "type": "array<mixed>" }
|
||||
}
|
||||
},
|
||||
|
||||
"POST::getEtree": {
|
||||
"description": "Retourne l'e-tree d'un groupe de machines",
|
||||
"permissions": [["admin"]],
|
||||
"parameters": {
|
||||
"id_machine_cluster": { "description": "UID du groupe de machines", "type": "id" }
|
||||
},
|
||||
"output": {
|
||||
"modules": { "description": "E-tree du groupe", "type": "array<mixed>" }
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
|
|
@ -2,12 +2,16 @@
|
|||
|
||||
"module": [
|
||||
"getAll",
|
||||
"getByWarehouse",
|
||||
"getByMachineCluster",
|
||||
"getForWarehouse",
|
||||
"getForMachineCluster",
|
||||
"link",
|
||||
"unlink"
|
||||
],
|
||||
|
||||
"etree": [
|
||||
"getForMachineCluster"
|
||||
],
|
||||
|
||||
"history": [
|
||||
"create",
|
||||
"delete",
|
||||
|
|
|
@ -337,6 +337,7 @@
|
|||
|
||||
.option > span.ignore > span{
|
||||
border-radius: 3px;
|
||||
margin-right: .4em;
|
||||
}
|
||||
|
||||
/* (5) Lien vers la modification */
|
||||
|
|
|
@ -539,6 +539,7 @@
|
|||
#WRAPPER > #CONTAINER > section > .inline-box .option > span.ignore > span,
|
||||
#WRAPPER > #CONTAINER > section > .inline-row .option > span.ignore > span {
|
||||
border-radius: 3px;
|
||||
margin-right: .4em;
|
||||
}
|
||||
|
||||
#WRAPPER > #CONTAINER > section > .inline-box .link_edit,
|
||||
|
|
Loading…
Reference in New Issue