Added macro

Former-commit-id: 08c46875bb09eafde6ebc2f4b526fe4c7bbf944e
This commit is contained in:
Daniel Maya 2019-04-24 13:40:37 +02:00
parent dcdb8c3aa9
commit a1dbf7b780

View File

@ -463,6 +463,24 @@ class Item extends Model
null null
); );
// The agent alias should be a valid string or a null value.
$agentData['agentAlias'] = static::notEmptyStringOr(
static::issetInArray($data, ['agentAlias', 'agent_alias']),
null
);
// The agent description should be a valid string or a null value.
$agentData['agentDescription'] = static::notEmptyStringOr(
static::issetInArray($data, ['agentDescription', 'agent_description']),
null
);
// The agent address should be a valid string or a null value.
$agentData['agentAddress'] = static::notEmptyStringOr(
static::issetInArray($data, ['agentAddress', 'agent_address']),
null
);
return $agentData; return $agentData;
} }
@ -508,6 +526,12 @@ class Item extends Model
null null
); );
// The module description should be a valid string or a null value.
$moduleData['moduleDescription'] = static::notEmptyStringOr(
static::issetInArray($data, ['moduleDescription', 'module_description']),
null
);
return $moduleData; return $moduleData;
} }
@ -735,32 +759,36 @@ class Item extends Model
throw new \InvalidArgumentException('missing metaconsole node Id'); throw new \InvalidArgumentException('missing metaconsole node Id');
} }
$agentName = false; $agent = false;
if (\is_metaconsole()) { if (\is_metaconsole()) {
$agentName = \db_get_value_filter( $sql = sprintf(
'nombre', 'SELECT nombre, alias, direccion, comentarios
'tmetaconsole_agent', FROM tmetaconsole_agent
[ WHERE id_tagente = %s and id_tmetaconsole_setup = %s',
'id_tagente' => $agentId, $agentId,
'id_tmetaconsole_setup' => $metaconsoleId, $metaconsoleId
]
); );
} else { } else {
$agentName = \db_get_value( $sql = sprintf(
'nombre', 'SELECT nombre, alias, direccion, comentarios
'tagente', FROM tagente
'id_agente', WHERE id_agente = %s',
$agentId $agentId
); );
} }
if ($agentName === false) { $agent = \db_get_row_sql($sql);
if ($agent === false) {
throw new \Exception('error fetching the data from the DB'); throw new \Exception('error fetching the data from the DB');
} }
// The agent name should be a valid string or a null value. // The agent name should be a valid string or a null value.
$agentData['agentName'] = $agentName; $agentData['agentName'] = $agent['nombre'];
$agentData['agentAlias'] = $agent['alias'];
$agentData['agentDescription'] = $agent['comentarios'];
$agentData['agentAddress'] = $agent['direccion'];
return $agentData; return $agentData;
} }
@ -801,36 +829,33 @@ class Item extends Model
$moduleName = false; $moduleName = false;
// Connect to node.
if (\is_metaconsole() && \metaconsole_connect(null, $metaconsoleId) !== NOERR) {
throw new \InvalidArgumentException(
'error connecting to the node'
);
}
$sql = sprintf(
'SELECT nombre, descripcion
FROM tagente_modulo
WHERE id_agente_modulo = %s',
$moduleId
);
$moduleName = \db_get_row_sql($sql);
// Restore connection.
if (\is_metaconsole()) { if (\is_metaconsole()) {
// Connect to node.
if (\metaconsole_connect(null, $metaconsoleId) !== NOERR) {
throw new \InvalidArgumentException(
'error connecting to the node'
);
}
$moduleName = \db_get_value_filter(
'nombre',
'tagente_modulo',
['id_agente_modulo' => $moduleId]
);
// Restore connection.
\metaconsole_restore_db(); \metaconsole_restore_db();
} else {
$moduleName = \db_get_value(
'nombre',
'tagente_modulo',
'id_agente_modulo',
$moduleId
);
} }
if ($moduleName === false) { if ($moduleName === false) {
throw new \Exception('error fetching the data from the DB'); throw new \Exception('error fetching the data from the DB');
} }
$moduleData['moduleName'] = $moduleName; $moduleData['moduleName'] = $moduleName['nombre'];
$moduleData['moduleDescription'] = $moduleName['descripcion'];
return $moduleData; return $moduleData;
} }