[1] machineDefault/update uses `moduleDefault/dispatch` to manage data for each feature
[2] `moduleDefault/dispatch` is now implemented [3] `moduleDefault/rfid_read` implemented and caught by the *dispatcher* [4] Added repo method etree/parse to get useable data from 'moduleName-etreeDaemonName'
This commit is contained in:
parent
d1f7f4f18f
commit
978aed690f
|
@ -682,57 +682,46 @@
|
|||
|
||||
/* [1] Initialisation des variables
|
||||
=========================================================*/
|
||||
$fetched = [
|
||||
'history' => 0, // count of registered logs
|
||||
'feature' => [], // count of registered logs for each feature
|
||||
'identity' => [ // network identity
|
||||
'ap' => isset($data['identity']) && is_array($data['identity']) && isset($data['identity']['ap']) ? $data['identity']['ap'] : null,
|
||||
'ip' => isset($data['identity']) && is_array($data['identity']) && isset($data['identity']['ip']) ? $data['identity']['ip'] : null
|
||||
]
|
||||
$fetched = [ // count of registered logs for each feature
|
||||
];
|
||||
|
||||
|
||||
/* [2] Gestion des données reçues
|
||||
=========================================================*/
|
||||
/* (1) For each history entry */
|
||||
if( isset($data['default']) && is_array($data['default']) ){
|
||||
/* (1) For each feature data */
|
||||
if( isset($data['feature']) && is_array($data['feature']) ){
|
||||
|
||||
/* (2) Create history entry in db */
|
||||
foreach($data['default'] as $entry){
|
||||
foreach($data['feature'] as $etree_name=>$feat_data){
|
||||
|
||||
// {1} Build request //
|
||||
$log_req = new Request('historyDefault/create', [
|
||||
'timestamp' => $entry[0],
|
||||
'id_user' => $entry[1],
|
||||
'id_action' => $entry[2],
|
||||
'id_machine' => $_SESSION['SATS']['id']
|
||||
// {1} Use moduleDefault to dispatch the request //
|
||||
$dispatch_feat_req = new Request('moduleDefault/dispatch', [
|
||||
'etree' => $etree_name,
|
||||
'data' => $feat_data
|
||||
]);
|
||||
|
||||
// {2} Process + get response //
|
||||
$log_res = $log_req->dispatch();
|
||||
$dispatch_feat_res = $dispatch_feat_req->dispatch();
|
||||
|
||||
// {3} Exit on failure //
|
||||
if( $log_res->error->get() != Err::Success )
|
||||
if( $dispatch_feat_res->error->get() != Err::Success )
|
||||
break;
|
||||
|
||||
// {4} Register count if success //
|
||||
$fetched['history']++;
|
||||
// {4} Register saved code (returned from dispatcher) //
|
||||
$fetched[$etree_name] = $dispatch_feat_res->get('saved');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (2) For each feature's entry */
|
||||
// TODO: Manage feature's entries
|
||||
|
||||
/* (3) Mise à jour de l'identité de la machine (ap-ip) */
|
||||
/* (2) Mise à jour de l'identité de la machine (ap-ip) */
|
||||
$updateNetId = new Repo('machine/updateNetworkIdentity', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$_SESSION['SATS']['id'],
|
||||
$fetched['identity']['ap'],
|
||||
$fetched['identity']['ip']
|
||||
isset($data['identity']) && is_array($data['identity']) && isset($data['identity']['ap']) ? $data['identity']['ap'] : null,
|
||||
isset($data['identity']) && is_array($data['identity']) && isset($data['identity']['ip']) ? $data['identity']['ip'] : null,
|
||||
]);
|
||||
|
||||
/* (2) On gère l'erreur */
|
||||
/* (3) Gestion erreur */
|
||||
if( $updateNetId->error->get() != Err::Success || !$updateNetId->answer() )
|
||||
return [ 'error' => new Error(Err::RepoError) ];
|
||||
|
||||
|
@ -747,7 +736,7 @@
|
|||
|
||||
/* [4] Envoi des données
|
||||
=========================================================*/
|
||||
return array_merge($basis_update, ['saved' => $fetched, 'id' => $fetched['identity']]);
|
||||
return array_merge($basis_update, ['saved' => $fetched]);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
namespace api\module;
|
||||
use \database\core\DatabaseDriver;
|
||||
use \manager\sessionManager;
|
||||
use \error\core\Error;
|
||||
use \error\core\Err;
|
||||
use \database\core\Repo;
|
||||
use \api\core\Request;
|
||||
|
||||
class moduleDefault{
|
||||
|
||||
public function __construct(){}
|
||||
public function __destruct(){}
|
||||
|
||||
/* [0] Dispatch des données d'une feature d'une machine
|
||||
*
|
||||
* @etree<String> Nom (complet) de l'e-tree
|
||||
* @data<mixed> Données à traiter
|
||||
*
|
||||
* @return saved<numeric> Code de réception (nombre d'entrées ou autre)
|
||||
*
|
||||
=========================================================*/
|
||||
public function dispatch($params){
|
||||
extract($params);
|
||||
|
||||
/* (1) On parse le nom complet
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Requête */
|
||||
$etree_parse_req = new Repo('etree/parse', [$etree]);
|
||||
|
||||
/* (2) On récupère la réponse */
|
||||
$etree_data = $etree_parse_req->answer();
|
||||
|
||||
/* (3) Gestion erreur */
|
||||
if( $etree_data === false )
|
||||
return ['error' => new Error(Err::FormatError)];
|
||||
|
||||
/* (4) On calcule le nom de la méthode */
|
||||
$method_name = $etree_data['module_name'].'_'.$etree_data['etree_name'];
|
||||
|
||||
|
||||
|
||||
/* (2) Gestion du dispatch
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Formulation requête */
|
||||
$request = new Request("moduleDefault/$method_name", [
|
||||
'data' => $data
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
if( $request->error->get() != Err::Success )
|
||||
return ['error' => new Error(Err::ModuleError)];
|
||||
|
||||
/* (3) Exécution */
|
||||
$response = $request->dispatch();
|
||||
|
||||
/* (4) Gestion erreur */
|
||||
if( $response->error->get() != Err::Success )
|
||||
return ['error' => new Error(Err::ModuleError)];
|
||||
|
||||
/* (5) Remontée du résultat */
|
||||
return [
|
||||
'saved' => $response->get('saved')
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* [1] Gestion des données historiques de l'etree READ du module RFID
|
||||
*
|
||||
* @data<mixed> Données à traiter
|
||||
*
|
||||
* @return saved<numeric> Nombre de lignes ajoutées
|
||||
*
|
||||
=========================================================*/
|
||||
public function rfid_read($params){
|
||||
|
||||
/* (1) Initialisation du compteur de lignes enregistrées */
|
||||
$count = 0;
|
||||
|
||||
|
||||
/* (2) Create history entry in db */
|
||||
foreach($data as $entry){
|
||||
|
||||
// {1} Build request to store each entry //
|
||||
$log_req = new Request('historyDefault/create', [
|
||||
'timestamp' => $entry[0],
|
||||
'id_user' => $entry[1],
|
||||
'id_action' => $entry[2],
|
||||
'id_machine' => $_SESSION['SATS']['id']
|
||||
]);
|
||||
|
||||
// {2} Process + get response //
|
||||
$log_res = $log_req->dispatch();
|
||||
|
||||
// {3} Exit on failure //
|
||||
if( $log_res->error->get() != Err::Success )
|
||||
break;
|
||||
|
||||
// {4} Register count if success //
|
||||
$count++;
|
||||
}
|
||||
|
||||
|
||||
/* (3) Retourne le nombre d'entrées enregistrées */
|
||||
return [ 'saved' => $count ];
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -43,84 +43,54 @@
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* [4] Adds a module to machine cluster of a warehouse
|
||||
/* [2] Parses an e-tree full name (mod_name-etree_name)
|
||||
*
|
||||
* @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
|
||||
* @full_name<String> Full name to parse
|
||||
*
|
||||
* @return status<bool> TRUE on success
|
||||
* @return info<Array> The useful data (id_module, id_etree)
|
||||
* FALSE on error
|
||||
*
|
||||
=========================================================*/
|
||||
public static function link($id_warehouse, $id_machine_cluster, $id_module){
|
||||
public static function parse($full_name){
|
||||
|
||||
/* (1) Check module
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Check if module exists (by its id) */
|
||||
|
||||
/* (1) On vérifie le format (permet l'extraction des données) */
|
||||
if( !preg_match('@^(.+)-(.+)$@', $full_name, $matches) )
|
||||
return false;
|
||||
|
||||
/* (2) On recherche le module */
|
||||
$module = Table::get('module')
|
||||
->select('*')
|
||||
->select('id_module')
|
||||
->select('name')
|
||||
->unique()
|
||||
->whereId($id_module);
|
||||
->whereName($matches[1])
|
||||
->fetch();
|
||||
|
||||
if( !$module->fetch() )
|
||||
/* (3) Si on ne trouve pas de module -> error */
|
||||
if( !is_array($module) || !isset($module['id_module']) )
|
||||
return false;
|
||||
|
||||
/* (2) Check if the module is allowed in the warehouse */
|
||||
$module_m = Table::get('module_availability')
|
||||
->select('*')
|
||||
/* (5) On cherche l'e-tree */
|
||||
$etree = Table::get('etree')
|
||||
->select('id_etree')
|
||||
->select('daemon')
|
||||
->whereIdModule($module['id_module'])
|
||||
->whereDaemon($matches[2])
|
||||
->unique()
|
||||
->whereIdWarehouse($id_warehouse)
|
||||
->whereIdModule($id_module);
|
||||
->fetch();
|
||||
|
||||
// if not allowed in the warehouse -> error
|
||||
if( !$module->fetch() )
|
||||
/* (6) Si erreur */
|
||||
if( !is_array($etree) || !isset($etree['id_etree']) )
|
||||
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;
|
||||
/* (7) Si tout ok, on retourne les données */
|
||||
return [
|
||||
'id_module' => $module['id_module'],
|
||||
'module_name' => $module['name'],
|
||||
'id_etree' => $etree['id_etree'],
|
||||
'etree_name' => $etree['daemon']
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
@ -130,68 +100,6 @@
|
|||
|
||||
|
||||
|
||||
/* [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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -83,160 +83,6 @@
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* [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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -524,6 +524,31 @@
|
|||
"output": {}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
"moduleDefault": {
|
||||
"POST::dispatch": {
|
||||
"description": "Dispatche la gestion des données reçues par un SATS",
|
||||
"permissions": [["sats"]],
|
||||
"parameters": {
|
||||
"etree": { "description": "Etree full name", "type": "text" },
|
||||
"data": { "descripton": "Données reçues", "type": "mixed" }
|
||||
},
|
||||
"output": {
|
||||
"saved": { "description": "Code de reception (nombre de lignes recues ou autre)", "type": "numeric" }
|
||||
}
|
||||
},
|
||||
|
||||
"POST::rfid_read": {
|
||||
"description": "Enregistrement de l'historique de l'e-tree READ du module RFID",
|
||||
"permissions": [["sats"]],
|
||||
"parameters": {
|
||||
"data": { "descripton": "Historique reçu", "type": "mixed" }
|
||||
},
|
||||
"output": {
|
||||
"saved": { "description": "Nombre d'entrées enregistrées", "type": "id" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,13 +3,12 @@
|
|||
"module": [
|
||||
"getAll",
|
||||
"getForWarehouse",
|
||||
"getForMachineCluster",
|
||||
"link",
|
||||
"unlink"
|
||||
"getForMachineCluster"
|
||||
],
|
||||
|
||||
"etree": [
|
||||
"getForMachineCluster"
|
||||
"getForMachineCluster",
|
||||
"parse"
|
||||
],
|
||||
|
||||
"history": [
|
||||
|
|
Loading…
Reference in New Issue